Ask HN: Does anyone still use Lex/Yacc?

4 points by stepvhen ↗ HN
I often see suggestions to use lex/yacc (or flex/bison) when discussing writing compilers or other tools that need parsing, but I don't see them in much use in the wild. Are there any good reasons to not use these tools, and instead roll your own? Or if people really are using these tools, what are some legitimate projects that use them?

I am writing a toy ledger (a smaller, "suckless" version of http://ledger-cli.org ), and I am curious if it is unwise to start working seriously with flex/bison, like if I am going to run into problems as my program becomes larger.

4 comments

[ 2.9 ms ] story [ 21.6 ms ] thread
I've only rolled my own when working with such a basic grammar (or such basic aspects of a grammar) that simple regex felt faster than dealing with actual parsing.

That said, most of that was at a time when I was much less comfortable with lex/yacc, so maybe I'd be more keen on them now.

I do see lex/yacc used in the wild. It's in the RDKit (a cheminformatics package) to parse SMILES and SLN. That's obscure, I know, but that's the field I'm in. I can't find any use in any of the other packages I've downloaded, except a copy of Boost from 2004 which is somehow hanging around.

FWIW, I prefer ANTLR, and for Python, I use PLY.

The usual issue is that it's not hard to write a parser by hand. Though on the other hand, parser generators can tell you about ambiguities that aren't obvious when hand-coding.

Personally, error-handling in yacc has always confused me. When I want detailed error reporting, I often switch to a tokenizer (like Ragel) plus some hand-written parser.

The ANTLR FAQ has the comment:

>> What do you think are the problems people will try to solve with ANTLR4?

> In my experience, almost no one uses parser generators to build commercial compilers. So, people are using ANTLR for their everyday work, building everything from configuration files to little scripting languages.

I say lex/yacc specifically because I am doing this in C, and I've learned that it's important to stick to tools thatare made to work together.

I am unfamiliar with File I/O and text processing in C overall, and so writing a parser by hand seems like more work than using BNF grammars that I am already pretty familiar with.