Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ANTLR vs parboiled

What is the difference between ANTLR and parboiled for parsing in Java?

  • Which is easier to use for a beginner in parsing?
  • Which is more scalable? (from simple to complex grammar)
  • Which has better support for AST construction?
  • Which produces better error or warning messages for syntax errors?
  • Which has less problems to contend with? (e.g. left recursion, shift/reduce conflicts, reduce/reduce conflicts)
  • Comparison with other open source tools also appreciated
like image 545
ruben2020 Avatar asked Oct 12 '25 11:10

ruben2020


1 Answers

Parboiled looks like a really cool tool. It might be easier for beginners as it is just pure programming using a "parser combinator" idiom. I think that this would become very verbose and harder to read, though the Java grammar doesn't look too bad that I see. I cannot comment on its AST construction but ANTLR 4 generates parse trees not a ASTs. It claims to have good error messages/recovery but that is suspect because it is based upon parser expression grammars, which can only detect errors once the entire input is been seen (worst case). It also cannot identify ambiguities in your grammar (not conflicts, ambiguities). Neither tool announces parsing conflicts. ANTLR 4 handles direct left recursion for things like arithmetic expressions but in general neither tool can handle left recursion. ANTLR requires that you use a library for its parser interpreter like parboiled but you must learn to use the tool if you want to have it generate parsers. Currently, ANTLR 4 can generate parsers in Java, C#, JavaScript, Python 2, Python 3.

like image 182
Terence Parr Avatar answered Oct 15 '25 11:10

Terence Parr