I am trying to write a LL(1) parser generator and I am running into a issue with grammars which I know to be LL(1) but I cannot factor them properly.
For example consider the grammar:
S -> As Ao
As -> a As
As -> Ɛ
Ao -> a
Ao -> Ɛ
Now this grammar has a first-follow conflict in As
so I perform Ɛ elimination and have:
S -> As Ao
S -> Ao
As -> a As
As -> a
Ao -> a
Ao -> Ɛ
Which has a first-first conflicts in S
and As
. Resolving the conflict in As
produces:
S -> As Ao
S -> Ao
As -> a As'
As' -> As
As' -> Ɛ
Ao -> a
Ao -> Ɛ
Which has a first-follow conflict in As'
which when eliminated simply cycles. Further, the conflict in S
cannot be solved via left factorization
I believe the issue is that As Ao == As
if I knew how to prove this I believe the issue would go away as the initial grammar could be transformed to:
S -> As
As -> a As
As -> Ɛ
Is there standard techniques for resolving such conflicts?
edit: I realize the grammar above is ambiguous. The grammar I am really interested in parsing is:
S -> a As Ao
As -> , a AS
As -> Ɛ
Ao -> ,
Ao -> Ɛ
I.e. a comma separated list of a
with an optional trailing comma.