
Parsing 69
If unambiguous grammars are so important, why do we see so many languages having
this ambiguous conditional statement? All of j--, Java, C, and C++ include precisely this
same ambiguous conditional construct. One could easily modify the syntax of conditionals
to remove the ambiguity. For example, the programming languages S-Algol and Algol-S
define conditionals so:
(3.14)
S ::= if E do S
| if E then S else S
| s
E ::= e
Here, the do indicates the simpler conditional (having no else clause) while the then
indicates the presence of an else clause. A simple solution but it does change the language.
But programmers have become both accustomed to