title: Why does my ternary operator cause a shift-reduce conflict?
body: <p>The following is my grammar:</p>
  
  <pre><code>arithmetic_expression : expression + expression
                        | expression - expression
  
  expression            : constant
                        | ID
                        | arithmetic_expression
                        | ternary
  
  ternary               : expression ? expression : expression
  </code></pre>
  
  <p>I receive a shift-reduce error in this state:</p>
  
  <pre><code>state 126
  
      (19) ternary -&gt; expression QUESTION_MARK expression COLON expression .
      (27) arithmetic_exp -&gt; expression . PLUS expression
      (28) arithmetic_exp -&gt; expression . MINUS expression
      (19) ternary -&gt; expression . QUESTION_MARK expression COLON expression
  
    ! shift/reduce conflict for PLUS resolved as shift
    ! shift/reduce conflict for MINUS resolved as shift
    ! shift/reduce conflict for QUESTION_MARK resolved as shift
  
      PLUS            shift and go to state 86
      MINUS           shift and go to state 88
      QUESTION_MARK   shift and go to state 85
  
    ! PLUS            [ reduce using rule 19 (ternary -&gt; expression QUESTION_MARK expression COLON expression .) ]
    ! MINUS           [ reduce using rule 19 (ternary -&gt; expression QUESTION_MARK expression COLON expression .) ]
    ! QUESTION_MARK   [ reduce using rule 19 (ternary -&gt; expression QUESTION_MARK expression COLON expression .) ]
  </code></pre>
  
  <p>I believe the conflict is that</p>
  
  <pre><code>true ? 1 : false ? 3 : 2
  </code></pre>
  
  <p>can be interpreted as <code>true ? 1 : (false ? 3 : 2)</code> or <code>(true ? 1 : false) ? 3 : 2</code>.</p>
  
  <p>I have set the precedence for <code>+</code>, and <code>-</code> as left associative and higher level than <code>?</code> (which I set to right associativity).</p>
  
  <p>What am I doing wrong?</p>