Math 2.0

Computer science Definition

Ambiguous grammar

Builds on Context-free grammarContext-free languageRooted tree

Definition

Let G=(N,Σ,P,S)G = (N, \Sigma, P, S) be a context-free grammar. The grammar GG is ambiguous if some word w∈L(G)w \in L(G) has two different leftmost derivations from SS. Otherwise GG is unambiguous.

Remarks

Equivalently, GG is ambiguous if some word of L(G)L(G) has two different parse trees, since parse trees, which are rooted trees, correspond one-to-one to leftmost derivations. Example: the grammar with rules E→E+EE \to E + E and E→aE \to a is ambiguous. The word a+a+aa + a + a has the two leftmost derivations E⇒E+E⇒a+E⇒a+E+E⇒a+a+E⇒a+a+aE \Rightarrow E + E \Rightarrow a + E \Rightarrow a + E + E \Rightarrow a + a + E \Rightarrow a + a + a and E⇒E+E⇒E+E+E⇒a+E+E⇒a+a+E⇒a+a+aE \Rightarrow E + E \Rightarrow E + E + E \Rightarrow a + E + E \Rightarrow a + a + E \Rightarrow a + a + a. Non-example: the grammar with rules E→E+aE \to E + a and E→aE \to a is unambiguous. Every sentential form contains a single EE, and a word with kk letters aa forces k−1k - 1 uses of E→E+aE \to E + a followed by one use of E→aE \to a. A context-free language is inherently ambiguous if every context-free grammar that generates it is ambiguous; {aibjck:i=j or j=k}\set{a^i b^j c^k : i = j \text{ or } j = k} is such a language.

Reading path

To understand this page from the ground up, read these 4 pages in order. The foundations come first.

Show the path as a graph
Each page uses the pages above it. The colour of the bar on a box shows how strong the evidence is, and the box also gives it as text. The list has the same pages.
  • no evidence level
  1. Context-free grammar concept
  2. Context-free language concept
  3. Rooted tree concept
  4. Ambiguous grammar definition

Further reading

  1. Web https://en.wikipedia.org/wiki/Ambiguous_grammar
About this page
TagWEJJSM62WM
URIm2://WEJJSM62WM
Kinddefinition
WritingW0 stub
MSC68Q42, 68Q45
DefinesAmbiguous grammar
UsesContext-free grammar, Context-free language, Rooted tree
Changed3 November 2026

Markdown · JSON · Edit on GitHub

What this page needs for W1

  • an inventory row: the row of the inventory that the node accounts for (0 of 1)
  • a source with a locator (0 of 1)

The writing levels say how complete the text of a page is. They do not measure its truth.

What links here

No page links to this page yet.