SLIDE 40
then accept end
LL(1): illustration of run of the algo * Remark The most interesting steps are of course those dealing with the dangling else, namely those with the non-terminal else−part at the top of the stack. That’s where the LL(1) table is ambiguous. In principle, with else−part on top of the stack (in the picture it’s just L), the parser table allows always to make the decision that the “current statement” resp “current conditional” is done. Expressions Original grammar exp → exp addop term ∣ term addop → + ∣ − term → term mulop factor ∣ factor mulop → ∗ factor → (exp ) ∣ number left-recursive ⇒ not LL(k)
Left-rec removed exp → term exp′ exp′ → addop term exp′ ∣ ǫ addop → + ∣ − term → factor term′ term′ → mulop factor term′ ∣ ǫ mulop → ∗ factor → ( exp ) ∣ n First Follow exp (, number $, ) exp′ +, −, ǫ $, ) addop +, − (, number term (, number $, ), +, − term′ ∗, ǫ $, ), +, − mulop ∗ (, number factor (, number $, ), +, −, ∗
40
SLIDE 79
Index
$ (end marker symbol), 8 abstract syntax tree, 17 ambiguity of a grammar, 22 associativity, 12, 29, 30 bottom-up parsing, 43 comlete item, 52 constraint, 4 context-free grammar reduced, 25 CUP, 77 dangling-else, 73 determinization, 15 EBNF, 14, 27, 35, 36 ǫ-production, 12, 13 First set, 1 Follow set, 1 follow set, 8, 47 grammar ambiguous, 22 LL(1), 25 LL(K), 24 start symbol, 8 handle, 46 higher-order rewriting, 26 initial item, 52 item complete, 52 initial, 52 LALR(1), 43 left factor, 12 left recursion, 12 left-derivation., 25 left-factoring, 11, 27, 38 left-recursion, 11, 12, 28, 29, 38 immediate, 11 linear production, 25 LL(1), 25, 27 LL(1) grammars, 37 LL(1) parse table, 38 LL(k), 24 LL(k)-grammar, 24 LR(0), 43, 52, 66 LR(1), 43 non-determinism, 26 non-terminal symbol, 26 nullable, 2, 24 nullable symbols, 1 parse error, 84 parse tree, 26 parser, 17 predictive, 27 recursive descent, 27 parsing bottom-up, 43 precedence, 29 predict-set, 26 predictive parser, 27 prefix viable, 51 production linear, 25 recursive descent parser, 27 reduced context-free grammar, 25 rewriting, 25 higher-order, 26 sentential form, 1 shift-reduce parser, 44 SLR(1), 43, 66 string rewriting, 26 syntax error, 17 term rewriting, 26 terminal symbol, 26 transducer tree, 26 transduction, 26 tree transducer, 26 type error, 17 viable prefix, 51 worklist, 6, 8, 9 worklist algorithm, 6, 8, 9 yacc, 77
79