Giter Site home page Giter Site logo

kauboy26 / pyevaluator Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 62 KB

Evaluates function definitions and assignment statements. If a rock is a planet, this is a language. On this one, I'm building the lexer and parser by hand, in Python.

Python 87.64% Assembly 12.36%

pyevaluator's Introduction

PyEvaluator

I would like to call this a language, although maybe that's an exaggeration. PyEvaluator evaluates statements that are arithmetic expressions, variable assignments, or function definitions. Here are its features:

  • Assignment statement processing
    >> a = 3 + 4
  • Multi character variable names
    >> hello = hello + world + 15
  • Pre-defined functions (you can call sin(x), etc)
    >> sin(22/7)
  • Finally, defining and using your own functions.
    >> def cos(x) = pow(1 - pow(sin(x), 2), 1/2)

Usage

You need Python 2.7 on your computer. Run the following, within the directory containing lex_test_script.py:

python lex_test_script.py

That should start it and you will see a prompt >>. Type in whatever expressions you want, like ">> a0 = 1 + 3 * 4", etc and have a blast. Type in "help" if you don't know what to do.

Oddities

These work:

  • >> 3 4 +
    In general, you can misplace arguments, put commas in the wrong place (it depends), etc. In this implementation, only the number of arguments is verified(counting the args and then counting the commas), not the exact position of the arguments. I will fix this later if time permits.

Running Tests

Run this command:
python lex_tests.py
All tests should pass. Ignore the other messages that are printed to console, they are messages from the parser.

pyevaluator's People

Contributors

kauboy26 avatar

Watchers

 avatar

pyevaluator's Issues

incorrect behaviour

def g() = 2
def h() = 3

-g() * -h()

Doesn't perform as expected, throws an error instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.