Parsing & Syntax Analysis



Answer & solution
Answer: Root loop S, body block S, two assignment statements linked by L→S;L. (no official key was published)
The outermost construct is the for production, not a sequencing block. Its body is one statement S expanded as begin L end. Inside that block the list has two assignments, so its first L uses S;L and its final L uses S.
S ├─for ├─id(j) ├─:= ├─E(2) ├─to ├─E(10) ├─do └─S ├─begin ├─L │ ├─S │ │ ├─id(x) │ │ ├─:= │ │ └─E(expr1) │ ├─; │ └─L │ └─S │ ├─id(y) │ ├─:= │ └─E(expr2) └─end
Reading leaves left to right gives exactly the requested token sequence. The E subtrees are abbreviated because the expression grammar was stipulated as already defined; 2 and 10 are constant expressions and expr1/expr2 stand for their expression subtrees. The semicolon separates the two assignments, while begin/end make both assignments part of a single loop body.