Given this grammar:
<Program> ::= <Stmt> | <Program>; <Stmt>
<Conditional> ::= If <Bool> then <Program>
<Bool> ::= true | false
<Stmt> ::= <Conditional> | s1 | s2
How do I prove that it is ambiguous?
Given this grammar:
<Program> ::= <Stmt> | <Program>; <Stmt>
<Conditional> ::= If <Bool> then <Program>
<Bool> ::= true | false
<Stmt> ::= <Conditional> | s1 | s2
How do I prove that it is ambiguous?
If you can draw two parse trees (or equivalently, write two leftmost derivations) for the same sentence, the grammar is ambiguous. No general algorithm exists to do this (ambiguity is an undecidable problem), but for many grammars it's not hard.
The example @rici gave is sufficient.
If true then s1; s2
One parse tree is
<Program>
/ | \
<Program> ; <Stmt>
| |
<Stmt> s2
/|\__________
/ | \ \
If <Bool> then <Program>
| |
true <Stmt>
|
s1
I will let you work out the other one.