ANTLR writes files to the current directory by default. But, the output filename is sensitive to the output directory and the directory where the grammar file was found. If you reference a grammar with a (relative or absolute) path,
ANTLR will pull the grammar from that directory and write the output to that directory:
If you specify an output directory with -o then ANTLR will put the output files in that directory or underneath if you have a relative path on the grammar file:
The output directory -o value takes precedence over the grammar's path when the output directory is absolute.
Use -fo option to force output to go explicitly into a directory, ignoring any path on the input grammar name.
Note: If the outputDir set by -o is not present it will be created.
9 Comments
Hide/Show CommentsDec 03, 2008
Lonnie VanZandt
How does Anltr / AntlrWorks resolve "import" statements? The It Just Works approach fails. Somewhere, I need to specify which folders to search when attempting resolve imports...
Dec 03, 2008
Terence Parr
It should look in the -lib dir.
Dec 03, 2008
Lonnie VanZandt
Showing real ignorance here: and how do I get that lib option passed to Antlr from the "java -jar antlrworks-1.2.2.jar" command line?
Dec 03, 2008
Terence Parr
Oh, in AW, use its preferences. Should be in there somewhere. Yep, put -lib foo in antlr options of general pane in preferences.
Dec 03, 2008
Lonnie VanZandt
Passed by both these guideposts while googling for the answer--thanks for the human interaction!
Dec 03, 2008
Lonnie VanZandt
Yep, all pilot error. I had a stray character in one of the grammar files, Deleting that and observing the import rules made all the difference.
Mar 26, 2009
ajeesh
I am new to java and when i run from command prompt i get the following :
its the same when i run from the Visual studio solution...
D:\antlr>java -jar antlr-3.1.3.jar org.antlr.Tool C.g
error(10): internal error: : java.io.FileNotFoundException: org.antlr.Tool (The system cannot find the file specified)
java.io.FileInputStream.open(Native Method)
java.io.FileInputStream.<init>(Unknown Source)
java.io.FileInputStream.<init>(Unknown Source)
java.io.FileReader.<init>(Unknown Source)
org.antlr.tool.GrammarSpelunker.parse(GrammarSpelunker.java:79)
org.antlr.Tool.sortGrammarFiles(Tool.java:525)
org.antlr.Tool.process(Tool.java:383)
org.antlr.Tool.main(Tool.java:91)
error(7): cannot find or open file: org.antlr.Tool
Please help.......
Mar 26, 2009
Terence Parr
Sorry about that; depends on if jar file has a manifest. Try:
java -jar antlr-3.1.3.jar C.g
Aug 02, 2011
David Biesack
I find a difference in how ANTLR 3.2 handles -o output generation between Linux and Windows.
Consider a grammar in src/com/example/parser/A.g that contains package declarations:
@parser::header { package com.example.parser; } @lexer::header { package com.example.parser; }On Windows,
will create
in the out directory whereas on Linux,
(using the same antlr 3.2 jar in the classpath) yields
That is, on Linux, ANTLR is creating files in package directories, but on Windows it is not.
I'm using Java 1.6.0_24 in both.
I have found I have to use
(that is, specify the package directory) in my Ant build.xml or Maven pom.xml - this works in both places. This means the parser and grammar must be in the same package.