title: Arithmetic expression grammar in prefix notation (Java Cup)
body: <p>I'm writting a grammar for arithmetic expression in prefix notation. However I have an issue when parsing negative numbers or substraction. Grammar example is this:</p>
  
  <pre><code>precedence right +, -;
  precedence right *, /;
  precedence right uminus;
  
  E ::= + E E
     |  - E E
     |  * E E
     |  / E E
     |  ( E )
     |  - E %prec uminus
     |  id
     |  digit
     ;
  </code></pre>
  
  <p>But if my input is <code>- 5 4</code>, it reduces <code>5</code> as <code>E</code>, next it reduces <code>- E</code> (negative) and then parser gives me a syntax error at <code>4</code>. The correct one should be <code>5</code> as <code>E</code>, next <code>4</code> as <code>E</code> and then <code>- E E</code> as <code>E</code>. How can I solve this problem using associativity? or do I need to rewrite my grammar?</p>