Fixing terminal definition as a production.
@@ -341,10 +341,10 @@ def act_grammar(_, nodes):
to_del = []
for idx, p in enumerate(res):
if len(p.rhs) == 1 and isinstance(p.rhs[0], Terminal):
- # Check if terminal has multiple definitions
- if len([x for x in res if x.symbol == p.symbol]) > 1:
- raise GrammarError('Multiple definition for terminal "{}"'
- .format(p.symbol))
+ # Optimization: If a production has a single terminal RHS and there
+ # is only one production for this grammar symbol then treat is as a
+ # terminal.
+ if len([x for x in res if x.symbol == p.symbol]) == 1:
t = p.rhs[0]
terms[p.symbol.name] = t
t.name = p.symbol.name
