Ambiguous Grammars
Ambiguity in grammars is a very important concept in Context-Free Grammars (CFGs) , especially because it directly affects parsing, compiler design, and language clarity . 🔹 What is Ambiguity in a Grammar? A context-free grammar (CFG) is said to be ambiguous if at least one string in the language it generates has more than one distinct parse tree (or equivalently, more than one leftmost or rightmost derivation). 👉 Formally: A CFG G G is ambiguous if ∃ w ∈ L ( G ) such that w has two or more different parse trees. \exists \; w \in L(G) \quad \text{such that} \quad w \;\; \text{has two or more different parse trees.} 🔹 Why is Ambiguity a Problem? In programming languages , ambiguity makes parsing uncertain : Example: Does a + b * c mean (a + b) * c or a + (b * c) ? Compilers require deterministic parsing → ambiguous grammars must be avoided or rewritten. 🔹 Example of an Ambiguous Grammar Consider the C...