Each nonterminal is referenced only once here, so we can combine the whole grammar in one expression:
s = a | ((a | h | f) gd)
So, we have two main options: a terminal, optionally followed by g, then d, or one of h or f, always followed by g, then d.
So we have
s = b' | c' b' = a | agd c' = (h | f) gd
or by pulling the overall gd sequence into your own production
s = b' | c' b' = a | ae' c' = (h | f) e' e' = gd
Then we can pull up like a regular start character in b 'by entering the parameter E (empty):
s = b'' | c' b'' = a (e' | E) c' = (h | f) e' e' = gd
Grammar is now unambiguous.
source share