Lexing & Parsing
Goal
Convert raw C source into a structured AST that preserves operator precedence, associativity, and nesting for the supported subset.
Design
The lexer emits typed tokens. A recursive-descent parser maps tokens into AST nodes. Unary and binary uses of the same operator are disambiguated by grammar position. Surface syntax stays separate from later machine-specific concerns.
Challenges
- Nested unary expressions such as ~(-2) force careful consume/produce order in the parser.
- Malformed token streams need useful errors without poisoning later stages.
- Precedence and associativity must be encoded in the parse structure, not patched during codegen.
Iterations
- Return integer literals.
- Unary negation and complement.
- Nested unary combinations.
- Scaffolding toward binary operators, statements, and control flow as the language grows.
Final implementation
A deterministic parser that produces an AST suitable for resolution and lowering. Syntax structure is frozen before semantic meaning is decided.
Nested unaries become explicit tree structure before IR lowering.