001: /* ====================================================================
002: * Tea - Copyright (c) 1997-2000 Walt Disney Internet Group
003: * ====================================================================
004: * The Tea Software License, Version 1.1
005: *
006: * Copyright (c) 2000 Walt Disney Internet Group. All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Walt Disney Internet Group (http://opensource.go.com/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "Tea", "TeaServlet", "Kettle", "Trove" and "BeanDoc" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact opensource@dig.com.
031: *
032: * 5. Products derived from this software may not be called "Tea",
033: * "TeaServlet", "Kettle" or "Trove", nor may "Tea", "TeaServlet",
034: * "Kettle", "Trove" or "BeanDoc" appear in their name, without prior
035: * written permission of the Walt Disney Internet Group.
036: *
037: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
038: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
039: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
040: * DISCLAIMED. IN NO EVENT SHALL THE WALT DISNEY INTERNET GROUP OR ITS
041: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
042: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
043: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
044: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
045: * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
046: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
047: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
048: * ====================================================================
049: *
050: * For more information about Tea, please see http://opensource.go.com/.
051: */
052:
053: package com.go.tea.parsetree;
054:
055: /******************************************************************************
056: * A NodeVisitor enables operations to be performed on a parse tree.
057: * The Visitor design pattern is discussed in detail in <i>Design Patterns</i>
058: * (ISBN 0-201-63361-2) by Gamma, Helm, Johnson and Vlissides.
059: *
060: * <p>The traditional operations performed on parse trees are type checking
061: * and code generation. The Visitor allows those operations to all be
062: * encapsulated into one place instead of having that functionality spread
063: * out into every Node subclass. It also makes it easy to target multiple
064: * languages by allowing any kind of code generation Visitor to be
065: * designed.
066: *
067: * <p>When using a Visitor to traverse a parse tree, the code responsible
068: * for moving the traversal into children nodes can either be placed in
069: * the nodes or in the Visitor implementation. The NodeVisitor places that
070: * responsibility onto NodeVisitor implementations because it is much
071: * more flexible. As a result, all Nodes have the same simple implementation
072: * for their "accept" method, but do not inherit it.
073: *
074: * <p>Every visit method in this interface returns an Object. The definition
075: * of that returned Object is left up to the specific implementation of the
076: * NodeVisitor. Most NodeVisitors can simply return null, but those that
077: * are modifying a parse tree or are using one to create another can use the
078: * returned Object to pass around newly created Nodes.
079: *
080: * @author Brian S O'Neill
081: * @version
082: * <!--$$Revision:--> 30 <!-- $-->, <!--$$JustDate:--> 5/31/01 <!-- $-->
083: * @see Node#accept(NodeVisitor)
084: */
085: public interface NodeVisitor {
086: public Object visit(Template node);
087:
088: public Object visit(Name node);
089:
090: public Object visit(TypeName node);
091:
092: public Object visit(Variable node);
093:
094: public Object visit(ExpressionList node);
095:
096: public Object visit(Statement node);
097:
098: public Object visit(StatementList node);
099:
100: public Object visit(Block node);
101:
102: public Object visit(AssignmentStatement node);
103:
104: public Object visit(ForeachStatement node);
105:
106: public Object visit(IfStatement node);
107:
108: public Object visit(SubstitutionStatement node);
109:
110: public Object visit(ExpressionStatement node);
111:
112: public Object visit(ReturnStatement node);
113:
114: public Object visit(ExceptionGuardStatement node);
115:
116: public Object visit(BreakStatement node);
117:
118: public Object visit(Expression node);
119:
120: public Object visit(ParenExpression node);
121:
122: public Object visit(NewArrayExpression node);
123:
124: public Object visit(FunctionCallExpression node);
125:
126: public Object visit(TemplateCallExpression node);
127:
128: public Object visit(VariableRef node);
129:
130: public Object visit(Lookup node);
131:
132: public Object visit(ArrayLookup node);
133:
134: public Object visit(NegateExpression node);
135:
136: public Object visit(NotExpression node);
137:
138: public Object visit(ConcatenateExpression node);
139:
140: public Object visit(ArithmeticExpression node);
141:
142: public Object visit(RelationalExpression node);
143:
144: public Object visit(AndExpression node);
145:
146: public Object visit(OrExpression node);
147:
148: public Object visit(NullLiteral node);
149:
150: public Object visit(BooleanLiteral node);
151:
152: public Object visit(StringLiteral node);
153:
154: public Object visit(NumberLiteral node);
155: }
|