/* Copyright (c) 2006, Sun Microsystems, Inc.
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 
 *     * Redistributions of source code must retain the above copyright notice,
 *       this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the Sun Microsystems, Inc. nor the names of its
 *       contributors may be used to endorse or promote products derived from
 *       this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

JJTreeExamples

This directory contains some simple JJTree input files intended to
illustrate some of the basic ideas.  All of them are based on a 
grammar to recognize arithmetic expressions built out of identifiers
and constants.

eg1.jjt

This example is just the JavaCC grammar, with a little extra code in
the parser's main method to call the dump method on the generated
tree.  It illustrates how the default behavior of JJTree will produce
a tree of non-terminals.

eg2.jjt

This example is the same grammar as eg1.jjt with modifications to
customize the generated tree.  It illustrates how unnecessary
intermediate nodes can be suppressed and how actions in the grammar
can attach extra information to the nodes.

eg3.jjt

This example is a modification of eg2.jjt with the NODE_DEFAULT_VOID
option set.  This instructs JJTree to treat all undecorated
non-terminals as if they were decorated as #void. The default JJTree
behavior is to treat such non-terminals as if they were decorated
with the name of the non-terminal.

eg4.jjt

This is a modification of eg3.jjt with the VISITOR option set.  This
instructs JJTree to insert a jjtAccept() method into all nodes it
generates, and to produce a visitor class.  The visitor is used to
dump the tree.

Here are some instructions on how to run the examples using the Ant build scripts, 
and the output you can expect to see.

eg1.jjt
-------

The only bit of JJTree-specific code is an action in the start
production that dumps the constructed parse tree when the parse is
complete.  It uses JJTree simple mode.

The input file is eg1.jjt.

$ ant -lib ../../../lib eg1
Buildfile: Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\build.xml

eg1:
   [delete] Deleting directory Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg1
    [mkdir] Created dir: Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg1
     [copy] Copying 1 file to Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg1
     [copy] Copying 1 file to Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg1
   [jjtree] Java Compiler Compiler Version 6.2_1 (Tree Builder)
   [jjtree] (type "jjtree" with no arguments for help)
   [jjtree] Reading from file Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg1.jjt . . .
   [jjtree] opt:c++
   [jjtree] File "Node.h" does not exist.  Will create one.
   [jjtree] File "SimpleNode.h" does not exist.  Will create one.
   [jjtree] File "SimpleNode.cc" does not exist.  Will create one.
   [jjtree] File "ParserTree.h" does not exist.  Will create one.
   [jjtree] File "ParserTreeConstants.h" does not exist.  Will create one.
   [jjtree] File "JJTParserState.h" does not exist.  Will create one.
   [jjtree] File "JJTParserState.cc" does not exist.  Will create one.
   [jjtree] Annotated grammar generated successfully in Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg1\eg1.jj
   [javacc] Java Compiler Compiler Version 6.2_1 (Parser Generator)
   [javacc] (type "javacc" with no arguments for help)
   [javacc] Reading from file Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg1\eg1.jj . . .
   [javacc] File "JavaCC.h" does not exist.  Will create one.
   [javacc] File "CharStream.h" does not exist.  Will create one.
   [javacc] File "CharStream.cc" does not exist.  Will create one.
   [javacc] File "Token.h" does not exist.  Will create one.
   [javacc] File "Token.cc" does not exist.  Will create one.
   [javacc] File "TokenManager.h" does not exist.  Will create one.
   [javacc] File "TokenMgrError.h" does not exist.  Will create one.
   [javacc] File "TokenMgrError.cc" does not exist.  Will create one.
   [javacc] File "ParseException.h" does not exist.  Will create one.
   [javacc] File "ParseException.cc" does not exist.  Will create one.
   [javacc] File "Token.h" is being rebuilt.
   [javacc] File "Token.cc" is being rebuilt.
   [javacc] File "ErrorHandler.h" does not exist.  Will create one.
   [javacc] Parser generated successfully.
[cpptasks:cc] 9 total files to be compiled.
[cpptasks:cc] In file included from Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg1\SimpleNode.cc:4:0:
[cpptasks:cc] Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg1\SimpleNode.h: In constructor ‘EG1::SimpleNode::SimpleNode(EG1::Parser*, int)’:
[cpptasks:cc] Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg1\SimpleNode.h:20:14: attention : ‘EG1::SimpleNode::parser’ will be initialized after [-Wreorder]
[cpptasks:cc]    Parser *   parser;
[cpptasks:cc]               ^
[cpptasks:cc] Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg1\SimpleNode.h:19:22: attention :   ‘int EG1::SimpleNode::id’ [-Wreorder]
[cpptasks:cc]    int                id;
[cpptasks:cc]                       ^
[cpptasks:cc] Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg1\SimpleNode.cc:14:1: attention :   lorsqu'initialisé ici [-Wreorder]
[cpptasks:cc]  SimpleNode::SimpleNode(Parser *parser, int id) :
[cpptasks:cc]  ^
[cpptasks:cc] Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg1\ParserTokenManager.cc: In member function ‘EG1::Token* EG1::ParserTokenManager::jjFillToken()’:
[cpptasks:cc] Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg1\ParserTokenManager.cc:361:28: attention : ‘endColumn’ may be used uninitialized in this function [-Wmaybe-uninitialized]
[cpptasks:cc]     t->endColumn = endColumn;
[cpptasks:cc]                             ^
[cpptasks:cc] Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg1\ParserTokenManager.cc:360:32: attention : ‘beginColumn’ may be used uninitialized in this function [-Wmaybe-uninitialized]
[cpptasks:cc]     t->beginColumn = beginColumn;
[cpptasks:cc]                                 ^
[cpptasks:cc] Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg1\ParserTokenManager.cc:359:24: attention : ‘endLine’ may be used uninitialized in this function [-Wmaybe-uninitialized]
[cpptasks:cc]     t->endLine = endLine;
[cpptasks:cc]                         ^
[cpptasks:cc] Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg1\ParserTokenManager.cc:358:28: attention : ‘beginLine’ may be used uninitialized in this function [-Wmaybe-uninitialized]
[cpptasks:cc]     t->beginLine = beginLine;
[cpptasks:cc]                             ^
[cpptasks:cc] Starting link
     [exec] Reading from standard input...
     [exec] Start
     [exec]  Expression
     [exec]   AdditiveExpression
     [exec]    MultiplicativeExpression
     [exec]     UnaryExpression
     [exec]      Expression
     [exec]       AdditiveExpression
     [exec]        MultiplicativeExpression
     [exec]         UnaryExpression
     [exec]          Integer
     [exec]        MultiplicativeExpression
     [exec]         UnaryExpression
     [exec]          Integer
     [exec]     UnaryExpression
     [exec]      Expression
     [exec]       AdditiveExpression
     [exec]        MultiplicativeExpression
     [exec]         UnaryExpression
     [exec]          Identifier
     [exec]        MultiplicativeExpression
     [exec]         UnaryExpression
     [exec]          Identifier
     [exec] thank you.

BUILD SUCCESSFUL
Total time: 4 seconds

eg2.jjt
-------

This is a modification of the first example to illustrate how the
parse tree can be customized:

$ ant -lib ../../../lib eg2
Buildfile: Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\build.xml

eg2:
   [delete] Deleting directory Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg2
    [mkdir] Created dir: Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg2
     [copy] Copying 1 file to Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg2
     [copy] Copying 1 file to Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg2
   [jjtree] Java Compiler Compiler Version 6.2_1 (Tree Builder)
   [jjtree] (type "jjtree" with no arguments for help)
   [jjtree] Reading from file Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg2.jjt . . .
   [jjtree] opt:c++
   [jjtree] File "Node.h" does not exist.  Will create one.
   [jjtree] File "SimpleNode.h" does not exist.  Will create one.
   [jjtree] File "SimpleNode.cc" does not exist.  Will create one.
   [jjtree] File "ASTUnaryExpression.h" does not exist.  Will create one.
   [jjtree] File "ASTAdd.h" does not exist.  Will create one.
   [jjtree] File "ASTStart.h" does not exist.  Will create one.
   [jjtree] File "ASTMyID.h" does not exist.  Will create one.
   [jjtree] File "ASTInteger.h" does not exist.  Will create one.
   [jjtree] File "ASTMult.h" does not exist.  Will create one.
   [jjtree] File "ASTUnaryExpression.cc" does not exist.  Will create one.
   [jjtree] File "ASTAdd.cc" does not exist.  Will create one.
   [jjtree] File "ASTStart.cc" does not exist.  Will create one.
   [jjtree] File "ASTMyID.cc" does not exist.  Will create one.
   [jjtree] File "ASTInteger.cc" does not exist.  Will create one.
   [jjtree] File "ASTMult.cc" does not exist.  Will create one.
   [jjtree] File "ParserTree.h" does not exist.  Will create one.
   [jjtree] File "ParserTreeConstants.h" does not exist.  Will create one.
   [jjtree] File "JJTParserState.h" does not exist.  Will create one.
   [jjtree] File "JJTParserState.cc" does not exist.  Will create one.
   [jjtree] Annotated grammar generated successfully in Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg2\eg2.jj
   [javacc] Java Compiler Compiler Version 6.2_1 (Parser Generator)
   [javacc] (type "javacc" with no arguments for help)
   [javacc] Reading from file Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg2\eg2.jj . . .
   [javacc] File "JavaCC.h" does not exist.  Will create one.
   [javacc] File "CharStream.h" does not exist.  Will create one.
   [javacc] File "CharStream.cc" does not exist.  Will create one.
   [javacc] File "Token.h" does not exist.  Will create one.
   [javacc] File "Token.cc" does not exist.  Will create one.
   [javacc] File "TokenManager.h" does not exist.  Will create one.
   [javacc] File "TokenMgrError.h" does not exist.  Will create one.
   [javacc] File "TokenMgrError.cc" does not exist.  Will create one.
   [javacc] File "ParseException.h" does not exist.  Will create one.
   [javacc] File "ParseException.cc" does not exist.  Will create one.
   [javacc] File "Token.h" is being rebuilt.
   [javacc] File "Token.cc" is being rebuilt.
   [javacc] File "ErrorHandler.h" does not exist.  Will create one.
   [javacc] Parser generated successfully.
     [copy] Copying 1 file to Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg2
     [copy] Copying 1 file to Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg2
[cpptasks:cc] 15 total files to be compiled.
[cpptasks:cc] In file included from Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg2\SimpleNode.cc:4:0:
[cpptasks:cc] Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg2\SimpleNode.h: In constructor ‘EG2::SimpleNode::SimpleNode(EG2::Parser*, int)’:
[cpptasks:cc] Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg2\SimpleNode.h:20:14: attention : ‘EG2::SimpleNode::parser’ will be initialized after [-Wreorder]
[cpptasks:cc]    Parser *   parser;
[cpptasks:cc]               ^
[cpptasks:cc] Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg2\SimpleNode.h:19:22: attention :   ‘int EG2::SimpleNode::id’ [-Wreorder]
[cpptasks:cc]    int                id;
[cpptasks:cc]                       ^
[cpptasks:cc] Z:\dev\llvm\x64\javacc_version_593\examples\JJTreeExamples\cpp\eg2\SimpleNode.cc:14:1: attention :   lorsqu'initialisé ici [-Wreorder]
[cpptasks:cc]  SimpleNode::SimpleNode(Parser *parser, int id) :
[cpptasks:cc]  ^
[cpptasks:cc] Starting link
     [exec] Reading from standard input...
     [exec] Start
     [exec]  Add
     [exec]   UnaryExpression
     [exec]    Integer
     [exec]   Mult
     [exec]    UnaryExpression
     [exec]     Integer
     [exec]    UnaryExpression
     [exec]     Add
     [exec]      UnaryExpression
     [exec]       Identifier: a
     [exec]      UnaryExpression
     [exec]       Identifier: b
     [exec] thank you.

BUILD SUCCESSFUL
Total time: 5 seconds

Look at eg2.jjt to see how node annotations can be used to restructure
the parse tree, and at ASTMyID.java to see how you can write your own
node classes that maintain more information from the input stream.

eg3.jjt
-------

This example can be run in the same manner as you ran eg2.jjt.

eg4.jjt
-------

This example again can be run in the same manner as you ran eg2.jjt.
