Calc – A powerful Python REPL calculator
This is a calculator with a complex source that includes a small AST, a parser
and a tokenizer. This is a personal project done in 2 days to understand how
operator precedence works and to practice my rusty skills of making interpreters.
This project has no external dependencies and should work with minimum
3.8 and newer versions of the Python interpreter.
- Complex but small and understandable source code. Implemented in less than 450LoC
- Supports all basic operations (sum, substraction, multiplication, division)
- Supports use of parentheses
- Proper precedence order of operations
- Rich errors handling (human-readable exceptions and hints to fix them)
main.py with Python, this will create a REPL in your terminal which
you can close by typing
- Contains all Tree classes
- Evaluates our generated AST
- Error handling, custom Exception class
- Parses our generated tokens and makes an AST
- Scans our expressions and makes tokens
- Tokenizer classes, debugging function to print tokens
This calculator is licensed under GPLv3.