https://github.com/kiblitz/stack-calculator
stack-based CLI postfix expression evaluator
https://github.com/kiblitz/stack-calculator
calculator cli cpp evaluator json postfix stack
Last synced: 3 months ago
JSON representation
stack-based CLI postfix expression evaluator
- Host: GitHub
- URL: https://github.com/kiblitz/stack-calculator
- Owner: kiblitz
- License: mit
- Created: 2020-10-15T22:45:29.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-10-25T03:57:32.000Z (over 5 years ago)
- Last Synced: 2025-10-31T10:39:56.652Z (8 months ago)
- Topics: calculator, cli, cpp, evaluator, json, postfix, stack
- Language: C++
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# stack-calculator
## About
CLI evaluator for postfix expressions (reverse Polish notation)
## Use
Download the release and execute it in the following form
```
./stack-calc [--stack] [file.json...]
```
- ### --stack
If enabled, displays the stack after every operation
- ### file.json...
Expand command list with json files
#### ex:
```
{
"abs":"dup 0 < if -1 * noop",
"dup":"1 pick",
"err":"2 pick - abs swap /"
}
```
### Commands
- **quit**: quits the program
- **help**: displays commands list
- **stack**: displays the stack
- **noop**: pass
- **clear**: empties stack
- **pop**: removes top of stack
- **popn**: removes top `n` elements of the stack (*ex: `1 2 3 2 popn` => `1`*)
- **skip**: skips next `n` commands (*ex: `2 skip 1 2 3 4` => `3 4`*)
- **pick**: copies the `n`th element of the stack (*ex: `2 3 4 2 pick` => `2 3 4 3`*)
- **swap**: swaps top `2` elements of the stack
- **if**: if the top element of the stack is `0`, skip the next `3` commands (*ex: `0 if 1 2 3 4` => `4`*)
- **>**, **=**, **<**: `1` if true, `0` otherwise (*ex: `2 < 3` => `1`*)
- **+**, **-**, **\***, **/**, **//**, **%**, **^**, **e**, **pi**, **ln**, **sin**, **arcsin**, **cos**, **arccos**, **tan**, **arctan**: standard functions
### Custom Commands
In the form `: command corresponding-commands... ;`
- **ex**: `: dup 1 pick ;`