A tiny Rust REPL that parses and evaluates arithmetic expressions.
- Supports
+,-,*,/with standard precedence - Parentheses for grouping
- Floating-point numbers
- Simple interactive REPL
Build and run:
cargo runYou should see a prompt like:
========== SimpL: Simple expression evaluator ===========
Enter arithmetic expressions like: 2 + 3 * 4
Type 'quit' or 'q' to exit
>>
>> (2 + 3) * 4
Parsed: ((2 + 3) * 4)
= 20
More examples are in examples/ with sample inputs and expected outputs.
- Whitespace is optional around operators.
- Unary minus (e.g.
-3) is not supported yet; use0 - 3instead. - Division by zero returns an error.
src/main.rs- REPL loop and I/Osrc/parser.rs- tokenizer and recursive-descent parsersrc/expr.rs- expression tree and evaluator