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

Readiness

  • Parse v3 postfix expressions and blocks.
  • Predict v4 loop events and boolean precedence.
2 / 6

Worked reconstruction

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.

3 / 6

Diagnose before implementing

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.

4 / 6

Independent transfer

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.

5 / 6

Carry forward

Carry a faithful for AST into analysis. Keep clause absence, parse validity, and loop placement as three separate decisions.

6 / 6
←/→ or click edges to navigate · ? help · N notes · F fullscreen