1 9 10 package org.nfunk.jep; 11 12 public class SimpleNode implements Node { 13 protected Node parent; 14 protected Node[] children; 15 protected int id; 16 protected Parser parser; 17 18 public SimpleNode(int i) { 19 id = i; 20 } 21 22 public SimpleNode(Parser p, int i) { 23 this(i); 24 parser = p; 25 } 26 27 public void jjtOpen() { 28 } 29 30 public void jjtClose() { 31 } 32 33 public void jjtSetParent(Node n) { parent = n; } 34 public Node jjtGetParent() { return parent; } 35 36 public void jjtAddChild(Node n, int i) { 37 if (children == null) { 38 children = new Node[i + 1]; 39 } else if (i >= children.length) { 40 Node c[] = new Node[i + 1]; 41 System.arraycopy(children, 0, c, 0, children.length); 42 children = c; 43 } 44 children[i] = n; 45 } 46 47 public Node jjtGetChild(int i) { 48 return children[i]; 49 } 50 51 public int jjtGetNumChildren() { 52 return (children == null) ? 0 : children.length; 53 } 54 55 56 public Object jjtAccept(ParserVisitor visitor, Object data) throws ParseException 57 { 58 return visitor.visit(this, data); 59 } 60 61 62 public Object childrenAccept(ParserVisitor visitor, Object data) throws ParseException 63 { 64 if (children != null) { 65 for (int i = 0; i < children.length; ++i) { 66 children[i].jjtAccept(visitor, data); 67 } 68 } 69 return data; 70 } 71 72 77 78 public String toString() { return ParserTreeConstants.jjtNodeName[id]; } 79 public String toString(String prefix) { return prefix + toString(); } 80 81 83 84 public void dump(String prefix) 85 { 86 System.out.println(toString(prefix)); 87 if (children != null) 88 { 89 for (int i = 0; i < children.length; ++i) 90 { 91 SimpleNode n = (SimpleNode)children[i]; 92 if (n != null) { 93 n.dump(prefix + " "); 94 } 95 } 96 } 97 } 98 99 102 public int getId() { 103 return id; 104 } 105 } 106 | Popular Tags |