An arithmetic expression parser in Python
- So basically I had a programming language implementation that I was working on click here and now I realized that I need to study more about the topic of parsing expressions, so this repo is like an experiment so I can get how much hard or easy it actually is to parse expressions in python before integrating this concept into the language.
$ git clone https://github.com/Moody0101-X/exp_parser
$ cd exp_parser\src
$ python main.py
- the main goal of this parser is just for short parsing and evaluating arithmetic expressions such as
(x + 1) * (6 * 20)
or1 + 2 * 2 - 20 * (-10)
.. - making a REPLE to give expressions and get answers from scratch, no libs and no plugin just python built-in functions and string manipulation.
- REPLE front-end:
$ REPLE > (1 + 1)
ans: 2
$ REPLE > (1 + 1) * (2 * 2)
ans: 8
- u can define functions using
Func
keyword
$ REPLE > Func increment(a, b) => |(a + 1) + (b + 1)|
$ REPLE > increment(1, 3)
ans: 6
- u can define functions using
Func
keyword
$ REPLE > x = 69
$ REPLE > x
ans: 69
- NOTE:
ans
is a special variable which is assigned to latest computed result. typeans
to access it!
- Stacks: for simple calculations