~ubuntu-branches/ubuntu/breezy/antlr/breezy

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2005-06-29 16:11:22 UTC
  • mfrom: (0.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050629161122-g81crc3z92p5xhsg
Tags: 2.7.5-6ubuntu4
Build depend on java-gcj-compat-dev, depend on java-gcj-compat.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 * Project led by Terence Parr at http://www.jGuru.com
6
6
 * Software rights: http://www.antlr.org/license.html
7
7
 *
8
 
 * $Id: //depot/code/org.antlr/release/antlr-2.7.4/lib/cpp/antlr/TreeParser.hpp#1 $
 
8
 * $Id: //depot/code/org.antlr/release/antlr-2.7.5/lib/cpp/antlr/TreeParser.hpp#1 $
9
9
 */
10
10
 
11
11
#include <antlr/config.hpp>
13
13
#include <antlr/ASTFactory.hpp>
14
14
#include <antlr/BitSet.hpp>
15
15
#include <antlr/RecognitionException.hpp>
 
16
#include <antlr/MismatchedTokenException.hpp>
16
17
#include <antlr/TreeParserSharedInputState.hpp>
17
18
 
18
19
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
21
22
 
22
23
class ANTLR_API TreeParser {
23
24
public:
24
 
        TreeParser();
25
 
        TreeParser(const TreeParserSharedInputState& state);
26
 
        virtual ~TreeParser();
 
25
        TreeParser()
 
26
        : astFactory(0)
 
27
        , inputState(new TreeParserInputState())
 
28
        , traceDepth(0)
 
29
        {
 
30
        }
 
31
 
 
32
        TreeParser(const TreeParserSharedInputState& state)
 
33
        : astFactory(0)
 
34
        , inputState(state)
 
35
        , traceDepth(0)
 
36
        {
 
37
        }
 
38
 
 
39
        virtual ~TreeParser()
 
40
        {
 
41
        }
27
42
 
28
43
        /// Get the AST return value squirreled away in the parser
29
44
        virtual RefAST getAST() = 0;
30
45
 
31
46
        /** Make sure current lookahead symbol matches the given set
32
 
         * Throw an exception upon mismatch, which is catch by either the
33
 
         * error handler or by the syntactic predicate.
 
47
         * Throw an exception upon mismatch, which is caught by either the
 
48
         * error handler or by a syntactic predicate.
34
49
         */
35
 
        virtual void match(RefAST t, const BitSet& b);
 
50
        virtual void match(RefAST t, const BitSet& b)
 
51
        {
 
52
                if ( !t || t==ASTNULL || !b.member(t->getType()) )
 
53
                        throw MismatchedTokenException( getTokenNames(), getNumTokens(),
 
54
                                                                                                          t, b, false );
 
55
        }
36
56
 
37
57
        /** Specify the AST factory to be used during tree building. (Compulsory)
38
58
         * Setting the factory is compulsory (if you intend to modify
62
82
        virtual void reportError(const ANTLR_USE_NAMESPACE(std)string& s);
63
83
        /// Parser warning-reporting function can be overridden in subclass
64
84
        virtual void reportWarning(const ANTLR_USE_NAMESPACE(std)string& s);
65
 
        /** Give panic message and exit the program. can be overridden in subclass
66
 
         * @deprecated this method is unused and will dissappear in the next release
67
 
         */
68
 
        virtual void panic();
69
85
 
70
86
        /// These are used during when traceTreeParser commandline option is passed.
71
87
        virtual void traceIndent();
80
96
        static RefAST ASTNULL;
81
97
 
82
98
protected:
83
 
        virtual void match(RefAST t, int ttype);
84
 
        virtual void matchNot(RefAST t, int ttype);
85
 
 
86
 
        /* Where did this rule leave off parsing; avoids a return parameter */
87
 
        //RefAST _retTree;
88
 
        /* AST return value for a rule is squirreled away here */
89
 
        //RefAST returnAST;
 
99
        virtual void match(RefAST t, int ttype)
 
100
        {
 
101
                if (!t || t == ASTNULL || t->getType() != ttype )
 
102
                        throw MismatchedTokenException( getTokenNames(), getNumTokens(),
 
103
                                                                                                          t, ttype, false );
 
104
        }
 
105
 
 
106
        virtual void matchNot(RefAST t, int ttype)
 
107
        {
 
108
                if ( !t || t == ASTNULL || t->getType() == ttype )
 
109
                        throw MismatchedTokenException( getTokenNames(), getNumTokens(),
 
110
                                                                                                          t, ttype, true );
 
111
        }
 
112
 
90
113
        /** AST support code; parser and treeparser delegate to this object */
91
114
        ASTFactory* astFactory;
92
115