java left logo
java middle logo
java right logo
 

Home arrow Other API Tips arrow Ant arrow How to use JJTree task
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4091
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to use JJTree task E-mail
User Rating: / 2
PoorBest 

JJTree

Description

Invokes the JJTree preprocessor for the JavaCC compiler compiler. It inserts parse tree building actions at various places in the JavaCC source that it generates. The output of JJTree is run through JavaCC to create the parser.

To use the jjtree task, set the target attribute to the name of the JJTree grammar file to process. You also need to specify the directory containing the JavaCC installation using the javacchome attribute, so that ant can find the JavaCC classes. Optionally, you can also set the outputdirectory to write the generated JavaCC grammar and node files to a specific directory. Otherwise jjtree writes the generated JavaCC grammar and node files to the directory containing the JJTree grammar file. As an extra option, you can also set the outputfile to write the generated JavaCC grammar file to a specific (directory and) file. Otherwise jjtree writes the generated JavaCC grammar file as the JJTree grammar file with a suffix .jj.

This task only invokes JJTree if the grammar file is newer than the generated JavaCC file.

Parameters

Attribute Description Required
target The jjtree grammar file to process. Yes
javacchome The directory containing the JavaCC distribution. Yes
outputdirectory The directory to write the generated JavaCC grammar and node files to. If not set, the files are written to the directory containing the grammar file.  No
outputfile The file to write the generated JavaCC grammar file to. If not set, the file is written with the same name as the JJTree grammar file but with a the suffix .jj. This is a filename relative to outputdirectory if specified, the project's basedir. No
buildnodefiles Sets the BUILD_NODE_FILES grammar option. This is a boolean option. No
multi Sets the MULTI grammar option. This is a boolean option. No
nodedefaultvoid Sets the NODE_DEFAULT_VOID grammar option. This is a boolean option. No
nodefactory Sets the NODE_FACTORY grammar option. This is boolean option. No
nodescopehook Sets the NODE_SCOPE_HOOK grammar option. This is a boolean option. No
nodeusesparser Sets the NODE_USES_PARSER grammar option. This is a boolean option. No
static Sets the STATIC grammar option. This is a boolean option. No
visitor Sets the VISITOR grammar option. This is a boolean option. No
nodepackage Sets the NODE_PACKAGE grammar option. This is a string option. No
visitorexception Sets the VISITOR_EXCEPTION grammar option. This is a string option. No
nodeprefix Sets the NODE_PREFIX grammar option. This is a string option. No

Example

<jjtree 
    target="src/Parser.jjt" 
    outputdirectory="build/src"
    javacchome="c:/program files/JavaCC" 

    nodeusesparser="true"
/>
This invokes JJTree on grammar file src/Parser.jjt, writing the generated grammar file, Parser.jj, file to build/src. The grammar option NODE_USES_PARSER is set to true when invoking JJTree.

Comparison output locations between command line JJTree and different Ant taskdef versions

Command Line JJTree options
     and Generated Files (working directory: /tmp)
Ant 1.5.3 versus command line Ant 1.6 versus command line

jjtree  grammar.jjt
    /tmp/grammar.jj
    /tmp/<generated>.java
Same Same

jjtree  relative/grammar.jjt
    /tmp/grammar.jj
    /tmp/<generated>.java
/tmp/rel../grammar.jj
/tmp/rel../<generated>.java
Same

jjtree  /tmp/absolute/grammar.jjt

    /tmp/grammar.jj
    /tmp/<generated>.java
/tmp/abs../grammar.jj
/tmp/abs../<generated>.java
Same

jjtree  
-OUTPUT_DIRECTORY:relative  
grammar.jjt
    /tmp/relative/grammar.jj
    /tmp/relative/<generated>.java
Same Same

jjtree  
-OUTPUT_DIRECTORY:relative  
relative/grammar.jjt
    /tmp/relative/grammar.jj
    /tmp/relative/<generated>.java
Same Same

jjtree  
-OUTPUT_DIRECTORY:relative  
/tmp/absolute/grammar.jjt
    /tmp/relative/grammar.jj
    /tmp/relative/<generated>.java
Same Same

jjtree  
-OUTPUT_DIRECTORY:/tmp/absolute/  
grammar.jjt
    /tmp/absolute/grammar.jj
    /tmp/absolute/<generated>.java
Same Same

jjtree  
-OUTPUT_DIRECTORY:/tmp/absolute/  
relative/grammar.jjt
    /tmp/absolute/grammar.jj
    /tmp/absolute/<generated>.java
Same Same

jjtree  
-OUTPUT_DIRECTORY:/tmp/absolute/  
    /tmp/absolute/grammar.jjt
    /tmp/absolute/grammar.jj
    /tmp/absolute/<generated>.java
Same Same

jjtree  
-OUTPUT_FILE:output.jj  
grammar.jjt
    /tmp/output.jj
    /tmp/<generated>.java
Not Supported Same

jjtree  
-OUTPUT_FILE:output.jj  
relative/grammar.jjt
    /tmp/output.jj
    /tmp/<generated>.java
Not Supported Same

jjtree  
-OUTPUT_FILE:output.jj  
/tmp/absolute/grammar.jjt
    /tmp/output.jj
    /tmp/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:output.jj  
-OUTPUT_DIRECTORY:relative  
grammar.jjt
    /tmp/relative/output.jj
    /tmp/relative/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:output.jj  
-OUTPUT_DIRECTORY:relative  
relative/grammar.jjt
    /tmp/relative/output.jj
    /tmp/relative/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:output.jj  
-OUTPUT_DIRECTORY:relative  
/tmp/absolute/grammar.jjt
    /tmp/relative/output.jj
    /tmp/relative/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:output.jj  
-OUTPUT_DIRECTORY:/tmp/absolute/  
grammar.jjt
    /tmp/absolute/output.jj
    /tmp/absolute/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:output.jj  
-OUTPUT_DIRECTORY:/tmp/absolute/  
relative/grammar.jjt
    /tmp/absolute/output.jj
    /tmp/absolute/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:output.jj  
-OUTPUT_DIRECTORY:/tmp/absolute/  
/tmp/absolute/grammar.jjt
    /tmp/absolute/output.jj
    /tmp/absolute/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:subdir/output.jj  
grammar.jjt
    /tmp/subdir/output.jj
    /tmp/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:subdir/output.jj  
relative/grammar.jjt
    /tmp/subdir/output.jj
    /tmp/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:subdir/output.jj  
/tmp/absolute/grammar.jjt
    /tmp/subdir/output.jj
    /tmp/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:subdir/output.jj  
-OUTPUT_DIRECTORY:relative  
grammar.jjt
    /tmp/relative/subdir/output.jj
    /tmp/relative/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:subdir/output.jj  
-OUTPUT_DIRECTORY:relative  
relative/grammar.jjt
    /tmp/relative/subdir/output.jj
    /tmp/relative/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:subdir/output.jj  
-OUTPUT_DIRECTORY:relative  
/tmp/absolute/grammar.jjt
    /tmp/relative/subdir/output.jj
    /tmp/relative/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:subdir/output.jj  
-OUTPUT_DIRECTORY:/tmp/absolute/  
grammar.jjt
    /tmp/absolute/subdir/output.jj
    /tmp/absolute/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:subdir/output.jj  
-OUTPUT_DIRECTORY:/tmp/absolute/  
relative/grammar.jjt
    /tmp/absolute/subdir/output.jj
    /tmp/absolute/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:subdir/output.jj  
-OUTPUT_DIRECTORY:/tmp/absolute/  
/tmp/absolute/grammar.jjt
    /tmp/absolute/subdir/output.jj
    /tmp/absolute/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:/tmp/subdir/output.jj  
grammar.jjt
    /tmp/subdir/output.jj
    /tmp/<generated>.java
Not Supported Same
jjtree 
-OUTPUT_FILE:/tmp/subdir/output.jj  
relative/grammar.jjt
    /tmp/subdir/output.jj
    /tmp/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:/tmp/subdir/output.jj  
/tmp/absolute/grammar.jjt
    /tmp/subdir/output.jj
    /tmp/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:D:/tmp/subdir/output.jj  
grammar.jjt
    /tmp/subdir/output.jj
    /tmp/<generated>.java
Not Supported Not Supported *)
jjtree  
-OUTPUT_FILE:D:/tmp/subdir/output.jj  
relative/grammar.jjt
    /tmp/subdir/output.jj
    /tmp/<generated>.java
Not Supported Not Supported *)
jjtree  
-OUTPUT_FILE:D:/tmp/subdir/output.jj  
/tmp/absolute/grammar.jjt
    /tmp/subdir/output.jj
    /tmp/<generated>.java
Not Supported Not Supported *)
jjtree  
-OUTPUT_FILE:/tmp/subdir/output.jj  
-OUTPUT_DIRECTORY:relative  
grammar.jjt
    /tmp/relative/tmp/subdir/output.jj
    /tmp/relative/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:/tmp/subdir/output.jj  
-OUTPUT_DIRECTORY:relative  
relative/grammar.jjt
    /tmp/relative/tmp/subdir/output.jj
    /tmp/relative/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:/tmp/subdir/output.jj  
-OUTPUT_DIRECTORY:relative  
/tmp/absolute/grammar.jjt
    /tmp/relative/tmp/subdir/output.jj
    /tmp/relative/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:/tmp/subdir/output.jj  
-OUTPUT_DIRECTORY:/tmp/absolute/  
grammar.jjt
    /tmp/absolute/tmp/subdir/output.jj
    /tmp/absolute/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:/tmp/subdir/output.jj  
-OUTPUT_DIRECTORY:/tmp/absolute/  
relative/grammar.jjt
    /tmp/absolute/tmp/subdir/output.jj
    /tmp/absolute/<generated>.java
Not Supported Same
jjtree  
-OUTPUT_FILE:/tmp/subdir/output.jj  
-OUTPUT_DIRECTORY:/tmp/absolute/  
/tmp/absolute/grammar.jjt
    /tmp/absolute/tmp/subdir/output.jj
    /tmp/absolute/<generated>.java
Not Supported Same

*) Footnote: When running JJTree with the Ant taskdef jjtree the option -OUTPUT_DIRECTORY must always be set, because the project's basedir and the ant working directory might differ. So even if you don't specify the jjtree taskdef outputdirectory JJTree will be called with the -OUTPUT_DIRECTORY set to the project's basedirectory. But when the -OUTPUT_DIRECTORY is set, the -OUTPUT_FILE setting is handled as if relative to this -OUTPUT_DIRECTORY. Thus when the -OUTPUT_FILE is absolute or contains a drive letter we have a problem. Therefore absolute outputfiles (when the outputdirectory isn't specified) are made relative to the default directory. And for this reason outputfiles that contain a drive letter can't be supported.

By the way: specifying a drive letter in the -OUTPUT_FILE when the -OUTPUT_DIRECTORY is set, also results in strange behavior when running JJTree from the command line.


Source: Apache Ant


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.