LL(1) & LR(0), SLR(1), LALR(1), CLR(1) Parsing Power & Conflicts
FIRST/FOLLOW rules, parsing hierarchy Venn relationships, state count equality between SLR(1) and LALR(1), and ambiguity.
LL(1) Grammar Necessary & Sufficient Conditions
- Grammar must be free of Left Recursion (an left-recursive grammar can never be ).
- For every non-terminal :
- If , then .
Ambiguous Grammars: An ambiguous grammar can NEVER be or for any ! Also, when merging states with identical cores to form , no new Shift-Reduce conflict can ever arise — only a Reduce-Reduce conflict can be introduced!
Practice Questions on This Chapter (6)
Which of the following statements about bottom-up LR parsers is FALSE?
Which pair of bottom-up LR parsers always have the exact same number of states for any given context-free grammar?
If a Context-Free Grammar is ambiguous, which of the following statements is guaranteed to be TRUE?
How many lexical tokens does a C lexical analyzer emit for the statement: printf("i = %d, &i = %x", i, &i);?
Consider a grammar that is LR(1) (CLR) and therefore unambiguous. When we merge LR(1) states sharing identical LR(0) cores to construct the LALR(1) parser, which new conflict(s) can possibly be introduced?
For the grammar , is the grammar LL(1) and/or SLR(1)?