v4 Parsing

for + loop control parser

  • for has optional init / condition / post clauses
  • break and continue are leaf statements with required ;

for header model

for (init; cond; post) { ... }

  • parse init without trailing ;
  • parse condition as optional expression
  • parse post as optional expression without trailing ;
  • require ) and block

precedence ladder

expr -> or -> and -> equality

or -> and ("||" and)* and -> equality ("&&" equality)*

practical checks

  • for (;;) is legal
  • missing semicolons are syntax errors at parse boundary
  • invalid assignment target in loop init/post is diagnosed by parser
  • a || b && c || d follows precedence

parser resilience

  • keep diagnostics precise at semicolon / paren boundaries
  • synchronize after failed for header to avoid cascading errors
1 / 1
Use arrow keys or click edges to navigate. Press H to toggle help, F for fullscreen.