# Why is this grammar ambiguous?

S ::= x
S ::= if E then S
S ::= if E then S else S



This is example if E then if E then x else x proves that it is ambiguous but I don't see why? Isn't it just an if statement within an if statement.

• The else could be part of either if, according to the grammar. Search for "dangling else". – rici Oct 30 '19 at 0:56

if E then ( if E then x ) else x

if E then ( if E then x else x )