ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/antlr/ASTPair.hpp
Revision: 2469
Committed: Fri Dec 2 15:38:03 2005 UTC (18 years, 7 months ago) by tim
File size: 1572 byte(s)
Log Message:
End of the Link --> List
Return of the Oject-Oriented
replace yacc/lex parser with antlr parser

File Contents

# Content
1 #ifndef INC_ASTPair_hpp__
2 #define INC_ASTPair_hpp__
3
4 /* ANTLR Translator Generator
5 * Project led by Terence Parr at http://www.jGuru.com
6 * Software rights: http://www.antlr.org/license.html
7 *
8 * $Id: ASTPair.hpp,v 1.1 2005-12-02 15:38:02 tim Exp $
9 */
10
11 #include <antlr/config.hpp>
12 #include <antlr/AST.hpp>
13
14 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
15 namespace antlr {
16 #endif
17
18 /** ASTPair: utility class used for manipulating a pair of ASTs
19 * representing the current AST root and current AST sibling.
20 * This exists to compensate for the lack of pointers or 'var'
21 * arguments in Java.
22 *
23 * OK, so we can do those things in C++, but it seems easier
24 * to stick with the Java way for now.
25 */
26 class ANTLR_API ASTPair {
27 public:
28 RefAST root; // current root of tree
29 RefAST child; // current child to which siblings are added
30
31 /** Make sure that child is the last sibling */
32 void advanceChildToEnd() {
33 if (child) {
34 while (child->getNextSibling()) {
35 child = child->getNextSibling();
36 }
37 }
38 }
39 // /** Copy an ASTPair. Don't call it clone() because we want type-safety */
40 // ASTPair copy() {
41 // ASTPair tmp = new ASTPair();
42 // tmp.root = root;
43 // tmp.child = child;
44 // return tmp;
45 // }
46 ANTLR_USE_NAMESPACE(std)string toString() const {
47 ANTLR_USE_NAMESPACE(std)string r = !root ? ANTLR_USE_NAMESPACE(std)string("null") : root->getText();
48 ANTLR_USE_NAMESPACE(std)string c = !child ? ANTLR_USE_NAMESPACE(std)string("null") : child->getText();
49 return "["+r+","+c+"]";
50 }
51 };
52
53 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
54 }
55 #endif
56
57 #endif //INC_ASTPair_hpp__