3 ms·
Lex, yacc, antlr, parsec, ragel, and the others are all hacks. Necessary hacks, when the language is inadequate to the job. But C++ is no longer inadequate. L
by ncmncm 5y ago
Lex, yacc, antlr, parsec, ragel, and the others are all hacks.
Necessary hacks, when the language is inadequate to the job. But C++ is no longer inadequate.
Lex and yacc depend on global variables, so you get one (1) parser per program, unless you further massage their output.
- klodolph 5y agoFlex and Bison depend on global variables by default, but you can eliminate the global variables if you like (e.g. %option reentrant) and change the prefix if you like (%option prefix="mylexer_"). Bison has similar options. I'm sure you could only have one lexer back at some point in the distant past, but that particular issue has been solvable for a long time by now.
- EuAndreh 5y agolex and yacc depend on global variables, flex and bison, which are one the implementations of lex and yacc, don't.
- klodolph 5y agoIs there a reason why you'd be stuck on lex / yacc and unable to use flex / bison? The main reason I can think of is that you are in a legacy code base which already uses lex / yacc.
- EuAndreh 5y agolex and yacc are part of POSIX, while flex and bison aren't.
- klodolph 5y agoSure, and C++ isn't part of POSIX. So if you must stick to strictly POSIX utilities, you cannot use C++.
- ncmncm 5y agoC++ and Posix are both ISO Standards.
- klodolph 5y agoAre you constrained to only use software which is standardized by ISO? I'm just trying to figure out what you're saying here.
- ncmncm 5y agoI am not so constrained, but some are. But in general, for anybody deploying software widely, any time you can avoid a necessary build dependency on another tool, you come out ahead.
- klodolph 5y agoCould you tell me more about who is constrained this way? I'm curious about what kind of organization has these kinds of constraints. I have some friends who work in aerospace or at defense contractors and these constraints sound a little extreme even by their standards.
- ncmncm 5y agoThey would know better than I do.
- kazinator 5y agoYou can avoid a build dependency on Bison or Flex by shipping their output. Their output is intended to be portable and standard-conforming. https://www.gnu.org/software/bison/manual/bison.html#Versioning https://www.gnu.org/software/bison/manual/bison.html#Version... Even if you have standard-conforming lex and yacc source code that, theoretically, work with any yacc or lex implementation, it's still wise to pick a good implementation and generate code with it, and ship that code. You don't want some random tool from the user's installation writing C code into your project. And POSIX does not guarantee the presence of a yacc command in an installation; it just describes what it does if it is present. There are Unix-like systems with no dev tools on them; requiring lex plus yacc plus a compiler is a bigger dependency than just requiring a compiler.
- pcwalton 5y agoIs C++ adequate, when compile time and maintainability are taken into account?
- ncmncm 5y agoCompile time seems like an odd thing for you to mention here. I don't know if your favorite language is similarly adequate, but I know it compiles way more slowly. But generally the time to analyze a constexpr initializer expression, even of even a pretty substantial grammar, will generally be pretty negligible, particularly given that it need not appear in a header file.
- pjmlp 5y agoMicrosoft would say so, specially with all the module's talks. I guess all those logos on ISO C++ meetings would state similar assertions. Some of them might be playing with Rust, but when it comes down to shipping SDKs, it is all about C++.
- kazinator 5y agoThis is false; GNU Bison introduced re-entrant parsing probably about a decade and half ago at least, in combination with Flex, and Berkeley Yacc implemented a compatible implementation. I use this in TXR Lisp. There are situations in which a Lisp macro may be expanded in the context of the parser. The macro can use the parser (e.g. call (read "(1 2 3)"). This works.