In this repository, I considered a parsing algorithm using recursive descent for a context-free LL(1) grammar of the language of arithmetic expressions. I use Top-Down parser to create an expression tree.
Based on this idea:
Grammar for arithmetic expressions:
I use Python3.7.0
or higher, so first of all we need to install some python packages so that we can run tests and check types as well.
pip install -r requirements.txt
Simply run:
pip install .
Tests based on Pytest fraimwork, to run all tests, enter:
pytest ./tests/
The tests in the section tests / test_calculation
are needed to check the correctness of the calculation of arithmetic expressions. A few simple test cases:
CASES = [CaseCalc("1", 1),
CaseCalc("1 + 2", 3),
CaseCalc("1 - 2", -1)]
To check code style i use flake8 and mypy for typings. Run the following command to start checking
- for
PEP8
code style:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- for typing:
mypy ./
This project is licensed under the MIT