source: trunk/yao/share/antlr-2.7.7/lib/csharp/antlr.runtime/antlr/ASTPair.cs @ 1

Last change on this file since 1 was 1, checked in by lnalod, 15 years ago

Initial import of YAO sources

File size: 1.5 KB
Line 
1namespace antlr
2{
3        using System;
4        using Queue = System.Collections.Queue;
5        using AST       = antlr.collections.AST;
6
7        /*ANTLR Translator Generator
8        * Project led by Terence Parr at http://www.jGuru.com
9        * Software rights: http://www.antlr.org/license.html
10        *
11        * $Id:$
12        */
13
14        //
15        // ANTLR C# Code Generator by Micheal Jordan
16        //                            Kunle Odutola       : kunle UNDERSCORE odutola AT hotmail DOT com
17        //                            Anthony Oguntimehin
18        //
19        // With many thanks to Eric V. Smith from the ANTLR list.
20        //
21
22
23        /*ASTPair:  utility class used for manipulating a pair of ASTs
24        * representing the current AST root and current AST sibling.
25        * This exists to compensate for the lack of pointers or 'var'
26        * arguments in Java.
27        */
28
29        public struct ASTPair
30        {
31                public AST root; // current root of tree
32                public AST child; // current child to which siblings are added
33               
34                /*Make sure that child is the last sibling */
35                public void  advanceChildToEnd()
36                {
37                        if (child != null)
38                        {
39                                while (child.getNextSibling() != null)
40                                {
41                                        child = child.getNextSibling();
42                                }
43                        }
44                }
45               
46                /*Copy an ASTPair.  Don't call it clone() because we want type-safety */
47                public ASTPair copy()
48                {
49                        ASTPair tmp = new ASTPair();
50                        tmp.root = root;
51                        tmp.child = child;
52                        return tmp;
53                }
54
55                private void reset()
56                {
57                        root  = null;
58                        child = null;
59                }
60               
61                override public string ToString()
62                {
63                        string r = (root == null) ? "null" : root.getText();
64                        string c = (child == null) ? "null" : child.getText();
65                        return "[" + r + "," + c + "]";
66                }
67        }
68}
Note: See TracBrowser for help on using the repository browser.