edited by
4,700 views

1 Answer

Best answer
38 votes
38 votes

Given CFG is "ambiguous" as you told. Is it deterministic? If so there must be a LR(k) grammar for it. This is not the case here - See this

And answer to your question is NO - because that is the definition of inherent ambiguity. If a language is inherently ambiguous it can have no unambiguous grammar possible. Now, no DCFL is inherently ambiguous - any DCFL must have some unambiguous grammar.

Some facts:

  1. DCFL has a one-one correspondence with LR(1) grammar and since LR(k) grammar is unambiguous this means no DCFL can be inherently ambiguous. 
  2. A DCFL can have an ambiguous grammar - just that some unambiguous grammar is also guaranteed to exist.
  3. If A CFL is not deterministic it may or may not have an unambiguous grammar. i.e., If the language of the grammar is not deterministic, still the grammar can be either ambiguous or not-ambiguous. i.e., Not-deterministic does not imply inherent ambiguity but inherent ambiguity does imply not deterministic. 

Quoting from Wikipedia:

Unambiguous grammars do not always generate a DCFL. For example, the language of even-length palindromes on the alphabet of 0 and 1 has the unambiguous context-free grammar S → 0S0 | 1S1 | ε. An arbitrary string of this language cannot be parsed without reading all its letters first which means that a pushdown automaton has to try alternative state transitions to accommodate for the different possible lengths of a semi-parsed string

selected by

Related questions

1 votes
1 votes
1 answer
1