Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the disadvantages of using ANTLR compared to Flex/Bison?

I've worked on Flex, Bison few years ago during my undergraduate studies. However, I don't remember much about it now. Recently, I have come to hear about ANTLR.

  • Would you recommend that I learn ANTLR or better to brush up Flex/Bison?
  • Does ANTLR have more/less features than Flex/Bison?
like image 599
user855 Avatar asked Nov 26 '09 22:11

user855


2 Answers

ANTLRv3 is LL(k), and can be configured to be LL(*). The latter in particular is ridiculously easy to write parsers in, as you can essentially use EBNF as-is.

Also, ANTLR generates code that is quite a lot like recursive descent parser you'd write from scratch. It's very readable and easy to debug to see why the parse doesn't work, or works wrong.

The advantage of Flex/Bison (or any other LALR parser) is that it's faster.

like image 136
Pavel Minaev Avatar answered Sep 21 '22 07:09

Pavel Minaev


ANTLR has a run-time library JAR that you must include in your project.

ANTLR's recursive-descent parsers are easier to debug than the "bottom-up" parsers generated by Flex/Bison, but the grammar rules are slightly different.

If you want a Flex/Bison-style (LALR) parser generator for Java, look at JavaCC.

like image 43
Stuart Sierra Avatar answered Sep 23 '22 07:09

Stuart Sierra