Ambiguity Through Two Parse Trees

A grammar is ambiguous when one terminal string has more than one distinct parse tree under that grammar.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace repeated pieces
  2. Distinguish derivation order
  3. Compare two distinct groupings of one token sequence
  4. Provide trees when claiming ambiguity

Trace repeated pieces

With a rule splitting S into two S symbols and an alternative terminal a, aaa can group its first two leaves or its last two. See context-free grammar ambiguity.

Distinguish derivation order

Expanding two independent subtrees in a different order can describe the same tree. Compare parent-child structure when giving an ambiguity witness. Tree shapes provide the representation.[1]

Compare two distinct groupings of one token sequence

A grammar with expression productions for binary subtraction and numeric literals, but no associativity restriction, can parse 8-3-2 with either subtraction as root. One parse evaluates to three and the other to seven under ordinary subtraction. See syntax trees and associativity.

Parse 1: (8-3)-2 = 5-2 = 3
Parse 2: 8-(3-2) = 8-1 = 7
Both trees preserve token order 8,-,3,-,2

Provide trees when claiming ambiguity

Two different orders of expanding independent branches can describe one tree. An ambiguity witness needs distinct trees for the same completed word. A layered grammar or declared associativity can select one interpretation.

References

  1. Michael Sipser, Introduction to the Theory of Computation ↩