How wuihee/toy-compiler works
Toy Compiler is a MiniJava front end with two user-facing commands: scan reads a source file and prints tokens; parse reads a file, builds an AST, and prints it or a formatted parse error. The implemented stages are file/CLI dispatch, lexing, and parsing; type checking and later compiler stages are planned, not runtime components. Parser internals are sampled only partially, so the graph limits links to documented or directly evidenced interactions.
Main entry points: lib.rs File workflows · parser.rs MiniJava parser · lexer.rs Lexer · main.rs Command dispatch
Components 14
CLI and file entry
- Command dispatch
src/main.rs - Command definitions
src/cli.rs - File workflows
src/lib.rs
Lexing
- Lexer
src/lexer.rs - Keyword lookup
src/lexer/keywords.rs - Token definitions
src/lexer/token.rs
Parsing and diagnostics
- MiniJava parser
src/parser.rs - Operator binding powers
src/parser/binding_powers.rs - AST model
src/ast.rs - Parse error formatting
src/parser/errors.rs - Source locations
src/span.rs
Other components
- Compiler user
- MiniJava source
- Terminal output
Connections 17
- Compiler user → Command dispatch: runs command
- Compiler user → MiniJava source: provides file
- Command dispatch → Command definitions: parses arguments
- Command dispatch → File workflows: dispatches scan or parse
- File workflows → MiniJava source: reads file
- File workflows → Lexer: creates lexer
- File workflows → MiniJava parser: creates parser
- Lexer → Keyword lookup: looks up words
- Lexer → Token definitions: produces tokens
- MiniJava parser → Lexer: consumes tokens
- MiniJava parser → Operator binding powers: gets operator precedence
- MiniJava parser → AST model: builds AST
- MiniJava parser → Parse error formatting: returns parse errors
- File workflows → Parse error formatting: formats parse errors
- Parse error formatting → Source locations: locates error
- Lexer → Source locations: marks token positions
- File workflows → Terminal output: prints tokens, AST, or error