Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xfnty/calc
Simple mathematical expression solver that supports operator priorities.
https://github.com/xfnty/calc
ast beginner-project calculator lexer parser
Last synced: 2 days ago
JSON representation
Simple mathematical expression solver that supports operator priorities.
- Host: GitHub
- URL: https://github.com/xfnty/calc
- Owner: xfnty
- Created: 2023-08-30T18:55:47.000Z (over 1 year ago)
- Default Branch: stable
- Last Pushed: 2024-01-28T07:41:47.000Z (12 months ago)
- Last Synced: 2024-01-28T08:28:32.552Z (12 months ago)
- Topics: ast, beginner-project, calculator, lexer, parser
- Language: C++
- Homepage:
- Size: 1.06 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple Calculator in C++
![preview.gif](.github/preview.gif)
Much simpler [python version](https://github.com/xfnty/calc/tree/simple_version) (140 loc)
## Features
- REPL
- Floating-point numbers
- Mathematical constants: `Pi`, `e`
- Operators: `+`, `-`, `*`, `/`, `^`, `%`, `!`
- Grouping expressions: `(...)`, `|...|`## Building and Running
- Configure, build and run (after cloning the repo): `make`
- Configure CMake: `make c`
- Build the project: `make b`, `make build`
- Build and run: `make args="'-2 * 2 + 1.5!'"`
- Run: `make r ...`
- Run using gdb: `make d args="'1+5!'"``make configure build_type=Release` will disable debug messages.
## Credits & References
- [Crafting Interpreters](https://craftinginterpreters.com/) by Bob Nystrom
- [Catch2](https://github.com/catchorg/Catch2/)
- [expected](https://github.com/TartanLlama/expected)
- [fmt](https://github.com/fmtlib/fmt)
- [spdlog](https://github.com/gabime/spdlog)
- [cpp-linenoise](https://github.com/yhirose/cpp-linenoise)## TODO
- Parser error messages
- Make macros in `Util.h` an inline functions
- Better stack-related error handling
- Remove `else` blocks at the end of functions in `ExpressionEvaluator`
- Fix `^` operator and increase its precedence
- Better `std::string` usage
- Builtin functions: `sin()`, `ctan()`, `ln()`, `floor()`, `ceil()` ...
- Fix Windows build