<P> 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, while an unambiguous grammar is a context - free grammar for which every valid string has a unique leftmost derivation or parse tree . Many languages admit both ambiguous and unambiguous grammars, while some languages admit only ambiguous grammars . Any non-empty language admits an ambiguous grammar by taking an unambiguous grammar and introducing a duplicate rule or synonym (the only language without ambiguous grammars is the empty language). A language that only admits ambiguous grammars is called an inherently ambiguous language, and there are inherently ambiguous context - free languages . Deterministic context - free grammars are always unambiguous, and are an important subclass of unambiguous grammars; there are non-deterministic unambiguous grammars, however . </P> <P> 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 . The set of all parse trees for an ambiguous sentence is called a parse forest . </P>

When is a grammar said to be ambiguous
find me the text answering this question