[antlr-interest] How to separate lexer and parser? How to invoke ANTLR?

David Piepgrass qwertie256 at gmail.com
Tue May 29 19:10:42 PDT 2007


> java -classpath antlr-3.0.jar org.antlr.Tool Test.g
>
> but I got the error
>
> >  Exception in thread "main" java.lang.NoClassDefFoundError:
> org/antlr/stringtemplate/StringTemplateErrorListener
> >        at org.antlr.Tool.main(Tool.java:67)
>

Ok, I found the answer at

http://www.antlr.org/wiki/pages/viewpage.action?pageId=728

except that it doesn't say how to add the .jars to the classpath, nor
what Java version is required. IMO, there should be a link to this
page from the download page, and the link to "ANTLR tool+runtime
binary only jar" should have a disclaimer saying that the jar is not
usable by itself.

On windows the CLASSPATH is normally forgotten when you exit a command
prompt so you might find it useful to write a batch file that contains
this:

@echo off
echo Note, you must edit this file to set the path to the JARs!
set antlrpath=C:\Path\to\antlr-3.0\lib
set classpath=%antlrpath%\antlr-2.7.7.jar;%classpath%
set classpath=%antlrpath%\antlr-3.0.jar;%classpath%
set classpath=%antlrpath%\antlr-runtime-3.0.jar;%classpath%
set classpath=%antlrpath%\stringtemplate-3.0.jar;%classpath%
echo Classpath: %classpath%

IMO scripts like this should be included with ANTLR. After you run the
above, commands like

java org.antlr.Tool Test.g

should work.

-- 
- David
http://qism.blogspot.com


More information about the antlr-interest mailing list