X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FIR%2FTree%2FParseNode.java;h=cc5009712906a8b25b50714ad90458effd21625d;hb=ac6191b514c0e54b468623bf868134e1ce809df5;hp=e5e34d2183ddaf3a29a8ca7c0cd94753245a2790;hpb=b9df1caacff3dbe5959bc12e0e6ba46500fcd3e2;p=IRC.git
diff --git a/Robust/src/IR/Tree/ParseNode.java b/Robust/src/IR/Tree/ParseNode.java
index e5e34d21..cc500971 100644
--- a/Robust/src/IR/Tree/ParseNode.java
+++ b/Robust/src/IR/Tree/ParseNode.java
@@ -1,10 +1,10 @@
/*
-
- Class: ParseNode
- Author: Dan Roy
- Purpose: ParseNode is used to represent a parse production
-*/
+ Class: ParseNode
+ Author: Dan Roy
+ Purpose: ParseNode is used to represent a parse production
+
+ */
package IR.Tree;
@@ -12,223 +12,223 @@ import java.util.*;
public class ParseNode implements Walkable {
- private String label;
- private ParseNode parent;
- private ParseNodeVector children;
- private int line;
- private Object literal;
-
- //private SymbolTable st;
-
- public ParseNode(String label) {
- this.label = label;
- this.line = -1;
- this.parent = null;
- this.literal=null;
- children = new ParseNodeVector();
- }
-
- public ParseNode ( String label, int line ) {
- this.label = label;
- this.line = line;
- this.parent = null;
- this.literal=null;
- children = new ParseNodeVector();
- }
-
- public void setLabel( String label ) {
- this.label = label;
- }
-
- public String getLabel() {
- return label;
- }
-
- public void setLiteral(Object o) {
- literal=o;
- }
-
- public Object getLiteral() {
- return literal;
- }
+ private String label;
+ private ParseNode parent;
+ private ParseNodeVector children;
+ private int line;
+ private Object literal;
+
+ //private SymbolTable st;
+
+ public ParseNode(String label) {
+ this.label = label;
+ this.line = -1;
+ this.parent = null;
+ this.literal=null;
+ children = new ParseNodeVector();
+ }
+
+ public ParseNode (String label, int line) {
+ this.label = label;
+ this.line = line;
+ this.parent = null;
+ this.literal=null;
+ children = new ParseNodeVector();
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLiteral(Object o) {
+ literal=o;
+ }
+
+ public Object getLiteral() {
+ return literal;
+ }
+
+ /*
+ public void setSymbolTable(SymbolTable st) {
+ if (st == null) {
+ throw new IRException("symboltable is null!");
+ }
+ this.st = st;
+ }
+
+ public SymbolTable getSymbolTable() {
+ if (st == null) {
+ if (parent != null) {
+ return parent.getSymbolTable();
+ } else {
+ return null;
+ }
+ } else {
+ return st;
+ }
+ }
+ */
+
+ public int getLine() {
+ if (line >= 0) {
+ return line;
+ } else {
+ if (parent != null) {
+ return parent.getLine();
+ } else {
+ return 0;
+ }
+ }
+ }
+
+ public void setParent(ParseNode parent) {
+ this.parent = parent;
+ }
+
+ public ParseNode getParent() {
+ return parent;
+ }
+
+ public ParseNode insertChild(ParseNode child) {
+ if (child == null) {
+ throw new NullPointerException("Can't add null node to parse tree");
+ }
+
+ children.insertElementAt(child, 0);
+ child.setParent(this);
+ return child;
+ }
+
+ public ParseNode insertChild(String newlabel) {
+ ParseNode child = new ParseNode(newlabel, -1);
+ return insertChild(child);
+ }
+
+ public ParseNode addChild(ParseNode child) {
+
+ if (child == null) {
+ throw new NullPointerException("Can't add null node to parse tree: "+getLabel());
+ }
+
+ children.addElement(child);
+ child.setParent(this);
+ return child;
+ }
+
+ public ParseNode addChild(String newlabel) {
+
+ ParseNode child = new ParseNode(newlabel, -1);
+ children.addElement(child);
+ child.setParent(this);
+ return child;
+ }
+
+ public ParseNode addChild(String newlabel, int line) {
+ ParseNode child = new ParseNode(newlabel, line);
+ children.addElement(child);
+ child.setParent(this);
+ return child;
+ }
+
+ public ParseNodeVector getChildren() {
+ return children;
+ }
+
+ public ParseNode getChild(String label) {
+ int i;
+ ParseNode p;
+
+ for (i = 0; i < children.size(); i++) {
+ p = children.elementAt(i);
+ if (p.getLabel().equals(label)) {
+ return p;
+ }
+ }
+
+ return null;
+ }
+
+ public ParseNode getRoot() {
+ return (parent == null) ? this : parent.getRoot();
+ }
+
+ public String getTerminal() {
+ ParseNode pn = children.elementAt(0);
+ if (pn == null) {
+ return null;
+ } else {
+ return pn.getLabel();
+ }
+ }
- /*
- public void setSymbolTable(SymbolTable st) {
- if (st == null) {
- throw new IRException("symboltable is null!");
- }
- this.st = st;
- }
-
- public SymbolTable getSymbolTable() {
- if (st == null) {
- if (parent != null) {
- return parent.getSymbolTable();
- } else {
- return null;
- }
- } else {
- return st;
- }
- }
- */
-
- public int getLine() {
- if (line >= 0) {
- return line;
- } else {
- if (parent != null) {
- return parent.getLine();
- } else {
- return 0;
- }
- }
- }
-
- public void setParent( ParseNode parent ) {
- this.parent = parent;
- }
-
- public ParseNode getParent() {
- return parent;
- }
-
- public ParseNode insertChild(ParseNode child) {
- if (child == null) {
- throw new NullPointerException("Can't add null node to parse tree");
- }
+ public ParseNode getFirstChild() {
+ return children.elementAt(0);
+ }
- children.insertElementAt(child, 0);
- child.setParent(this);
- return child;
- }
+ public ParseNodeVector getChildren(String label) {
+ int i;
+ ParseNodeVector v = new ParseNodeVector();
- public ParseNode insertChild(String newlabel) {
- ParseNode child = new ParseNode(newlabel, -1);
- return insertChild(child);
+ for (i = 0; i < children.size(); i++) {
+ ParseNode pn = children.elementAt(i);
+ if (pn.getLabel().equals(label))
+ v.addElement(pn);
}
- public ParseNode addChild( ParseNode child ) {
+ return v;
+ }
- if (child == null) {
- throw new NullPointerException("Can't add null node to parse tree: "+getLabel());
- }
+ public String getNodeName() {
+ return label + " - " + getLine();
+ }
- children.addElement (child);
- child.setParent(this);
- return child;
- }
+ public int getNeighborCount() {
+ return children.size();
+ }
- public ParseNode addChild( String newlabel ) {
-
- ParseNode child = new ParseNode(newlabel, -1);
- children.addElement(child);
- child.setParent(this);
- return child;
- }
+ public Object getNeighbor(int index) {
+ return children.elementAt(index);
+ }
- public ParseNode addChild (String newlabel, int line) {
- ParseNode child = new ParseNode(newlabel, line);
- children.addElement(child);
- child.setParent(this);
- return child;
- }
-
- public ParseNodeVector getChildren() {
- return children;
- }
+ public String doIndent(int indent) {
- public ParseNode getChild (String label) {
- int i;
- ParseNode p;
+ String output = new String();
+ for(int i=0; i\n";
+ } else {
+ output += doIndent(indent) + "<" + label + ">\n";
+ indent += 2;
- public String getTerminal () {
- ParseNode pn = children.elementAt(0);
- if (pn == null) {
- return null;
- } else {
- return pn.getLabel();
+ if (recursive) {
+ for (int i = 0; i < children.size(); i++) {
+ Walkable w = (Walkable)children.elementAt(i);
+ output += w.PPrint(indent, true);
}
- }
-
- public ParseNode getFirstChild() {
- return children.elementAt(0);
- }
-
- public ParseNodeVector getChildren(String label) {
- int i;
- ParseNodeVector v = new ParseNodeVector();
-
- for (i = 0; i < children.size(); i++) {
- ParseNode pn = children.elementAt(i);
- if (pn.getLabel().equals(label))
- v.addElement(pn);
+ } else {
+ for (int i = 0; i < children.size(); i++) {
+ Walkable w = (Walkable)children.elementAt(i);
+ output += doIndent(indent) + "<" + w.getNodeName() + "/>\n";
}
+ }
- return v;
- }
-
- public String getNodeName() {
- return label + " - " + getLine();
- }
-
- public int getNeighborCount() {
- return children.size();
- }
-
- public Object getNeighbor(int index) {
- return children.elementAt(index);
+ indent -= 2;
+ output += doIndent(indent) + "" + label + ">\n";
}
- public String doIndent(int indent) {
-
- String output = new String();
- for(int i=0;i\n";
- } else {
- output += doIndent(indent) + "<" + label + ">\n";
- indent += 2;
-
- if (recursive) {
- for (int i = 0; i < children.size(); i++) {
- Walkable w = (Walkable)children.elementAt(i);
- output += w.PPrint(indent, true);
- }
- } else {
- for (int i = 0; i < children.size(); i++) {
- Walkable w = (Walkable)children.elementAt(i);
- output += doIndent(indent) + "<" + w.getNodeName() + "/>\n";
- }
- }
-
- indent -= 2;
- output += doIndent(indent) + "" + label + ">\n";
- }
-
- return output;
- }
+ return output;
+ }
}