Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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