Ambiguous grammar
In computer science, an ambiguous grammar is a context-free grammar for which there exists a string that can have more than one leftmost derivation or parse tree. Every non-empty context-free language admits an ambiguous grammar by introducing e.g. a duplicate rule. A language that only admits ambiguous grammars is called an inherently ambiguous language. Deterministic context-free grammars are always unambiguous, and are an important subclass of unambiguous grammars; there are non-deterministic unambiguous grammars, however. For computer programming languages, the reference grammar is often ambiguous, due to issues such as the dangling else problem. If present, these ambiguities are... Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.
In computer science, an ambiguous grammar is a context-free grammar for which there exists a string that can have more than one leftmost derivation or parse tree. Every non-empty context-free language admits an ambiguous grammar by introducing e.g. a duplicate rule. A language that only admits ambiguous grammars is called an inherently ambiguous language. Deterministic context-free grammars are always unambiguous, and are an important subclass of unambiguous grammars; there are non-deterministic unambiguous grammars, however. For computer programming languages, the reference grammar is often ambiguous, due to issues such as the dangling else problem. If present, these ambiguities are generally resolved by adding precedence rules or other context-sensitive parsing rules, so the overall phrase grammar is unambiguous. Some parsing algorithms (such as Earley or GLR parsers) can generate sets of parse trees (or "parse forests") from strings that are syntactically ambiguous. The language \{x | x=a^n b^m a^{n^{\prime}} b^m \text { or } x=a^n b^m a^n b^{m^{\prime}}, \text { where } n, n', m, m' \geq 1\} is inherently ambiguous. Ogden's lemma can be used to prove that certain context-free languages, such as \{a^nb^mc^m | m, n \geq 1\} \cup \{a^mb^mc^n | m, n \geq 1\} , are inherently ambiguous. See for a proof. The union of \{a^n b^n c^m d^m \mid n, m > 0\} with \{a^n b^m c^m d^n \mid n, m > 0\} is inherently ambiguous. This set is context-free, since the union of two context-free languages is always context-free. But give a proof that no context-free grammar for this union language can unambiguously parse strings of form a^n b^n c^n d^n, (n > 0) . More examples, and a general review of techniques for proving inherent ambiguity of context-free languages, are found given by Bassino and Nicaud (2011).
Cite this
"Ambiguous grammar". 1789420166. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1374936733 JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy