8

ANTLR generates java source from the grammar file. Generated source has dependency to ANTLR classes.

Can I generate 'clean' java sources using ANTLR, that do not have any antlr - dependecy?

If not, can someone recommend some java parser that excels with performances and can produce clean java code?

svick
  • 236,525
  • 50
  • 385
  • 514
igr
  • 10,199
  • 13
  • 65
  • 111
  • I think this is an excellent question. With the large availability of tools, frameworks and libraries, limited vertical scaling, and the environmental impact of horizontal scaling and energy consumption overall, I believe that producing lean bloat-free code over functionality should be a foremost concern of modern quality software engineering. – Coder Guy Jul 17 '15 at 19:30
  • Hey @JonathanNeufeld I agree with you - may I quote this? Thats why i coded [jodd](http://jodd.org) - to minimize the code base... – igr Jul 17 '15 at 20:18

2 Answers2

2

It really isn't practical to remove runtime dependencies on ANTLR. You need to distribute the ANTLR runtime library with your recognizers.

If I remember correctly, JavaCC creates a copy of the necessary runtime classes (the JavaCC "boilerplate") as part of the "generated" code, so that you don't need to include an additional JAR.

What is the root of your concern about the ANTLR dependencies?

erickson
  • 265,237
  • 58
  • 395
  • 493
  • Generated code should be part of the framework/library, therefore I want to keep dependencies minimal, to avoid possible collisions with different versions of existing client antlr jars. But, more important, I want so ;) – igr Nov 21 '11 at 14:41
1

You can use the Apache Maven Shade Plugin to relocate the ANTLR to a new package that will not conflict with other ANTLR runtime installations in the same process. StringTemplate 4 uses exactly this method to relocate the ANTLR runtime to package st4hidden.org.antlr as part of the ST4-4.0.8-complete.jar distributable jar.

Sam Harwell
  • 97,721
  • 20
  • 209
  • 280