parsingcompiler-constructionparser-generator

Do production compilers use parser generators?


I've heard that "real compiler writers" roll their own handmade parser rather than using parser generators. I've also heard that parser generators don't cut it for real-world languages. Supposedly, there are many special cases that are difficult to implement using a parser generator. I have my doubts about this:

  1. Theoretically, a GLR parser generator should be able to handle most programming language designs (except maybe C++...)
  2. I know of at least one production language that uses a parser generator: Ruby [1].
  3. When I took my compilers class in school, we used a parser generator.

So my question: Is it reasonable to write a production compiler using a parser generator, or is using a parser generator considered a poor design decision by the compiler community?

[1] https://github.com/ruby/ruby/blob/trunk/parse.y


Solution

  • For what it's worth, GCC used a parser generator pre-4.0 I believe, then switched to a hand written recursive descent parser because it was easier to maintain and extend.

    Parser generators DO "cut it" for "real" languages, but the amount of work to transform your grammar into something workable grows exponentially.

    Edit: link to the GCC document detailing the change with reasons and benefits vs cost analysis: http://gcc.gnu.org/wiki/New_C_Parser.