Questions: Lookahead in Parsing and Grammar Classes

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

An LL(1) parser and an LR(1) parser both use exactly one token of lookahead. Why is LR(1) strictly more powerful?

ALR(1) parsers read tokens from right to left, gaining more context about the input structure
BLR(1) parsers encode the complete left context (everything already parsed) in their state, so the same single lookahead token carries more disambiguating information in combination with that accumulated context
CLR(1) parsers use a stack of tokens rather than a single lookahead, effectively seeing multiple symbols ahead
DLR(1) parsers can backtrack and try alternative parses when a conflict occurs
Question 2 Multiple Choice

A grammar has an LL(1) conflict because two productions for nonterminal A both can follow the same FIRST token. Which approach will NOT genuinely resolve the conflict?

ALeft-factor the grammar to share the common prefix in a single production before branching
BSwitch to an LR(1) parser generator, since LR(1) can handle this grammar class
CIncrease the lookahead to LL(2), which may resolve the conflict if the second token disambiguates
DUse a Yacc/PLY parser, since it automatically resolves all conflicts via default shift/reduce rules
Question 3 True / False

Every grammar that is LL(1) is also LR(1), but not every LR(1) grammar is LL(1).

TTrue
FFalse
Question 4 True / False

An LR(1) parser examines more tokens of lookahead than an LL(1) parser, which is why it can handle more grammars.

TTrue
FFalse
Question 5 Short Answer

Why can't an LL parser handle left-recursive grammars, even with increased lookahead?

Think about your answer, then reveal below.