I need to prove this context free grammar ambiguous, I know to prove this I need to find 2 different paths of the same string, but this question has 'begin' and 'end' which I don't know what they mean
S -> begin A end
A -> A ; A | a | S
I need to prove this context free grammar ambiguous, I know to prove this I need to find 2 different paths of the same string, but this question has 'begin' and 'end' which I don't know what they mean
S -> begin A end
A -> A ; A | a | S
Hint:
I hope this helps $\ddot\smile$.
begin and end must be terminals.
all CFG (without useless symbols) with left and right recursion for the same symbol is ambiguous.
In this case, the productions A -> A ; A | a | S are causing ambiguity.
For example, the string 'begin a; a; a end' has 2 leftmost derivations:
S > begin A end > begin A ; A end > begin A ; A; A end > begin a ; A ; A end > begin a ; a ; A end > begin a ; a ; a end
S > begin A end > begin A ; A end > begin a ; A end > begin a ; A ; A end > begin a ; a ; A end > begin a ; a ; a end
This is because the production A -> A ; A does not indicate whether the ";" is left or rigth associative. If you want ";" to be left associative, you should write:
A -> A ; a | A ; S | a | S
I hope this help you.