https://github.com/francescoapophis/calc-parser
Small parser for simple math expressions.
https://github.com/francescoapophis/calc-parser
lexer-parser parsing python python3
Last synced: about 1 year ago
JSON representation
Small parser for simple math expressions.
- Host: GitHub
- URL: https://github.com/francescoapophis/calc-parser
- Owner: francescoApophis
- License: mit
- Created: 2024-01-09T14:07:48.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-06T13:57:10.000Z (over 1 year ago)
- Last Synced: 2024-09-06T16:16:23.091Z (over 1 year ago)
- Topics: lexer-parser, parsing, python, python3
- Language: Python
- Homepage:
- Size: 42 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# calc-parser
Small parser for simple math expressions. Built to learn about how
lexing, parsing and operator precendence work.
It uses the '[precedence climbing method](https://en.wikipedia.org/wiki/Operator-precedence_parser)'.
Again, this is for learning purposes and to get a general idea of how this process works, so it may not
use the best algorithm or the best implentation.
Supported:
- [x] addition,
- [x] subtraction,
- [x] multiplication
- [x] division
- [x] parentheses
Soon to be implemented:
- [ ] negative and decimal numbers
- [ ] exponentiation
## Usage
python3 main.py
python3 main.py '' (to use spacing inside the expression)
flags:
-c calculate and print result from string expression
-t generate and print tree from expression
-tc both previous flags
-ct calculate and print result from tree, for debugging tree
-all all commands at the same time