# unambiguous SLR grammar, with both binary and unary minus nonterminal E Expr nonterminal T Expr nonterminal F Expr terminal ( ) * - + typedterminal num Integer topsym E # top level grammar symbol # precedence and associativity declarations not needed # Grammar production rules, order breaks reduce-reduce conflicts # spaces must separate grammar elements E --> E:e - T:t { return new subexp(e,t); } E --> E:e + T:t { return new sumexp(e,t); } E --> T:t { return t; } T --> T:t * F:f { return new multexp(t,f); } T --> F:f { return f; } F --> num:x { return new intexp(x); } F --> ( E:e ) { return e; } F --> - F:e { return new negexp(e); } # ends file, whatever follows EOF is ignored: EOF What would happen if the unary - (negative) is represented by: T --> - F F --> num F --> ( E ) This is also unambiguous, and will suffice to parse 4 - -2, but not 4 - --2. - binds tighter than +,- and *. However, since it's a unary operation there is no problem with associativity, otherwise we would another nonterminal. Say you wanted another binary operator A ^ B, which binds tighter than anything else, and which associates to the RIGHT, you would need to change the grammar with the following: F --> G ^ F F --> G G --> num G --> (E)