Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/i-redbyte/calculator
Simple console calculator using abstract syntax tree(AST) and recursive descent
https://github.com/i-redbyte/calculator
Last synced: 2 months ago
JSON representation
Simple console calculator using abstract syntax tree(AST) and recursive descent
- Host: GitHub
- URL: https://github.com/i-redbyte/calculator
- Owner: i-redbyte
- License: mit
- Created: 2021-03-09T20:35:49.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-04T14:44:09.000Z (4 months ago)
- Last Synced: 2024-09-06T17:49:44.192Z (4 months ago)
- Language: Kotlin
- Homepage:
- Size: 97.7 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## An example of recursive descent for a calculator
An expression tree is something like this:
![Tree](image/expression_tree.png)Links:
- https://ps-group.github.io/compilers/simple_recursive_parser.html
- https://en.wikipedia.org/wiki/Recursive_descent_parser
- http://www.craftinginterpreters.com
- https://rosettacode.org/wiki/Recursive_descent_parser_generator## About program
This is an example of a simple console calculator implemented through a Recursive Descent Parser. All the usual operator
precedence and associativity rules were followed. The calculator supports basic arithmetic operations [+,-,*,/,^] and
parentheses.Example:
```
>>> 2+2
Result: 4
>>> 5 - 100 + 4
Result: -91
>>> 2^(3+2)
Result: 32
>>> (1+2)/(10-7)
Result: 1
>>> 8-9-(1
Exception in thread "main" expression.ParseException: ) not found.
```