egervari
egervari

Reputation: 22512

Is there a java-only equivalent to scala's parser generators?

Scala has an amazingly simple way to create parsers. Is there a fairly equivalent way to doing the same thing in the Java-only world that doesn't take a week of learning curve?

Upvotes: 3

Views: 322

Answers (3)

James Black
James Black

Reputation: 41858

Manning publications has a book, "DSLs in Action", that covers Java in the beginning.

But, you may want to look at perhaps using Groovy to write your DSL, as there is a great deal of opportunities in a dynamic language, and it would have a shorter learning curve than Scala does.

For an introduction you can start with http://docs.codehaus.org/display/GROOVY/Writing+Domain-Specific+Languages.

The book I mentioned also covers using antlr, and when it makes sense to use and when it doesn't, so if you want to get a better understanding of how to write and maintain a DSL it is an excellent book.

Upvotes: 0

Óscar López
Óscar López

Reputation: 236024

I'm not sure about the lerning curve, but in the Java world, the ANTLR Parser Generator is very well regarded and considered among the best.

Upvotes: 2

3martini
3martini

Reputation: 510

How robust and how configurable does the parser need to be? If the grammar is fairly simple and stable you could just use a recursive descent parser, which uses methods that represent each grammar production rule. I think the output would be roughly what JavaCC would produce, as they are both top-down.

http://en.wikipedia.org/wiki/Recursive_descent_parser

Hope this might be helpful.

Upvotes: 1

Related Questions