Is there a parser combinator as awesome as the Scala one for Java?
Asked Answered
E

3

10

I read the tutorial on parser combinators for Scala, and I was wondering if there's something as "magical" for Java. The best thing I could find was JParsec.

Extravehicular answered 9/3, 2011 at 10:38 Comment(1)
+1 - I didn't know the difference between a parser generator and a combinator until I read this. Thank you - I learned something today.Boscage
C
8

JParsec seems to do the trick, but I cannot comment on its quality. Java has no operator overloading, which is the syntactic part of the "magic" in parser combinators.

You could also use Scala to implement parsers, then call them from Java. But then the benefit over a code generator such as JavaCC isn't as great.

Cesura answered 9/3, 2011 at 10:50 Comment(3)
I didn't have time to read the links, so I was ignorant about the distinction. Thank you for the correction and the education.Boscage
Hmm. You can still get something better than JParsec without using any overloading. I'm thinking of the Newspeak Executable Grammars: bracha.org/executableGrammars.pdf . I just feels clumsy to have to define the tokenization separately, as in the JParsec tutorial. The grammar should be defined more modularly. Though I see that I can't express in hard criteria what it is that I'm looking for :). Just something beautiful!Extravehicular
If you want something beautiful, stay away from Java. </flamebait>Cesura
E
3

I've come to enjoy jParsec, even if it isn't as hot as, say, the Newspeak parser combinator. We've shot an aweseome video tutorial on how to use JParsec.

Extravehicular answered 14/4, 2012 at 12:29 Comment(1)
Just want to mention here that I loved the video and it gave me a very quick idea of deciding on using JParsec. It definetly looks promising. Great work!Saddlery
A
-3

Javacc, grammatica by percederberg.. Any one of these can be used.

Absorbing answered 9/3, 2011 at 10:41 Comment(1)
These are compiler compilers, i.e. code generators. The idea of parser combinators is that you write them in the same language as the rest of the code.Cesura

© 2022 - 2024 — McMap. All rights reserved.