title: Using precedence in Bison for unary minus doesn't solve shift/reduce conflict
body: <p>I'm devising a very simple grammar, where I use the unary minus operand. However, I get a shift/reduce conflict. In the Bison manual, and everywhere else I look, it says that I should define a new token and give it higher precedence than the binary minus operand, and then use "%prec TOKEN" in the rule.</p>
  
  <p>I've done that, but I still get the warning. Why?</p>
  
  <p>I'm using bison (GNU Bison) 2.4.1. The grammar is shown below:</p>
  
  <pre><code>%{
  #include &lt;string&gt;
  extern "C" int yylex(void);
  %}
  
  %union {
      std::string token;
  }
  
  %token &lt;token&gt; T_IDENTIFIER T_NUMBER
  %token T_EQUAL T_LPAREN T_RPAREN
  
  %right T_EQUAL
  %left T_PLUS T_MINUS
  %left T_MUL T_DIV
  %left UNARY
  
  %start program
  
  %%
  
  program : statements expr
  ;
  
  statements : '\n'
             | statements line
  ;
  
  line : assignment
       | expr
  ;
  
  assignment : T_IDENTIFIER T_EQUAL expr
  ;
  
  expr : T_NUMBER
       | T_IDENTIFIER
       | expr T_PLUS expr
       | expr T_MINUS expr
       | expr T_MUL expr
       | expr T_DIV expr
       | T_MINUS expr   %prec UNARY
       | T_LPAREN expr T_RPAREN
  ;
  </code></pre>