v4 Parsing: for loops and short-circuit logic
- Assign for-header delimiters to the correct parser.
- Represent missing clauses without losing loop structure.
- Parse loop-control syntax without enforcing analyzer context.
1 / 6
For for (let i=0; i<3; i=i+1) { continue; }:
| AST field | Shape | Delimiter owned by outer parser |
|---|---|---|
| Init | variable declaration i initialized to 0 | first ; |
| Cond | Lt(Ident(i),Number(3)) | second ; |
| Post | assignment to i with Add(i,1) | ) |
| Body | one Continue statement | closing } |
For for (;;) { break; }, all three clause fields are nil. Compilation later
supplies true for the absent condition; parsing should preserve absence rather
than inventing a source expression. The body still requires braces.
A header parser calls the ordinary semicolon-consuming declaration parser for init and then consumes another semicolon. Explain why a valid for header fails and which routine should own that token.
Draw the AST for for (;ready || a && b;) { break; }, marking nil fields and the logical root. Produce one missing-semicolon error and one syntactically valid but semantically illegal break outside a loop.
Carry a faithful for AST into analysis. Keep clause absence, parse validity, and loop placement as three separate decisions.