title: Precedence of operators in BNF grammar
body: <p>I'm doing a homework assignment where I am give some BNF grammar:</p>
  
  <pre><code>&lt;assign&gt; -&gt; &lt;id&gt; = &lt;expr&gt;
  &lt;id&gt; -&gt; A | B | C
  &lt;expr&gt; -&gt; &lt;expr&gt; + &lt;term&gt;
        | &lt;term&gt;
  &lt;term&gt; -&gt; &lt;term&gt; * &lt;factor&gt;
        | &lt;factor&gt;
  &lt;factor&gt; -&gt; ( &lt;expr&gt; )
        | &lt;id&gt;
  </code></pre>
  
  <p>and the question is: </p>
  
  <p>"Rewrite this grammar so that the <code>+</code> operator is right associative and takes precedence over the <code>*</code> operator."</p>
  
  <p>A classmate suggested we simply switch the <code>+</code> and <code>*</code> operators and then <code>+</code> will have precedence and gain right association, however I don't think this is correct since the question is recursive. </p>
  
  <p>My question is, does the <code>+</code> operator gain precedence and right association by simply switching it with the <code>*</code> operator? My two thoughts are to remove the recursion and do what my classmate suggests, or put the <code>+</code> operator in a condition where is must be surrounded by <code>(</code> and <code>)</code> to work. </p>
  
  <p>Maybe I'm over thinking this? </p>