1#ifndef INC_Parser_hpp__
2#define INC_Parser_hpp__
11#include <antlr/config.hpp>
16#include <antlr/BitSet.hpp>
17#include <antlr/TokenBuffer.hpp>
18#include <antlr/RecognitionException.hpp>
19#include <antlr/MismatchedTokenException.hpp>
20#include <antlr/ASTFactory.hpp>
21#include <antlr/ParserSharedInputState.hpp>
23#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
27extern bool DEBUG_PARSER;
75 : inputState(state), astFactory(0), traceDepth(0)
87 virtual int LA(
unsigned int i)=0;
105 astFactory = factory;
124 return inputState->filename;
129 inputState->filename = f;
136 virtual inline ParserSharedInputState getInputState()
const
146 while (LA(1) != Token::EOF_TYPE && LA(1) != tokenType)
153 while (LA(1) != Token::EOF_TYPE && !set.member(LA(1)))
166 ANTLR_USE_NAMESPACE(std)cout <<
"enter match(" << t <<
") with LA(1)=" << LA(1) << ANTLR_USE_NAMESPACE(std)endl;
173 ANTLR_USE_NAMESPACE(std)cout <<
"token mismatch: " << LA(1) <<
"!=" << t << ANTLR_USE_NAMESPACE(std)endl;
184 virtual void matchNot(
int t)
207 ANTLR_USE_NAMESPACE(std)cout <<
"enter match(" <<
"bitset"
208 <<
") with LA(1)=" << LA(1) << ANTLR_USE_NAMESPACE(std)endl;
210 if ( !b.member(LA(1)) )
215 ANTLR_USE_NAMESPACE(std)cout <<
"token mismatch: " << LA(1) <<
" not member of "
216 <<
"bitset" << ANTLR_USE_NAMESPACE(std)endl;
230 virtual inline unsigned int mark()
232 return inputState->getInput().mark();
235 virtual inline void rewind(
unsigned int pos)
237 inputState->getInput().rewind(pos);
245 consumeUntil(tokenSet);
251 virtual void reportError(
const ANTLR_USE_NAMESPACE(std)
string& s);
253 virtual void reportWarning(
const ANTLR_USE_NAMESPACE(std)
string& s);
267 virtual void traceIndent();
268 virtual void traceIn(
const char* rname);
269 virtual void traceOut(
const char* rname);
295 parser->traceIn(text);
299#ifdef ANTLR_CXX_SUPPORTS_UNCAUGHT_EXCEPTION
301 if(!ANTLR_USE_NAMESPACE(std)uncaught_exceptions())
303 parser->traceOut(text);
315#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
AST Super Factory shared by TreeParser and Parser.
A BitSet to replace java.util.BitSet.
Utility class which allows tracing to work even when exceptions are thrown.
A generic ANTLR parser (LL(k) for k>=1) containing a bunch of utility routines useful at any lookahea...
virtual void setASTNodeFactory(ASTFactory *factory)
DEPRECATED! Specify the factory to be used during tree building.
virtual ASTFactory * getASTFactory()
Return a pointer to the ASTFactory used.
virtual void setASTFactory(ASTFactory *factory)
Specify the factory to be used during tree building.
virtual std::string getFilename() const
Return the filename of the input file.
virtual void match(int t)
Make sure current lookahead symbol matches token type t.
virtual void recover(const RecognitionException &, const BitSet &tokenSet)
called by the generated parser to do error recovery, override to customize the behaviour.
ASTFactory * astFactory
AST support code; parser and treeparser delegate to this object.
virtual const char *const * getTokenNames() const =0
get a vector with all token names
virtual RefAST getAST()=0
Get the root AST node of the generated AST.
virtual int getNumTokens(void) const =0
Get the number of tokens defined.
virtual unsigned int mark()
Mark a spot in the input and return the position.
virtual void setFilename(const std ::string &f)
Set the filename of the input file (used for error reporting).
virtual int LA(unsigned int i)=0
Return the token type of the ith token of lookahead where i=1 is the current token being examined by ...
virtual void consumeUntil(const BitSet &set)
Consume tokens until one matches the given token set.
virtual void consumeUntil(int tokenType)
Consume tokens until one matches the given token.
virtual void match(const BitSet &b)
Make sure current lookahead symbol matches the given set Throw an exception upon mismatch,...
virtual RefToken LT(unsigned int i)=0
Return the i-th token of lookahead.
virtual void consume()=0
Get another token object from the token stream.
virtual const char * getTokenName(int num) const =0
get the token name for the token number 'num'
virtual void rewind(unsigned int pos)
rewind to a previously marked position
A Stream of Token objects fed to the parser from a TokenStream that can be rewound via mark()/rewind(...