A simple and lightweight recursive descent parser for parsing mathematical expressions.
Currently only parsing is supported, no error handling is provided.
Supported operations are negation, exponentiation, addition, multiplication and grouping.
The recuirsive descent parser works with the following grammar:
Expression = Addition
Addition = Multiplication | Addition "+" Multiplication | Addition "-" Multiplication
Multiplication = Exponentiation | Multiplication "*" Exponentiation | Multiplication "/" Exponentiation
Exponentiation = Primary | Exponentiation "^" Primary
Primary = Immediate | "(" Expression ")"
Currently the parser runs in a simple REPL:
>>> 2+2+2-6
0.0
>>> 2*4/8
1.0
>>> 2^10
1024.0
>>> (2+2)*2
8.0
>>> 2^2^2
16.0
>>> 2^((3+2)*2)/(2*512)
1.0
- Install virtual-env (skip if already installed)
- Clone the repository
- Setup the virtualenv and activate
- Install the required dependencies
pip install virtualenv
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
Feel free to help with additional functionality by opening a PR. Follow the styling guidelines. All tests must pass. Features needed:
- Error handling (Matching brackets, illegal expressions etc.)
- Division order of operation