https://github.com/shravanasati/crusade
A friendly math interpreter.
https://github.com/shravanasati/crusade
cpp math-interpreter shunting-yard-algorithm
Last synced: 12 months ago
JSON representation
A friendly math interpreter.
- Host: GitHub
- URL: https://github.com/shravanasati/crusade
- Owner: shravanasati
- License: mit
- Created: 2024-02-09T17:50:19.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-15T11:07:17.000Z (almost 2 years ago)
- Last Synced: 2025-06-23T12:43:34.459Z (about 1 year ago)
- Topics: cpp, math-interpreter, shunting-yard-algorithm
- Language: C++
- Homepage:
- Size: 18.7 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# crusade
A simple math interpreter written in C++ using the Shunting-yard algorithm.
Watch the [demo video](https://youtu.be/KPOjq7f3VuU).
### Working mechanism
crusade first tokenizes the given input and classifies them into numbers, operators, parentheses and so on. During this operation, it also validates the input and checks for invalid expressions like missing operators/operands/parentheses and so on.
The next step is to use the [shunting yard algorithm](https://en.wikipedia.org/wiki/Shunting_yard_algorithm) to convert the infix expression to the reverse polish notation (aka postfix expression, eg. `1 + 2 - 3` => `1 2 + 3 -`). I've also added a slight modification by providing unary operators with the highest precedence and right associativity. The evaluation of the postfix expression is pretty easy.
### Build from source
```sh
make
```
### Usage
Just launch the executable file and you'd see a prompt. Enter your expressions here and press enter.
You can type `/q`, `exit` or `quit` to exit the application.
You can also toggle the debug mode using the `/debug` command. It will show your given expression in a parenthesized manner.
You can autocomplete these commands by pressing tab.
### Further Goals
- [x] Support for unary operators
- [x] Pretty output
- [x] Input history
- [x] Tab Completions
- [ ] Functions
### Acknowledgements
1. The awesome [linenoise](https://github.com/arangodb/linenoise-ng) library.