A small, blazingly fast interpreted language. Cute name, serious intent.
Phase 1: The Tokenizer (Lexical Analysis)Goal: Convert a raw string of code into a stream of meaningful "Tokens."
- Define the
TokenEnum: Create a robust Enum in Rust to represent keywords, operators, and literals (e.g.,Token::Let,Token::Int(5),Token::Plus). - Implement the
TokenizerStruct: Use aPeekable<Chars>iterator to traverse the source code. - Handle Whitespace & Comments: Skip characters that don't affect logic.
- Identifier Recognition: Implement logic to distinguish between keywords (like
fn) and user-defined variables (likemy_var). - Rust Skill focus: Pattern matching on characters and
Iterators.
##Phase 2: The Parser (Syntactic Analysis)Goal: Turn the flat list of Tokens into a hierarchical Tree (Abstract Syntax Tree - AST).
- Define the AST Nodes: Use Enums and Structs to represent the grammar (e.g.,
Expression::Binary,Statement::Let). - Implement Recursive Descent: Write functions that call each other to handle grammar rules.
- Implement Pratt Parsing: Specifically for mathematical expressions to handle "Operator Precedence" (making sure
2 + 3 * 4equals14, not20). - Error Handling: Create a custom
ParseErrortype to report exactly where the user made a typo. - Rust Skill focus: Recursive data structures and
Box<T>(for heap allocation of recursive types).
- Define the
ObjectSystem: Create an Enum to represent your language's runtime values (Integer, Boolean, Null, Function). - The Eval Function: Create a recursive function that takes an AST node and returns an
Object. - Basic Arithmetic: Implement addition, subtraction, etc., by matching on AST nodes.
- Conditionals: Implement
if/elselogic. - Rust Skill focus: Deep understanding of
Enumsand result handling.
- The Environment Struct: Use a
HashMapto map variable names toObjectvalues. - Nested Scopes: Implement a system where inner scopes can see outer variables, but not vice versa.
- Function Literals: Store the function's parameters and body in the Environment.
- Closures: Handle functions that "capture" variables from their parent scope.
- Rust Skill focus:
Rc<RefCell<Environment>>to handle shared, mutable ownership of scopes.
Phase 5: The Virtual Machine (Compiling to Bytecode)Goal: Move from "Tree-Walking" to a high-performance "Bytecode VM" (0 to 100 level).
- The Compiler: Instead of evaluating the AST, write a compiler that emits "Opcodes" (e.g.,
OP_ADD,OP_CONSTANT). - The Bytecode Chunk: A structure to hold a sequence of bytes and a constant pool.
- The VM: Build a Stack-Based VM that loops through instructions. Use a
Vecas your stack. - Benchmarks: Compare the speed of your Tree-Walk interpreter vs. your Bytecode VM.
- Rust Skill focus: Low-level memory layout,
Vecoptimization, andmatchperformance.
##Phase 6: Quality of Life (The "Finish")* [ ] The REPL: Create a "Read-Eval-Print Loop" so you can type code into your terminal and see results instantly.
- Standard Library: Add built-in functions like
print(),len(), orpush(). - File Execution: Allow the VM to read and run
.yourlangfiles from the command line.
Riko the ermine — small but has bite.
