CHAPTER 4 Flashcards
What does it mean for a grammar to be ambiguous?
A grammar is ambiguous if there exists at least one string in its language that has two or more different parse trees.
What does it mean for two grammars to be equivalent?
Two grammars
𝐺
1
G
1
and
𝐺
2
are equivalent if they generate the same language
𝐿
(
𝐺
1
)
=
𝐿
(
𝐺
2
)
L(G
1
)=L(G
2
).
- What is “left factoring”?
A transformation used to eliminate common prefixes to make a grammar suitable for LL parsing.
What is “left recursion”?
A grammar has left recursion if a nonterminal calls itself as the first symbol in its production.
Can LL(k) parsing algorithms handle common prefixes and left recursion?
LL(k) cannot handle left recursion (must eliminate it).
LL(k) struggles with common prefixes, but left factoring fixes this.
Can LR(k) parsing algorithms handle common prefixes and left recursion?
LR(k) parsers can handle left recursion naturally (no need for transformation).
LR(k) can also handle common prefixes without modification.