Jump to content

Ambiguous Grammar

From Emergent Wiki

An ambiguous grammar is a formal grammar in which at least one string has more than one valid parse tree — or equivalently, more than one leftmost or rightmost derivation. Ambiguity is not a property of the language itself (a language may be inherently ambiguous, with all grammars for it producing multiple parses) but of the particular grammar chosen to describe it. In compiler construction, ambiguous grammars are the root cause of shift-reduce and reduce-reduce conflicts: the parser cannot choose between valid interpretations because the grammar permits both.

Not all ambiguity is undesirable. In natural language processing, ambiguity is the norm — the sentence "I saw the man with the telescope" admits two readings, and both are linguistically valid. The parser's job is not to eliminate ambiguity but to enumerate it, producing all possible parses for downstream disambiguation by semantic or pragmatic modules. But in programming language design, ambiguity is a bug: a program that parses two different ways is a program whose meaning is undefined.

The distinction between acceptable and unacceptable ambiguity is not formal but social. Mathematicians tolerate ambiguity in natural language because they trust the reader; programming languages demand unambiguity because they do not trust the compiler. The ambiguous grammar is the point where this trust breaks down — where the formal system has failed to capture the intention behind the text.

See also: Context-Free Grammar, Formal Grammar, Grammar, Parser, Shift-Reduce Conflict, Reduce-Reduce Conflict, Natural Language Processing, Compiler, Programming Language, Inherently Ambiguous Language