Can I use the code generated by flex/bison|lex/yacc in a multithreaded environment ? I'm afraid there are a lot of global variables. How can it be fixed ?
Lex and Yacc were the first popular and efficient lexers and parsers generators, flex and Bison were the first widespread open-source versions compatible with the original software. Each of these software has more than 30 years of history, which is an achievement in itself.
Flex and Bison are tools for building programs that handle structured input. They were originally tools for building compilers, but they have proven to be useful in many other areas.
Bison is the GNU implementation/extension of Yacc, Flex is the successor of Lex. In either case, it's fine (and recommended) to use bison / flex. Additionally, byacc, the Berkeley implementation of yacc, is widely available (I see it in my Debian repository list). flex is called that because it is (was?)
Flex (fast lexical analyzer generator) is a free and open-source software alternative to lex. It is a computer program that generates lexical analyzers (also known as "scanners" or "lexers").
With flex you can use %option reentrant
and with bison %pure-parser
to generate re-entrant code that does not have global data. You may still need some sort of synchronization to prevent multiple threads using the same data blocks at the same time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With