title: Rewriting Bison grammar to fix shift/reduce conflicts
body: <p>Here are the relevant parts of my Bison grammar rules:</p>
  
  <pre><code>statement:
    expression ';' |
    IF expression THEN statement ELSE statement END_IF ';' 
    ;
  
  expression:
    IDENTIFIER |
    IDENTIFIER '('expressions')' |
    LIT_INT |
    LIT_REAL |
    BOOL_OP |
    LOG_NOT expression |
    expression operator expression |
    '('expression')'
    ;
  
  expressions:
    expression |
    expressions ',' expression  
    ;
  
  operator: 
    REL_OP |
    ADD_OP |
    MULT_OP |
    LOG_OR  |
    LOG_AND
    ;
  </code></pre>
  
  <p>When compiling, I get 10 shift/reduce conflicts:</p>
  
  <p>5 conflicts are caused by the <strong>LOG_NOT expression</strong> rule:</p>
  
  <pre><code>State 45
  
     25 expression: LOG_NOT expression .
     26           | expression . operator expression
  
      REL_OP   shift, and go to state 48
      ADD_OP   shift, and go to state 49
      MULT_OP  shift, and go to state 50
      LOG_OR   shift, and go to state 51
      LOG_AND  shift, and go to state 52
  
      REL_OP    [reduce using rule 25 (expression)]
      ADD_OP    [reduce using rule 25 (expression)]
      MULT_OP   [reduce using rule 25 (expression)]
      LOG_OR    [reduce using rule 25 (expression)]
      LOG_AND   [reduce using rule 25 (expression)]
      $default  reduce using rule 25 (expression)
  
      operator  go to state 54
  </code></pre>
  
  <p>5 conflicts are caused by the <strong>expressions operator expression</strong> rule:</p>
  
  <pre><code>State 62
  
     26 expression: expression . operator expression
     26           | expression operator expression .
  
      REL_OP   shift, and go to state 48
      ADD_OP   shift, and go to state 49
      MULT_OP  shift, and go to state 50
      LOG_OR   shift, and go to state 51
      LOG_AND  shift, and go to state 52
  
      REL_OP    [reduce using rule 26 (expression)]
      ADD_OP    [reduce using rule 26 (expression)]
      MULT_OP   [reduce using rule 26 (expression)]
      LOG_OR    [reduce using rule 26 (expression)]
      LOG_AND   [reduce using rule 26 (expression)]
      $default  reduce using rule 26 (expression)
  
      operator  go to state 54
  </code></pre>
  
  <p>I know that the problem has to do with precedence. For instance, if the expression was:</p>
  
  <p><strong>a + b * c</strong></p>
  
  <p>Does Bison shift after the a + and hope to find an expression, or does it reduce the a to an expression? I have a feeling that this is due to the Bison 1-token look-ahead limitation, but I can't figure out how to rewrite the rule(s) to resolve the conflicts.</p>
  
  <p>My professor will take points off for shift/reduce conflicts, so I can't use %expect. My professor has also stated that we cannot use %left or %right precedence values. </p>
  
  <p>This is my first post on Stack, so please let me know if I'm posting this all wrong. I've searched existing posts, but this really seems a case-by-case thing. If I use any code from Stack, I will note the source in my submitted project.</p>
  
  <p>Thanks!</p>