3

Whenever deterministic context-free languages are discussed, the webpage/textbook would always give a side note saying that although deterministic context-free languages are never ambiguous, unambiguous context-free languages may still be nondeterministic.

However, they never give an example. Is there a short, simple example of a context-free language that is

  • unambiguous
  • but nondeterministic
ithisa
  • 357
  • 2
  • 9

1 Answers1

6

$\{ww^R\mid w\in\{a,b\}^∗\}$ should do the job. The rest is up to you regarding proofs, such as providing an unambiguous grammar.

From Example of Non-Linear, UnAmbiguous and Non-Deterministic CFL? Third answer by Google.

Another one found similarly at Non-Deterministic CFLs: $\{x^ny^n \;\mid\; n \geq 0\} \cup \{x^ny^{2n} \;\mid\; n \geq 0\}$

babou
  • 19,445
  • 40
  • 76
  • 1
    So the language $ww^R$ does not have deterministic grammar? That's very interesting (so yacc shouldn't be able to parse it?) – ithisa May 27 '15 at 01:04
  • @user54609 AFAIK, Yacc will parse a lot of languages that are not deterministic, or grammars that are not LR(k). It makes choices, when it has to (with consequences you may guess). But I am not a big Yacc user, so you should rather check the Yacc literature,. – babou May 27 '15 at 07:45
  • I rather meant "parse without complaining about shift/reduce conflicts". – ithisa May 27 '15 at 19:30