KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > antlr > ASTPair


1 package antlr;
2
3 /* ANTLR Translator Generator
4  * Project led by Terence Parr at http://www.jGuru.com
5  * Software rights: http://www.antlr.org/RIGHTS.html
6  *
7  * $Id: //depot/code/org.antlr/main/main/antlr/ASTPair.java#4 $
8  */

9
10 import antlr.collections.AST;
11
12 /** ASTPair: utility class used for manipulating a pair of ASTs
13  * representing the current AST root and current AST sibling.
14  * This exists to compensate for the lack of pointers or 'var'
15  * arguments in Java.
16  */

17 public class ASTPair {
18     public AST root; // current root of tree
19
public AST child; // current child to which siblings are added
20

21     /** Make sure that child is the last sibling */
22     public final void advanceChildToEnd() {
23         if (child != null) {
24             while (child.getNextSibling() != null) {
25                 child = child.getNextSibling();
26             }
27         }
28     }
29
30     /** Copy an ASTPair. Don't call it clone() because we want type-safety */
31     public ASTPair copy() {
32         ASTPair tmp = new ASTPair();
33         tmp.root = root;
34         tmp.child = child;
35         return tmp;
36     }
37
38     public String JavaDoc toString() {
39         String JavaDoc r = root == null ? "null" : root.getText();
40         String JavaDoc c = child == null ? "null" : child.getText();
41         return "[" + r + "," + c + "]";
42     }
43 }
44
Popular Tags