I have written an Interpreter / Compiler simply as a programming algorithm using features such as recursive functions and concepts from finite-State machines. To me, these things are ideally suited to building a compiler (Although it does end up getting pretty complex).

Doing a little bit of research on the subject, I came across Flex/Bison. I'm wondering how these tools make it better to develop a compiler. Is is simpler to use that or is the end product better in some way?

  • 4
    @gnat Where do you see a query for software recommendation? OP asks what advantages a specific tool has, compared to not using it. OP doesn't ask "I want to write a compiler, which parser generator (if any) should I use?" – user7043 Nov 10 '14 at 8:28
  • 3
    @gnat How about you give some reasons for why it seems like that to you? I appreciate that you so often dig up the formal reason why a obviously bad question really is bad, but here you seem overzealous. See also: The fact that the existing answer doesn't even mention any specifics of any particular product. – user7043 Nov 10 '14 at 9:05
  • 1
    @gnat I... think I see your thought process but it doesn't make sense to me. "Try this instead" belongs into an answer saying "don't do that", but for this question the "don't do that answer" would be "Use parser generators because [...]", not "Use parser generator X". Recommendation questions are verboten for a reason (chiefly: lots of very poor answers and being primarily opinion-based); I don't see the danger of either for this question. I may reconsider if further answers go badly, or if more people vote to close. For the time being, I ask you to be less literal-minded. – user7043 Nov 10 '14 at 9:22
  • 1
    @delnan I am generally open to reconsider my position, but discussion like this isn't really appropriate in question comment, that's why I suggested Software Engineering Meta – gnat Nov 10 '14 at 9:32
  • 2
    You might want to consider ease of development. Personally, I find straight C (or C++ or your language of choice) code easier to debug than Lex/Yacc, which is why I have hand-crafted so many parses & lexxers. UNTIL ... I discovered ANTLR, which only gets better when you find that the ANTLRworks front-end let's you visually step through your expressions as they lex & parse... liek this (Argh! how to insert an image? Sorry, you will have to click the link) antlr3.org/works/screenshots/debugger.png – Mawg says reinstate Monica Nov 10 '14 at 17:20

Compiler generators (such as Bison) use pretty much the same concepts from finite state machines as you have used in your hand-crafted parser.

The main differences between compiler generators and hand-crafted parsers are

  • Most hand-crafted parsers use a top-down parsing strategy, while compiler generators often create a bottom-up parser. This has a slight impact on the languages that can be supported, although most languages of real interest can be handled by both (possibly after slight tweaks to the grammar rules). This has mostly to do with recursion in the grammar.
  • With a compiler generator, you specify the language's grammar directly, in a form that is usually close to the BNF form that is commonly used for describing language grammars. With a hand-crafted parser, it can sometimes be hard to recognize the language's grammar in the code, which can make it more difficult to diagnose errors resulting from incorrect interpretation of the language rules.
  • With a compiler generator, you may have to learn a new language (the language accepted by the generator). Hand-crafted parsers can be written in most languages.
  • I am not certain, but I THINK ANTLR builds top-down parsers. – John R. Strohm Nov 10 '14 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.