I have a little problem with this exercise.
Given this grammar:
S -> aX | X
X -> aXb | b | eps
a) shows that it is ambiguous with a string
b) say what language captures the grammar
c) change the grammar and build a descendant parser
Solution by me:
a) I shows the ambiguous with the string 'ab':
- S -> aX -> ab
- S -> X -> aXb -> ab
b) the grammar captures this language:
L = {a^n b^n: n >= 0} U {a^n b^m: n=m+1, n,m >= 0} U {a^n b^m: m=n+1, n,m >= 0}
c) my problem is change the grammar to build the parser. I try different grammars but they are ambiguous also. For example this:
- G -> X$
X -> aX' | b | eps
X' -> XB | eps
Can you help me to find a correct grammar for the exercise or give me an input?