Consider the following grammar for IF-THEN-ELSE statements:

where b represents a boolean condition and a represents some other statements. Then IF b THEN IF b THEN a ELSE a has two parse trees.

The second parse, with ELSE associated with the closest IF is considered the way this should be parsed.

We can rewrite this grammar to be unambiguous:

Then, IF b THEN IF b THEN a ELSE a has only 1 parse

Send questions and comments to: Karen Lemone