3

I have a huge project that is using YACC and I would need to fix a bug in it.

I might ask someone else who wrote that to fix it but I'm interested in how compilers work. Does it make sense to learn YACC nowadays? It was told me that it's old and obsolete. I would love to understand how compilers/llvm and other stuff like those work... what about YACC?

Makane Elhay
  • 209
  • 3
  • 7
  • 6
    If your project includes a DSL (Domain-Specific Language), you **should** learn about parsing, grammars, ASTs and all the funky stuff where the usual introduction is the Dragon Book. Then you can turn to the tools (yacc, bison, haskell-based compiler compilers etc.) – Deer Hunter Jul 22 '13 at 13:52
  • @DeerHunter Haskell-based compilers? – daniel gratzer Jul 22 '13 at 14:08
  • 1
    @jozefg - [**compiler compilers**](https://en.wikipedia.org/wiki/Parser_generator) like Parsec (http://legacy.cs.uu.nl/daan/parsec.html). – Deer Hunter Jul 22 '13 at 14:14
  • Makane Elhay: if you need a quick fix, I'd say definitely go and ask the original coder. You have to climb over a high wall to make some progress, so investing your time into learning lexers, parsers, and compilers now can help you, but not immediately. – Deer Hunter Jul 22 '13 at 14:20
  • 2
    @DeerHunter Ah, I'd just never heard the term compiler-compiler before. Parsec is more commonly called a parse-combinator library – daniel gratzer Jul 22 '13 at 14:40
  • 2
    YACC is based on foundational research on formal languages so, even if the tool can be improved and alternative tools / methods can be proposed, it can hardly become "obsolete" because formal languages will continue to work in the same way in the future. – Giorgio Jul 22 '13 at 16:09
  • There are other ways to do DSLs than YACC and its inheritors. Still, they're hardly _bad_ things to know about… – Donal Fellows Jul 22 '13 at 16:09
  • 1
    @jozefg: YACC stands for "Yet Another Compiler Compiler." – Blrfl Jul 22 '13 at 16:24

2 Answers2

7

YACC helps you with one step of the pipeline: creating a parser for a specific grammar. There are lots of other ways to do that step. There are a ton of parser generators available, or you can manually write your own parser. Depending on your requirements, there are many technical reasons to consider YACC to be obsolete, not the least of which is its limited choice of output languages.

However, it is nowhere near obsolete as a pedagogical tool. You'll need to learn the fundamentals of parsers and grammars no matter what parser you use, and you can learn those just as easily using YACC as with anything else. The knowledge translates very easily. I learned YACC in school, but picked up ANTLR with very little effort.

Also consider that it's very likely your bug isn't even in the parser. Usually most parser bugs get ironed out very early in the project, because they have a tendency to produce spectacular failures. The more subtle errors tend to be in the layers downstream of the parser, which have nothing to do with YACC.

Karl Bielefeldt
  • 146,727
  • 38
  • 279
  • 479
3

I don't think YACC is obsolete. In a sense it is obsoleted by bison, the GNU implementation, but that is backward compatible with the original version.

The big compilers appear to have manually written parsers, I suppose mainly because they need better diagnostics in case of parse errors than what the generic parser generator provides. But many tools with smaller domain specific language use bison (llvm suite build-depends on bison, so it apparently has some, though clang has manually written parser), because it gets the job done quickly and in more maintainable way.

Jan Hudec
  • 18,250
  • 1
  • 39
  • 62