001: /* Copyright (c) 2006, Sun Microsystems, Inc.
002: * All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * * Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: * * Redistributions in binary form must reproduce the above copyright
010: * notice, this list of conditions and the following disclaimer in the
011: * documentation and/or other materials provided with the distribution.
012: * * Neither the name of the Sun Microsystems, Inc. nor the names of its
013: * contributors may be used to endorse or promote products derived from
014: * this software without specific prior written permission.
015: *
016: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
017: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
018: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
019: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
020: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
021: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
022: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
023: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
024: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
025: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
026: * THE POSSIBILITY OF SUCH DAMAGE.
027: */
028: package org.javacc.parser;
029:
030: import java.util.Set;
031:
032: /**
033: * Describes JavaCC productions.
034: */
035:
036: public class NormalProduction {
037:
038: /**
039: * The line and column number of the construct that corresponds
040: * most closely to this node.
041: */
042: public int line, column;
043:
044: /**
045: * The NonTerminal nodes which refer to this production.
046: */
047: java.util.Vector parents = new java.util.Vector();
048:
049: /**
050: * The access modifier of this production.
051: */
052: public String accessMod;
053:
054: /**
055: * The name of the non-terminal of this production.
056: */
057: public String lhs;
058:
059: /**
060: * The tokens that make up the return type of this production.
061: */
062: public java.util.Vector return_type_tokens = new java.util.Vector();
063:
064: /**
065: * The tokens that make up the parameters of this production.
066: */
067: public java.util.Vector parameter_list_tokens = new java.util.Vector();
068:
069: /**
070: * Each entry in this vector is a vector of tokens that represents an
071: * exception in the throws list of this production. This list does not
072: * include ParseException which is always thrown.
073: */
074: public java.util.Vector throws_list = new java.util.Vector();
075:
076: /**
077: * The RHS of this production. Not used for JavaCodeProduction.
078: */
079: public Expansion expansion;
080:
081: /**
082: * This boolean flag is true if this production can expand to empty.
083: */
084: boolean emptyPossible = false;
085:
086: /**
087: * A list of all non-terminals that this one can expand to without
088: * having to consume any tokens. Also an index that shows how many
089: * pointers exist.
090: */
091: NormalProduction[] leftExpansions = new NormalProduction[10];
092: int leIndex = 0;
093:
094: /**
095: * The following variable is used to maintain state information for the
096: * left-recursion determination algorithm: It is initialized to 0, and
097: * set to -1 if this node has been visited in a pre-order walk, and then
098: * it is set to 1 if the pre-order walk of the whole graph from this
099: * node has been traversed. i.e., -1 indicates partially processed,
100: * and 1 indicates fully processed.
101: */
102: int walkStatus = 0;
103:
104: /**
105: * The first and last tokens from the input stream that represent this
106: * production.
107: */
108: public Token firstToken, lastToken;
109:
110: protected String eol = System.getProperty("line.separator", "\n");
111:
112: protected StringBuffer dumpPrefix(int indent) {
113: StringBuffer sb = new StringBuffer(128);
114: for (int i = 0; i < indent; i++)
115: sb.append(" ");
116: return sb;
117: }
118:
119: protected String getSimpleName() {
120: String name = getClass().getName();
121: return name.substring(name.lastIndexOf(".") + 1); // strip the package name
122: }
123:
124: public StringBuffer dump(int indent, Set alreadyDumped) {
125: StringBuffer sb = dumpPrefix(indent).append(
126: System.identityHashCode(this )).append(' ').append(
127: getSimpleName()).append(' ').append(lhs);
128: if (!alreadyDumped.contains(this )) {
129: alreadyDumped.add(this );
130: if (expansion != null) {
131: sb.append(eol).append(
132: expansion.dump(indent + 1, alreadyDumped));
133: }
134: }
135:
136: return sb;
137: }
138:
139: }
|