01: package org.antlr.runtime.tree;
02:
03: import org.antlr.runtime.Token;
04:
05: /** What does a tree look like? ANTLR has a number of support classes
06: * such as CommonTreeNodeStream that work on these kinds of trees. You
07: * don't have to make your trees implement this interface, but if you do,
08: * you'll be able to use more support code.
09: *
10: * NOTE: When constructing trees, ANTLR can build any kind of tree; it can
11: * even use Token objects as trees if you add a child list to your tokens.
12: *
13: * This is a tree node without any payload; just navigation and factory stuff.
14: */
15: public interface Tree {
16: public static final Tree INVALID_NODE = new CommonTree(
17: Token.INVALID_TOKEN);
18:
19: Tree getChild(int i);
20:
21: int getChildCount();
22:
23: /** Add t as a child to this node. If t is null, do nothing. If t
24: * is nil, add all children of t to this' children.
25: * @param t
26: */
27: void addChild(Tree t);
28:
29: /** Indicates the node is a nil node but may still have children, meaning
30: * the tree is a flat list.
31: */
32: boolean isNil();
33:
34: /** What is the smallest token index (indexing from 0) for this node
35: * and its children?
36: */
37: int getTokenStartIndex();
38:
39: void setTokenStartIndex(int index);
40:
41: /** What is the largest token index (indexing from 0) for this node
42: * and its children?
43: */
44: int getTokenStopIndex();
45:
46: void setTokenStopIndex(int index);
47:
48: Tree dupTree();
49:
50: Tree dupNode();
51:
52: /** Return a token type; needed for tree parsing */
53: int getType();
54:
55: String getText();
56:
57: /** In case we don't have a token payload, what is the line for errors? */
58: int getLine();
59:
60: int getCharPositionInLine();
61:
62: String toStringTree();
63:
64: String toString();
65: }
|