~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to lib/antlr/antlr/TreeParser.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef INC_TreeParser_hpp__
 
2
#define INC_TreeParser_hpp__
 
3
 
 
4
/* ANTLR Translator Generator
 
5
 * Project led by Terence Parr at http://www.jGuru.com
 
6
 * Software rights: http://www.antlr.org/RIGHTS.html
 
7
 *
 
8
 */
 
9
 
 
10
#include <antlr/config.hpp>
 
11
#include <antlr/AST.hpp>
 
12
#include <antlr/ASTFactory.hpp>
 
13
#include <antlr/BitSet.hpp>
 
14
#include <antlr/RecognitionException.hpp>
 
15
#include <antlr/TreeParserSharedInputState.hpp>
 
16
 
 
17
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
 
18
namespace antlr {
 
19
#endif
 
20
 
 
21
class ANTLR_API TreeParser {
 
22
public:
 
23
        TreeParser();
 
24
        TreeParser(const TreeParserSharedInputState& state);
 
25
        virtual ~TreeParser();
 
26
 
 
27
        /// Get the AST return value squirreled away in the parser
 
28
        RefAST getAST() const
 
29
        {
 
30
                return returnAST;
 
31
        }
 
32
 
 
33
        /** Make sure current lookahead symbol matches the given set
 
34
         * Throw an exception upon mismatch, which is catch by either the
 
35
         * error handler or by the syntactic predicate.
 
36
         */
 
37
        virtual void match(RefAST t, const BitSet& b);
 
38
 
 
39
        /** Specify the AST factory to be used during tree building. (Compulsory)
 
40
         * Setting the factory is compulsory (if you intend to modify
 
41
         * the tree in the treeparser). The AST Factory is shared between
 
42
         * parser (who builds the initial AST) and treeparser.
 
43
         * @see Parser::getASTFactory()
 
44
         */
 
45
        virtual void setASTFactory(ASTFactory* factory)
 
46
        {
 
47
                astFactory = factory;
 
48
        }
 
49
        /// Return pointer to ASTFactory
 
50
        virtual ASTFactory* getASTFactory() const
 
51
        {
 
52
                return astFactory;
 
53
        }
 
54
        /// Get the name for token 'num'
 
55
        virtual const char* getTokenName(int num) const = 0;
 
56
        virtual int getNumTokens() const = 0;
 
57
 
 
58
        /// Parser error-reporting function can be overridden in subclass
 
59
        virtual void reportError(const RecognitionException& ex);
 
60
        /// Parser error-reporting function can be overridden in subclass
 
61
        virtual void reportError(const ANTLR_USE_NAMESPACE(std)string& s);
 
62
        /// Parser warning-reporting function can be overridden in subclass
 
63
        virtual void reportWarning(const ANTLR_USE_NAMESPACE(std)string& s);
 
64
        /// Give panic message and exit the program. can be overridden in subclass
 
65
        static void panic();
 
66
 
 
67
        /// These are used during when traceTreeParser commandline option is passed.
 
68
        virtual void traceIndent();
 
69
        virtual void traceIn(const char* rname, RefAST t);
 
70
        virtual void traceOut(const char* rname, RefAST t);
 
71
 
 
72
        /** The AST Null object; the parsing cursor is set to this when
 
73
         * it is found to be null.  This way, we can test the
 
74
         * token type of a node without having to have tests for 0
 
75
         * everywhere.
 
76
         */
 
77
        static RefAST ASTNULL;
 
78
 
 
79
protected:
 
80
        virtual void match(RefAST t, int ttype);
 
81
        virtual void matchNot(RefAST t, int ttype);
 
82
 
 
83
        /** Where did this rule leave off parsing; avoids a return parameter */
 
84
        RefAST _retTree;
 
85
        /** AST return value for a rule is squirreled away here */
 
86
        RefAST returnAST;
 
87
        /** AST support code; parser and treeparser delegate to this object */
 
88
        ASTFactory* astFactory;
 
89
 
 
90
        /// The input state of this tree parser.
 
91
        TreeParserSharedInputState inputState;
 
92
 
 
93
        /** Used to keep track of indent depth with -traceTreeParser */
 
94
        int traceDepth;
 
95
 
 
96
        /** Utility class which allows tracing to work even when exceptions are
 
97
         * thrown.
 
98
         */
 
99
        class Tracer {
 
100
        private:
 
101
                TreeParser* parser;
 
102
                const char* text;
 
103
                RefAST tree;
 
104
        public:
 
105
                Tracer(TreeParser* p, const char* t, RefAST a)
 
106
                : parser(p), text(t), tree(a)
 
107
                {
 
108
                        parser->traceIn(text,tree);
 
109
                }
 
110
                ~Tracer()
 
111
                {
 
112
                        parser->traceOut(text,tree);
 
113
                }
 
114
        private:
 
115
                Tracer(const Tracer&);                                                  // undefined
 
116
                const Tracer& operator=(const Tracer&); // undefined
 
117
        };
 
118
 
 
119
private:
 
120
        // no copying of treeparser instantiations...
 
121
        TreeParser(const TreeParser& other);
 
122
        TreeParser& operator=(const TreeParser& other);
 
123
};
 
124
 
 
125
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
 
126
}
 
127
#endif
 
128
 
 
129
#endif //INC_TreeParser_hpp__