KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nfunk > jep > SimpleNode


1 /*****************************************************************************
2
3 JEP - Java Math Expression Parser 2.3.0
4       October 3 2004
5       (c) Copyright 2004, Nathan Funk and Richard Morris
6       See LICENSE.txt for license information.
7
8 *****************************************************************************/

9 /* Generated By:JJTree: Do not edit this line. SimpleNode.java */
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     /** Accept the visitor. **/
56     public Object JavaDoc jjtAccept(ParserVisitor visitor, Object JavaDoc data) throws ParseException
57     {
58         return visitor.visit(this, data);
59     }
60     
61     /** Accept the visitor. **/
62     public Object JavaDoc childrenAccept(ParserVisitor visitor, Object JavaDoc 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     /* You can override these two methods in subclasses of SimpleNode to
73     customize the way the node appears when the tree is dumped. If
74     your output uses more than one line you should override
75     toString(String), otherwise overriding toString() is probably all
76     you need to do. */

77     
78     public String JavaDoc toString() { return ParserTreeConstants.jjtNodeName[id]; }
79     public String JavaDoc toString(String JavaDoc prefix) { return prefix + toString(); }
80     
81     /* Override this method if you want to customize how the node dumps
82     out its children. */

83     
84     public void dump(String JavaDoc 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     /**
100      * Returns the id of the node (for simpler identification).
101      */

102     public int getId() {
103         return id;
104     }
105 }
106
Popular Tags