Parsing Programs (v2)
New parsing responsibility
- move from raw expression parser to full program parser
- support top-level declaration list with
fn - parse statements in both top-level and block contexts
Dispatch model
parseDecl:- if
fnthen function declaration - else statement
- if
parseStmt:- vars, if/while/return/block
- assignment disambiguation when IDENT followed by
= - otherwise expression statement
Calls at this stage
- only identifier-call form is supported:
IDENT(args...) - this is before postfix/member forms in later versions
Assignment vs expression statement
IDENT = expr; is parsed as StmtAssign.
expr; otherwise.
Block and function boundaries
- function parsing happens only from declaration context
- blocks recurse through parseStmt
fninside block is treated as statement unless parser explicitly allows it
Practice focus
- top-level dispatch (fn vs stmt)
- missing braces/semicolons and boundary errors
- assignment lookahead
- nested blocks and return/if/while parse order
1 / 1