Why you should not use (f)lex, yacc and bison
tomassetti.me
tomassetti.me
Now, this is one of the most atrocious handwavy kind of FUD that I've had a displeasure to see. If the parsers generated by bison are GPL-free, where is the problem? Can you even name the problem? Or you just see the word "GPL" and it's scaring you somehow?
The author might just as well put up a comparison chart:
bison: PROBLEMATIC AND GPL
ANTLR: does not have a problem*
----
* With yearly consulting contract from our company
The message would be exactly the same.https://stanislaw.github.io/2016/03/29/reentrant-parser-usin...
which in turn links this:
https://github.com/blynn/symple/tree/75aaea79141a18a234c94dc...
The magic flags are:
%option reentrant
and %lex-param { yyscan_t scanner }
%parse-param { yyscan_t scanner }
%parse-param { val_callback_t callback }
... so ... it seems a reentrant flex/bison parser is easily possible?Have the ANTLR guys dropped their Java credo or they're still thinking they are going to convince any C developer with a .jar?
re2c has good unicode support -- takes a while to compile if attempting TR31 "Unicode Identifier And Pattern Syntax" though.
Haven't used lemon on anything too complicated, I basically just play with grammars for fun, but it works really well for my MiniScheme fork I like to poke at every once in a while.
My new shiny is Coco/R which is a dream to use (once you get up the learning curve) but hasn't really been maintained for ages.
I think that lemon is comming from the same author as sqlite. I used it like 15 years ago ;) but i still remember lemon as high quality piece of software (Much better compared with flex, yacc, bison...)
Globals are just the 80's setup, and flex/bison are supposed to be POSIX lex/yacc compatible, so I'm gonna count this as "shitty defaults due to compatibility with stone tablets".
Flex has had some work done to push it towards being able to generate Go and Rust code too, though this work isn’t finished. In principle it is now possible to generate any Algol–style language.
But I was quickly discouraged by the complexity of using these tools, they are more like a new language that you have to learn.
Today I prefer writing parsers by hand, in C, like Fabrice Bellard, it is not super easy but manageable and I never encountered major issues.
I think that Lex/Yacc and similar tools are a good illustration of the power and shortcomings of metaprogramming.
There are some obvious use cases, but it is not always the best choice.
Imagine, for example, that the input being parsed is not under the authors control and it suddenly changes. The parser must be changed.
As a practical matter the grammar can act like a contract between the two systems. You don't have control of the input, but the input must follow the same grammar.
I don't work on parsers and grammar day to day, so I might not be the best person to ask about this. I am interested in the subject though. I just don't get to work on this in my current day job.
- It's just normal code; you don't have to go learn a whole 'nother thing
- Easy and fun to write (ymmv)
- Does not add extra dependencies to your build system (the time I've wasted getting the right version of yacc installed just to handle software that parses some trivial grammar...)
- You can easily deliver really good error messages to your users (they love this!)
Disadvantages:
If you're not careful, you can accidentally end up w/ some sort of weird frankenstein grammar
Can't remember why but my Compilers teacher (Adrian Johnstone, Royal Holloway) doesn't like PEGs - think due to parse forest not being generated?
While I definitely agree that ANTLR is a great tool, I feel that many of the critics about Bison are somewhat unfair.
First of all, many people like to tie Flex and Bison together, and that's wrong. You don't have to use Flex to feed tokens to your Bison parser. And my personal opinion is that Flex is badly maintained. Releases are infrequent, and issues keep on stacking. So please, stop putting Flex and Bison in the same bucket: they _can_ be used together, but they are not maintained by the same people.
Second, many people seem to not know that Bison is way more than YACC. To name just a few features of Bison
- it goes way beyond LALR(1): IELR(1), canonical LR(1), and GLR are supported
- it generates parsers in C, C++, Java and D
- it supports push and pull parsing
- it supports customized error message generation
- it can generate explicit counterexamples about conflicts (see https://en.wikipedia.org/wiki/GNU_Bison#Counterexample_gener... to see examples)
- it perfectly supports reentrant parsers and it comes with several examples of such parsers (see https://github.com/akimd/bison/tree/master/examples/c)
- and way more.
The original article says:
> Flex and Bison are very much stable software. They are maintained, but development of new features is limited, if not absent.
Before emitting such strong statements about Bison, please at least look at its current state and to the NEWS file (https://git.savannah.gnu.org/cgit/bison.git/tree/NEWS). There were two major releases in 2018, three in 2019 and two in 2020. That's 29 releases in four years if you also count the bug fix releases. Therefore "development of new features is limited, if not absent" is pretty much false. Did the author actually studied Bison before writing all this?
https://www.gnu.org/software/bison/manual/bison.html#Pure-De...
Lots of people have opinions on the language (or Microsoft themselves) and it may not be up there with C++, Java, and Javascript in terms of adoption.
However it's 20+ years old, massively used in enterprise, powers sites like StackOverflow, and is most definitely (by language rankings and surveys) a top tier ecosystem - often in the top 5.
You're right about embedded systems. Most ecosystems that use a GC would struggle there, including DotNet.