1 2 package org.ejen.util.arl; 23 24 public class SimpleNode implements Node { 25 protected Node parent; 26 protected Node[] children; 27 protected int id; 28 protected ArlParser parser; 29 protected Token first, last; 31 public SimpleNode(int i) { 33 id = i; 34 } 35 36 public SimpleNode(ArlParser p, int i) { 37 this(i); 38 parser = p; 39 } 40 41 public void jjtOpen() { 42 first = parser.getToken(1); 44 } 46 47 public void jjtClose() { 48 last = parser.getToken(0); 50 } 52 53 public Token getFirstToken() { 55 return first; 56 } 57 58 public Token getLastToken() { 59 return last; 60 } 61 62 64 public void jjtSetParent(Node n) { 65 parent = n; 66 } 67 68 public Node jjtGetParent() { 69 return parent; 70 } 71 72 public void jjtAddChild(Node n, int i) { 73 if (children == null) { 74 children = new Node[i + 1]; 75 } else if (i >= children.length) { 76 Node c[] = new Node[i + 1]; 77 78 System.arraycopy(children, 0, c, 0, children.length); 79 children = c; 80 } 81 children[i] = n; 82 } 83 84 public Node jjtGetChild(int i) { 85 return children[i]; 86 } 87 88 public int jjtGetNumChildren() { 89 return (children == null) ? 0 : children.length; 90 } 91 92 97 public String toString() { 98 return ArlParserTreeConstants.jjtNodeName[id]; 99 } 100 101 public String toString(String prefix) { 102 return prefix + toString(); 103 } 104 105 107 public void dump(String prefix) { 108 System.out.println(toString(prefix)); 109 if (children != null) { 110 for (int i = 0; i < children.length; ++i) { 111 SimpleNode n = (SimpleNode) children[i]; 112 113 if (n != null) { 114 n.dump(prefix + " "); 115 } 116 } 117 } 118 } 119 } 120 | Popular Tags |