A simple tree-walk interpreter written in Rust for a Python-like language. This interpreter demonstrates the fundamental concepts of language implementation including lexical analysis, parsing, and evaluation.
- Lexical Analysis: Tokenizes source code into meaningful symbols
- Recursive Descent Parser: Parses tokens into an Abstract Syntax Tree (AST)
- Tree-Walk Evaluator: Executes the AST by traversing it
- Error Handling: Comprehensive error reporting with source location information using Ariadne
- REPL Mode: Interactive Read-Eval-Print Loop for experimentation
- File Execution: Run programs from source files
- Integers:
42,-10 - Floating Point:
3.14,-2.5 - Strings:
"hello world" - Booleans:
true,false
- Arithmetic:
+,-,*,/ - Assignment:
x = 5 - Parentheses:
(2 + 3) * 4
# Basic arithmetic
5 + 3 * 2
# Variable assignment
x = 10
y = 5
result = x + y
# Mixed type operations
pi = 3.14
radius = 5
area = pi * radius * radius
# String operations
greeting = "Hello"
name = "World"
message = greeting + " " + name
cargo runcargo run example.bccThe interpreter follows a traditional three-stage design:
- Lexer (
src/lexer.rs): Converts source code into tokens - Parser (
src/parser.rs): Builds an AST from tokens - Evaluator (
src/evaluator.rs): Executes the AST
See the individual documentation files in /docs for detailed explanations of each component.