A console expression evaluator and utility DSL for arithmetic, conversions, encoding/decoding, and other programmable operations.
Inspired by the tree-walk interpreter architecture from Crafting Interpreters.
I think this project has reached a good milestone. I may or may not come back in future ;(
I needed a quick and handy tool to do stuff like number system conversions, unit conversions, encoders, and decoders. This project starts as a workable calculator prototype and gradually evolves into a more extensible expression engine with utility-focused features.
This also helps me revisit concepts like recursive descent parsing and AST evaluation that I learned from Crafting Interpreters. This project also serves as groundwork for building my first proper programming language with features I actually want (very ambitious goal, I know).
So, let's see how far I can go.
./exprcalcexprcalc v0.3
Press Ctrl+C to exit.
> 3+4*(2-9)^2
199
> log(2,dec(2CD))
9.485 829 308 7
> 3+4*(2-9)^2
199
> ans/2
99.5
> sin((140-20)*cos(60)^2)
0.5
> gcd(4,6)
2
> lcm(68,28)
476
> perm(hypot(3,4),3)
60
> min(34,89)
34
- ✅ Scanner/Tokenizer class complete
- recognize numbers, basic operators, parenthesis
- stores alphanumerics (first letter alphabet) as identifiers which can later be used for constants and function names
- ✅ Abstract Syntax Tree (AST)
- handles binary operators
(+,-,*,/,^), grouping, unary, literal values.
- handles binary operators
- ✅ Evaluator
- evaluates binary operators
(+,-,*,/,^), grouping, unary, and literal values - ⚠ exponent (
^) associativity currently incorrect
- evaluates binary operators
- ✅ Various mathematical, phisical and chemical constants (pi, G, NA, etc)
- ✅ Runtime variable support internally (can't make variables yet)
- ✅
ansvariable support for storing latest answerin memory
- ✅
- ✅ Functions calls, check src/library.cpp for the complete list
- leaks every node of Abstract Syntax Tree on synax/parse error.
- other times there is no leak