1
votes

I've been thinking about learning bison/yacc after reading some old Steve Yegge articles. Steve of course loves compilers and so recommends that people should learn them. He's given much other good advice on what skills to develop so I figured I'd take a look.

What I'm wondering is - what are the practical use cases for lex/flex/yacc/bison outside of constructing your own programming language? I'm sure there's an obvious use cases that I'm missing, but nothing comes to mind.

What kinds of problems can you more easily/stably solve with bison/yacc rather than parsing things with regexes?

1
Is it worth clarifying what you mean by language? For instance, if your question, does it mean "general-purpose programming language"? For surely the tools you mentioned are very useful even if you're "just" dealing with a small configuration, user-interaction, or specification language. - Nick Russo
It's interesting to think of the coding of parsers for a language as constituting the "constructing" of the language. It's also useful to note that fully-constructed languages may also need parsers/compilers/validators built for them. - Nick Russo
Combining Flex and Bison, you can create a calculator--very easily. Far more easily than if you tried to code an in-fix calculator via an all-purpose programming language (like Java or C). In fact I once showed a friend that you can code a working in-fix calculator in about 20 minutes using Flex and Bison (obviously you have to know the syntax of each to do it this quickly). If you know the structure of the input (and the input is highly structured), you can do things very quickly with Flex/Bison. - Jared
Nick, I updated it to say "programming language" - but your comment seems to indicate that there are uses beyond this. :) - bitops
Yup, just about every interaction between computers and people or computers and computers (and even people and people), uses a language, and not all are programming languages, but all need to be parsed. For instance, html isn't a programming language, nor is xml, nor the phrases you can put into a google search to constrain to certain sites, avoid certain words, etc. - Nick Russo

1 Answers

1
votes

What kinds of problems can you more easily/stably solve with bison/yacc rather than parsing things with regexes?

Big problems.

Keeping track of regexes for all the different, potentially nested lexical elements in a language can be daunting, and automation tools can make it more feasible, maintainable, shareable, etc.

what are the practical use cases for lex/flex/yacc/bison outside of constructing your own language?

Maybe the language already exists, but you want to implement a parser/compiler/validator for it. Possibly in new language or on a different platform than existing tools.