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.
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It only takes a minute to sign up.Sign up to join this community
Rici is correct. The statement could be reasonably interpreted, as you first assumed:
if E then ( if E then x ) else x
It may also be interpreted:
if E then ( if E then x else x )
In a context-free grammar, the allowable set of expressions are determined through substitution. In the first interpretation I took your third statement and substituted the first S for the second statement, and then replaced all remain S with x. In the second interpretation, I took your second statement and replaced it with the third statement, and replaced the remaining S with x using the first statement.