1 public class ParseNode {
4 private ParseNode parent;
5 private ParseNodeVector children;
7 private Object literal;
9 //private SymbolTable st;
11 public ParseNode(String label) {
16 children = new ParseNodeVector();
19 public ParseNode ( String label, int line ) {
24 children = new ParseNodeVector();
27 public void setLabel( String label ) {
31 public String getLabel() {
35 public void setLiteral(Object o) {
39 public Object getLiteral(Object o) {
44 public void setSymbolTable(SymbolTable st) {
46 throw new IRException("symboltable is null!");
51 public SymbolTable getSymbolTable() {
54 return parent.getSymbolTable();
64 public int getLine() {
69 return parent.getLine();
76 public void setParent( ParseNode parent ) {
80 public ParseNode getParent() {
84 public ParseNode insertChild(ParseNode child) {
88 children.insertElementAt(child, 0);
89 child.setParent(this);
93 public ParseNode insertChild(String newlabel) {
94 ParseNode child = new ParseNode(newlabel, -1);
95 return insertChild(child);
98 public ParseNode addChild( ParseNode child ) {
103 children.addElement (child);
104 child.setParent(this);
108 public ParseNode addChild( String newlabel ) {
110 ParseNode child = new ParseNode(newlabel, -1);
111 children.addElement(child);
112 child.setParent(this);
116 public ParseNode addChild (String newlabel, int line) {
117 ParseNode child = new ParseNode(newlabel, line);
118 children.addElement(child);
119 child.setParent(this);
123 public ParseNodeVector getChildren() {
127 public ParseNode getChild (String label) {
131 for (i = 0; i < children.size(); i++) {
132 p = children.elementAt(i);
133 if (p.getLabel().equals(label)) {
141 public ParseNode getRoot() {
143 return this; else return parent.getRoot();
146 public String getTerminal () {
147 ParseNode pn = children.elementAt(0);
151 return pn.getLabel();
156 public ParseNodeVector getChildren(String label) {
158 ParseNodeVector v = new ParseNodeVector();
160 for (i = 0; i < children.size(); i++) {
161 ParseNode pn = children.elementAt(i);
162 if (pn.getLabel().equals(label))
169 public String getNodeName() {
170 return label + " - " + getLine();
173 public int getNeighborCount() {
174 return children.size();
177 public Object getNeighbor(int index) {
178 return children.elementAt(index);
181 public String doIndent(int indent) {
183 String output = new String();
184 for(int i=0;i<indent;i++) output += " ";
188 public String PPrint(int indent, boolean recursive) {
190 String output = new String();
192 if (children.size()==0) {
193 output += doIndent(indent) + "<" + label + "/>\n";
195 output += doIndent(indent) + "<" + label + ">\n";
199 for (int i = 0; i < children.size(); i++) {
200 Walkable w = (Walkable)children.elementAt(i);
201 output += w.PPrint(indent, true);
204 for (int i = 0; i < children.size(); i++) {
205 Walkable w = (Walkable)children.elementAt(i);
206 output += doIndent(indent) + "<" + w.getNodeName() + "/>\n";
211 output += doIndent(indent) + "</" + label + ">\n";
219 public class String {}
221 public class ParseNodeVector {}
223 public class Object {}