1

I'm attempting to come up with a non-ambiguous grammar for arithmetic expressions to make an Earley parser faster but I seem to be having trouble. This is the given ambiguous grammar

S -> E | S,S
E -> E+E | E-E | E*E | (E) | -E | V
V -> a | b | c

this is my attempt at making it unambiguous

S -> S+E | S-E | E | (S+E) | (S-E) | (E)
E -> E*T | E
T -> -V | V
V -> a | b | c

It parses everything fine but there isn't any significant speedup as compared to using the ambiguous one.

hippietrail
  • 15,848
  • 18
  • 99
  • 158
  • 1
    Your answer: [**A correct unambiguous version of your grammar is linked**](http://stackoverflow.com/questions/14554752/how-can-i-add-parentheses-as-the-highest-level-of-precedence-in-a-simple-grammar?answertab=votes#tab-top). Let me know if you need any other help – Grijesh Chauhan Feb 24 '13 at 20:04
  • Because of introduction of new variables in non-ambiguous grammar parse tree become lengthy and it become reason for slow parsing. That is the reason that tools like YACC provides way resolve ambiguity explicitly(out size grammar by writing precedence rules). – Grijesh Chauhan Feb 24 '13 at 20:10

0 Answers0