How jkylander/codecrafters-interpreter-c works
Main Components
a) Scanner/Lexer (scanner.c/h)
• Input: Source code text
• Output: Token stream
• Purpose: Breaks source code into tokens
b) Parser (parse.c/h)
• Input: Token stream
• Output: Abstract Syntax Tree (AST)
• Purpose: Creates syntactic structure
c) AST Components (ast.c/h, stmt.h)
• Purpose: Represents program structure
• Contains: Expression and Statement nodes
d) Interpreter (interpreter.c/h)
• Input: AST
• Output: Execution results
• Purpose: Evaluates the AST
[Source Code] → [Scanner] → [Token Stream] → [Parser] → [AST] → [Interpreter] → [Program Output]
Component Details
For each major component, include a sub-section showing:
Scanner:
• Character processing
• Token generation
• Error handling
Parser:
• Grammar rules
• AST node creation
• Error recovery
AST:
• Expression types
• Statement types
• Tree structure
Interpreter:
• Environment handling
• Expression evaluation
• Statement execution
Important Relationships
• How the AST (ast.h) is used by both Parser and Interpreter
• Error handling flows
• Relationship between statements (stmt.h) and the AST
• Demonstrate the single-pass nature of the interpreter
Technical Details
• That this is a tree-walk interpreter
• Main execution flow starting from main.c
• Error reporting paths
• Where ANSI handling occurs (ansi.h)