1
#ifndef INC_TreeParser_hpp__
2
#define INC_TreeParser_hpp__
4
/* ANTLR Translator Generator
5
* Project led by Terence Parr at http://www.jGuru.com
6
* Software rights: http://www.antlr.org/RIGHTS.html
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>
17
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
21
class ANTLR_API TreeParser {
24
TreeParser(const TreeParserSharedInputState& state);
25
virtual ~TreeParser();
27
/// Get the AST return value squirreled away in the parser
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.
37
virtual void match(RefAST t, const BitSet& b);
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()
45
virtual void setASTFactory(ASTFactory* factory)
49
/// Return pointer to ASTFactory
50
virtual ASTFactory* getASTFactory() const
54
/// Get the name for token 'num'
55
virtual const char* getTokenName(int num) const = 0;
56
virtual int getNumTokens() const = 0;
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
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);
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
77
static RefAST ASTNULL;
80
virtual void match(RefAST t, int ttype);
81
virtual void matchNot(RefAST t, int ttype);
83
/** Where did this rule leave off parsing; avoids a return parameter */
85
/** AST return value for a rule is squirreled away here */
87
/** AST support code; parser and treeparser delegate to this object */
88
ASTFactory* astFactory;
90
/// The input state of this tree parser.
91
TreeParserSharedInputState inputState;
93
/** Used to keep track of indent depth with -traceTreeParser */
96
/** Utility class which allows tracing to work even when exceptions are
105
Tracer(TreeParser* p, const char* t, RefAST a)
106
: parser(p), text(t), tree(a)
108
parser->traceIn(text,tree);
112
parser->traceOut(text,tree);
115
Tracer(const Tracer&); // undefined
116
const Tracer& operator=(const Tracer&); // undefined
120
// no copying of treeparser instantiations...
121
TreeParser(const TreeParser& other);
122
TreeParser& operator=(const TreeParser& other);
125
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
129
#endif //INC_TreeParser_hpp__