| commit | 519412600929d0dc64638699a9fd497a4f92416a | [log] [tgz] |
|---|---|---|
| author | Sketch🕴️ <skallywag@sketch.dev> | Sat Feb 28 21:09:37 2026 +0400 |
| committer | Sketch🕴️ <skallywag@sketch.dev> | Sat Feb 28 21:09:37 2026 +0400 |
| tree | c2ab830a826ad73e7410c4cd0dfdd02def5a0303 | |
| parent | 5a0d94fb5cc18a1d137a9e3e301497e81992b4df [diff] |
Resurrect old plan
A math expression evaluator with an interactive REPL, written in Go.
+, -, *, /.5 syntax)* and / bind tighter than + and -)go build -o matheval ./cmd/matheval
Run the REPL:
./matheval
Then type expressions:
>> 2 + 3 * 4 14 >> (2 + 3) * 4 20 >> 7 / 2 3.5 >> 1 / 0 error: division by zero
Press Ctrl+D (EOF) to exit.
You can also pipe input:
echo "2 + 3" | ./matheval
Input string → Lexer → Parser → AST → Evaluator → Result
| Package | Responsibility |
|---|---|
token | Token types and data structures |
lexer | Tokenizes input string |
ast | AST node types (NumberLit, BinaryExpr) |
parser | Recursive-descent parser |
evaluator | Walks AST and computes result |
repl | Read-eval-print loop |
expr → term (('+' | '-') term)*
term → factor (('*' | '/') factor)*
factor → NUMBER | '(' expr ')'
go test ./...
This runs unit tests for each package plus integration tests covering the full pipeline.