title: Issue resolving a shift-reduce conflict in my grammar
body: <p>I'm trying to write a small parser with <a href="http://www.codeplex.com/irony/" rel="nofollow noreferrer">Irony</a>. Unfortunately I get a "shift-reduce conflict". Grammars are not my strong point, and I only need to get this one small thingy done. Here's the reduced grammar that produces the error:</p>
  
  <pre><code>ExpressionTerm := "asd"
  LogicalExpression :=
      ExpressionTerm |
      LogicalExpression "AND" LogicalExpression |
      LogicalExpression "OR" LogicalExpression
  </code></pre>
  
  <p>What does the "shift-reduce conflict" mean and how can I solve it? I gather that it means that my grammar is ambiguous, but I cannot twist my logic sufficiently to see how.</p>
  
  <p><strong>Added:</strong> To clarify - "asd" is simply a literal string "asd". So I would expect that the following expressions are parsed by this grammar:</p>
  
  <pre><code>asd
  asd AND asd
  asd AND asd OR asd
  asd OR asd AND asd OR asd
  </code></pre>
  
  <p><strong>Added 2:</strong> Forgot to say, the root of the grammar is <code>LogicalExpression</code>.</p>
  
  <p><strong>Added 3:</strong> Ahh, I got it! The ambiguity is because an expression like</p>
  
  <pre><code>asd AND asd OR asd
  </code></pre>
  
  <p>could be interpreted in two different ways:</p>
  
  <pre><code>(asd AND asd) OR asd
  asd AND (asd OR asd)
  </code></pre>
  
  <p>But how can I solve this? OK, I can put one of AND or OR to be stronger than the other (I had inteded to anyway). But now I see that the error appears even if there is just one operator. In other words, this also produces the same error:</p>
  
  <pre><code>LogicalExpression := "asd" | LogicalExpression "OR" LogicalExpression
  </code></pre>
  
  <p>In this case I want this:</p>
  
  <pre><code>asd OR asd OR asd
  </code></pre>
  
  <p>to be parsed to this:</p>
  
  <pre><code>(asd OR asd) OR asd
  </code></pre>
  
  <p>What is the non-ambiguous way of doing this?</p>
  
  <p><strong>Added 4:</strong> Got it!</p>
  
  <pre><code>LogicalExpression1 := LogicalExpression1 "OR" LogicalExpression2 | LogicalExpression2
  LogicalExpression2 := LogicalExpression2 "AND" LogicalExpression3 | LogicalExpression3
  LogicalExpression3 := "NOT" LogicalExpression4 | LogicalExpression4
  LogicalExpression4 := "asd" | "(" LogicalExpression1 ")"
  </code></pre>
  
  <p>This parses all boolean expressions, with operator precedence as NOT->AND->OR. "asd" can be replaced with the expression intended for your terms.</p>