Why we need to know LR and recursive descent parsing techniques
What an excellent article that I agree almost entirely with.<p>I&#x27;d like to add nuance in two places:<p>&gt; If you&#x27;re writing a parser for a language which is ambiguous, you might be able to use the conflict resolution offered by YACC and friends. However, in general, I suggest avoiding YACC&#x27;s conflict resolution if possible, as you have to at least somewhat understand the underlying LR algorithm to understand how conflicts have been resolved.<p>I&#x27;d say: Specifically for binary operator precedence and associativity, definitely use conflict resolution of Yacc and friends instead of rewriting the grammar. An ambiguous grammar for binary operators might look like:<p><pre><code>  E → E ^ E
  E → E × E
  E → E + E
  E → (E)
  E → num
</code></pre>
Disambiguating in Yacc and friends involves a few lines like:<p><pre><code>  %left  ´+´
  %left  ´×´
  %right ´^´
</code></pre>
whereas rewriting the grammar above to be unambiguous is a mess:<p><pre><code>  E₀ → EA E₁
  EA → E₁ + EA
  EA → ε
  E₁ → EM E₂
  EM → E₂ × EM
  EM → ε
  E₂ → E₃ EP
  EP → ^ E₃ EP
  E₃ → num
  E₃ → (E₀)
</code></pre>
Disambiguating by resolving shift&#x2F;reduce conflicts means fewer states, whereas disambiguating by rewriting the grammar means more states. Perhaps, as Laurence points out in this article wrt. LALR and SLR: This probably doesn&#x27;t matter at all on modern computers.<p>Any other shift&#x2F;reduce or reduce&#x2F;reduce conflict caused by some other ambiguity than specifically a binary operator, e.g. when you have multiple if-then-else-if-then-else and you want to know where an else belongs: You need to be quite into LR parser generators to understand what&#x27;s happening; took quite a lot of guessing, trial-and-error when I worked with them, and I probably forgot again. I&#x27;d probably document these as non-trivial choices if I were maintaining a Yacc-like parser, and I&#x27;d generally avoid syntax that is ambiguous in this way (although I don&#x27;t think you can always do that).<p>&gt; If you need the best possible performance or error recovery, recursive descent parsing is the best choice. If you know you will need this and you&#x27;re designing a new language, at least create an LL grammar, since from that you can derive a recursive descent parser. [Bear in mind that LL grammars are more annoying to write than LR grammars which is why I suggest avoiding LL unless you have this very specific use case.]<p>I would say: If you get used to parser combinator libraries, you can get a fast, readable LL parser that is also fast to write and does not require extra compilation steps like practically every LR parser generator. I.e. you can skip the part where you convert your grammar file into a native-$YOUR_LANG parser, because parser combinators are embedded DSLs, some of which are just as fast as their hand-written recursive-descent parser. Parser combinator libraries usually have excellent error reporting capability. (The best example I know is Haskell&#x27;s diagnose package. [2]) And some of them have backtracking capability, so that for those few parts where your grammar isn&#x27;t LL, you can go back and try something else.<p>Modern parser combinator libraries like Haskell&#x27;s Parsec &#x2F; Megaparsec has helper functions for generating a parser that effectively translates an operator associativity&#x2F;precedence table into an LL parser; so you get the nicely readable description, and the transformed LL parser that goes with it; see Megaparsec&#x27;s makeExprParser [3]:<p><pre><code>  expr = makeExprParser term table &lt;?&gt; &quot;expression&quot;

  term = parens expr &lt;|&gt; integer &lt;?&gt; &quot;term&quot;

  table = [ [ prefix  &quot;-&quot;  negate
            , prefix  &quot;+&quot;  id ]
          , [ postfix &quot;++&quot; (+1) ]
          , [ binary  &quot;*&quot;  (*)
            , binary  &quot;&#x2F;&quot;  div  ]
          , [ binary  &quot;+&quot;  (+)
            , binary  &quot;-&quot;  (-)  ] ]

  binary  name f = InfixL  (f &lt;$ symbol name)
  prefix  name f = Prefix  (f &lt;$ symbol name)
  postfix name f = Postfix (f &lt;$ symbol name)

</code></pre>
[1]: <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;898489&#x2F;what-programming-languages-are-context-free&#x2F;17686190#17686190" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;898489&#x2F;what-programming-...</a>
[2]: <a href="https:&#x2F;&#x2F;github.com&#x2F;mesabloo&#x2F;diagnose#error-reporting-made-easy">https:&#x2F;&#x2F;github.com&#x2F;mesabloo&#x2F;diagnose#error-reporting-made-ea...</a>
[3]: <a href="https:&#x2F;&#x2F;hackage.haskell.org&#x2F;package&#x2F;parser-combinators-1.3.0&#x2F;docs&#x2F;Control-Monad-Combinators-Expr.html" rel="nofollow">https:&#x2F;&#x2F;hackage.haskell.org&#x2F;package&#x2F;parser-combinators-1.3.0...</a>