antlr::Parser Class Reference
#include <Parser.hpp>
List of all members.
Detailed Description
A generic ANTLR parser (LL(k) for k>=1) containing a bunch of utility routines useful at any lookahead depth. We distinguish between the LL(1) and LL(k) parsers because of efficiency. This may not be necessary in the near future.
Each parser object contains the state of the parse including a lookahead cache (the form of which is determined by the subclass), whether or not the parser is in guess mode, where tokens come from, etc...
During guess mode, the current lookahead token(s) and token type(s) cache must be saved because the token stream may not have been informed to save the token (via mark
) before the try
block. Guessing is started by:
-
saving the lookahead cache.
-
marking the current position in the TokenBuffer.
-
increasing the guessing level.
After guessing, the parser state is restored by:
-
restoring the lookahead cache.
-
rewinding the TokenBuffer.
-
decreasing the guessing level.
- See also:
- antlr.Token
-
antlr.TokenBuffer
-
antlr.TokenStream
-
antlr.LL1Parser
-
antlr.LLkParser
- Todo:
- add constructors with ASTFactory.
Constructor & Destructor Documentation
antlr::Parser::Parser |
( |
TokenBuffer & |
input |
) |
[inline, protected] |
antlr::Parser::Parser |
( |
TokenBuffer * |
input |
) |
[inline, protected] |
virtual antlr::Parser::~Parser |
( |
|
) |
[inline, virtual] |
antlr::Parser::Parser |
( |
const Parser & |
|
) |
[private] |
Member Function Documentation
virtual void antlr::Parser::consume |
( |
|
) |
[pure virtual] |
Get another token object from the token stream.
Implemented in antlr::LLkParser.
virtual void antlr::Parser::consumeUntil |
( |
const BitSet & |
set |
) |
[inline, virtual] |
Consume tokens until one matches the given token set.
virtual void antlr::Parser::consumeUntil |
( |
int |
tokenType |
) |
[inline, virtual] |
Consume tokens until one matches the given token.
virtual RefAST antlr::Parser::getAST |
( |
|
) |
[pure virtual] |
Get the root AST node of the generated AST. When using a custom AST type or heterogenous AST's, you'll have to convert it to the right type yourself.
virtual ASTFactory* antlr::Parser::getASTFactory |
( |
|
) |
[inline, virtual] |
Return a pointer to the ASTFactory used. So you might use it in subsequent treewalkers or to reload AST's from disk.
virtual std ::string antlr::Parser::getFilename |
( |
|
) |
const [inline, virtual] |
Return the filename of the input file.
virtual int antlr::Parser::getNumTokens |
( |
void |
|
) |
const [pure virtual] |
Get the number of tokens defined. This one should be overridden in subclasses.
virtual const char* antlr::Parser::getTokenName |
( |
int |
num |
) |
const [pure virtual] |
get the token name for the token number 'num'
virtual const char* const* antlr::Parser::getTokenNames |
( |
|
) |
const [pure virtual] |
get a vector with all token names
virtual int antlr::Parser::LA |
( |
unsigned int |
i |
) |
[pure virtual] |
Return the token type of the ith token of lookahead where i=1 is the current token being examined by the parser (i.e., it has not been matched yet).
Implemented in antlr::LLkParser.
virtual RefToken antlr::Parser::LT |
( |
unsigned int |
i |
) |
[pure virtual] |
virtual unsigned int antlr::Parser::mark |
( |
|
) |
[inline, virtual] |
Mark a spot in the input and return the position. Forwarded to TokenBuffer.
virtual void antlr::Parser::match |
( |
const BitSet & |
b |
) |
[inline, virtual] |
Make sure current lookahead symbol matches the given set Throw an exception upon mismatch, which is catch by either the error handler or by the syntactic predicate.
virtual void antlr::Parser::match |
( |
int |
t |
) |
[inline, virtual] |
Make sure current lookahead symbol matches token type t
. Throw an exception upon mismatch, which is catch by either the error handler or by the syntactic predicate.
virtual void antlr::Parser::matchNot |
( |
int |
t |
) |
[inline, virtual] |
const Parser& antlr::Parser::operator= |
( |
const Parser & |
|
) |
[private] |
called by the generated parser to do error recovery, override to customize the behaviour.
void antlr::Parser::reportError |
( |
const std::string & |
s |
) |
[virtual] |
Parser error-reporting function can be overridden in subclass.
Parser error-reporting function can be overridden in subclass
Parser error-reporting function can be overridden in subclass.
Parser error-reporting function can be overridden in subclass
void antlr::Parser::reportWarning |
( |
const std::string & |
s |
) |
[virtual] |
Parser warning-reporting function can be overridden in subclass.
Parser warning-reporting function can be overridden in subclass
virtual void antlr::Parser::rewind |
( |
unsigned int |
pos |
) |
[inline, virtual] |
rewind to a previously marked position
virtual void antlr::Parser::setASTFactory |
( |
ASTFactory * |
factory |
) |
[inline, virtual] |
Specify the factory to be used during tree building. (Compulsory) Setting the factory is nowadays compulsory.
virtual void antlr::Parser::setASTNodeFactory |
( |
ASTFactory * |
factory |
) |
[inline, virtual] |
DEPRECATED! Specify the factory to be used during tree building. (Compulsory) Setting the factory is nowadays compulsory.
- See also:
- setASTFactory
virtual void antlr::Parser::setFilename |
( |
const std::string & |
f |
) |
[inline, virtual] |
Set the filename of the input file (used for error reporting).
void antlr::Parser::traceIn |
( |
const char * |
rname |
) |
[virtual] |
void antlr::Parser::traceIndent |
( |
|
) |
[virtual] |
Set or change the input token buffer
void antlr::Parser::traceOut |
( |
const char * |
rname |
) |
[virtual] |
Member Data Documentation
AST support code; parser and treeparser delegate to this object.
The documentation for this class was generated from the following files: