【正文】
mar is LL(1) or LR(1), so we must either rewrite the grammar to remove the ambiguity or resolve conflicts in the parser table or implementation. The hierarchy of LR variants is clear: every LR(0) grammar is SLR(1) and thus LALR(1) which in turn is LR(1). There are grammars that don’t meet the requirements for the weaker forms that can be parsed by the more powerful variations. We’ve seen several examples of grammars that are not LL(1) that are LR(1). A not immediately obvious fact is that every LL(1) grammar is LR(1). Proving this rigorously is a little tricky, but your intuition should tell you that an LR(1) parser uses more information the LL(1) parser Parsing miscellany A different way of resolving ambiguity Ambiguity in a grammar means we have two or more leftmost derivations for the same input string, or equivalently, that we can build more than one parse trees for the same input string. Common examples: E – E + E | E * E | (E) | id S – iSeS | iS | a rewriting the grammar to introduce new intermediate nonterminals that force the precedence that we desired. to build an SLR(1) table for this grammar. 3. try to build an LL(1) table for this grammar 。). b) If [S39。 (augmented by adding the special production S39。 – S? is in Ii then set action[i,] to accept. c) If A – u?av is in Ii and succ(Ii, a) = Ij, then set action[i,a] to shift j (a must be a terminal). 3. The goto transitions for state i are constructed for all nonterminals A using the rule: If GO(Ii, A) = Ij, then goto [i, A] = j. 4. All entries not defined by rules 2 and 3 are errors. 5. The initial state is the one constructed from the configurating set containing S39。. 2. State i is determined from Ii. The parsing actions for the state are determined as follows: a) If A – u? is in Ii then set action[i,a] to reduce A – u for all a in Follow(A) (A may not be S39。 – S? is in Ii then set action[i,] to accept. c) If A – u?av is in Ii and GO(Ii, a) = Ij, then set action[i,a] to shift j (a is a terminal). 3. The goto transitions for state i are constructed for all nonterminals A using the rule: If GO(Ii, A) = Ij, then goto [i, A] = j. 4. All entries not defined by rules 2 and 3 are errors. 5. The initial state is the one constructed f