1 33 34 35 package bsh; 36 52 class SimpleNode implements Node 53 { 54 public static SimpleNode JAVACODE = 55 new SimpleNode( -1 ) { 56 public String getSourceFile() { 57 return "<Called from Java Code>"; 58 } 59 60 public int getLineNumber() { 61 return -1; 62 } 63 64 public String getText() { 65 return "<Compiled Java Code>"; 66 } 67 }; 68 69 protected Node parent; 70 protected Node[] children; 71 protected int id; 72 Token firstToken, lastToken; 73 74 75 String sourceFile; 76 77 public SimpleNode(int i) { 78 id = i; 79 } 80 81 public void jjtOpen() { } 82 public void jjtClose() { } 83 84 public void jjtSetParent(Node n) { parent = n; } 85 public Node jjtGetParent() { return parent; } 86 88 public void jjtAddChild(Node n, int i) 89 { 90 if (children == null) 91 children = new Node[i + 1]; 92 else 93 if (i >= children.length) 94 { 95 Node c[] = new Node[i + 1]; 96 System.arraycopy(children, 0, c, 0, children.length); 97 children = c; 98 } 99 100 children[i] = n; 101 } 102 103 public Node jjtGetChild(int i) { 104 return children[i]; 105 } 106 public SimpleNode getChild( int i ) { 107 return (SimpleNode)jjtGetChild(i); 108 } 109 110 public int jjtGetNumChildren() { 111 return (children == null) ? 0 : children.length; 112 } 113 114 121 public String toString() { return ParserTreeConstants.jjtNodeName[id]; } 122 public String toString(String prefix) { return prefix + toString(); } 123 124 128 public void dump(String prefix) 129 { 130 System.out.println(toString(prefix)); 131 if(children != null) 132 { 133 for(int i = 0; i < children.length; ++i) 134 { 135 SimpleNode n = (SimpleNode)children[i]; 136 if (n != null) 137 { 138 n.dump(prefix + " "); 139 } 140 } 141 } 142 } 143 144 146 151 public void prune() { 152 jjtSetParent( null ); 153 } 154 155 158 public Object eval( CallStack callstack, Interpreter interpreter ) 159 throws EvalError 160 { 161 throw new InterpreterError( 162 "Unimplemented or inappropriate for " + getClass().getName() ); 163 } 164 165 169 public void setSourceFile( String sourceFile ) { 170 this.sourceFile = sourceFile; 171 } 172 173 180 public String getSourceFile() { 181 if ( sourceFile == null ) 182 if ( parent != null ) 183 return ((SimpleNode)parent).getSourceFile(); 184 else 185 return "<unknown file>"; 186 else 187 return sourceFile; 188 } 189 190 193 public int getLineNumber() { 194 return firstToken.beginLine; 195 } 196 197 203 204 207 public String getText() 208 { 209 StringBuffer text = new StringBuffer (); 210 Token t = firstToken; 211 while ( t!=null ) { 212 text.append(t.image); 213 if ( !t.image.equals(".") ) 214 text.append(" "); 215 if ( t==lastToken || 216 t.image.equals("{") || t.image.equals(";") ) 217 break; 218 t=t.next; 219 } 220 221 return text.toString(); 222 } 223 } 224 225 | Popular Tags |