OpenMD 3.1
Molecular Dynamics in the Open
|
A generic ANTLR parser (LL(k) for k>=1) containing a bunch of utility routines useful at any lookahead depth. More...
#include <Parser.hpp>
Classes | |
class | Tracer |
Utility class which allows tracing to work even when exceptions are thrown. More... | |
Public Member Functions | |
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 the parser (i.e., it has not been matched yet). | |
virtual RefToken | LT (unsigned int i)=0 |
Return the i-th token of lookahead. | |
virtual void | setASTNodeFactory (ASTFactory *factory) |
DEPRECATED! Specify the factory to be used during tree building. | |
virtual void | setASTFactory (ASTFactory *factory) |
Specify the factory to be used during tree building. | |
virtual ASTFactory * | getASTFactory () |
Return a pointer to the ASTFactory used. | |
virtual RefAST | getAST ()=0 |
Get the root AST node of the generated AST. | |
virtual std::string | getFilename () const |
Return the filename of the input file. | |
virtual void | setFilename (const std ::string &f) |
Set the filename of the input file (used for error reporting). | |
virtual void | setInputState (ParserSharedInputState state) |
virtual ParserSharedInputState | getInputState () const |
virtual void | consume ()=0 |
Get another token object from the token stream. | |
virtual void | consumeUntil (int tokenType) |
Consume tokens until one matches the given token. | |
virtual void | consumeUntil (const BitSet &set) |
Consume tokens until one matches the given token set. | |
virtual void | match (int t) |
Make sure current lookahead symbol matches token type t . | |
virtual void | matchNot (int t) |
virtual void | match (const BitSet &b) |
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 unsigned int | mark () |
Mark a spot in the input and return the position. | |
virtual void | rewind (unsigned int pos) |
rewind to a previously marked position | |
virtual void | recover (const RecognitionException &, const BitSet &tokenSet) |
called by the generated parser to do error recovery, override to customize the behaviour. | |
virtual void | reportError (const RecognitionException &ex) |
Parser error-reporting function can be overridden in subclass. | |
virtual void | reportError (const std ::string &s) |
Parser error-reporting function can be overridden in subclass. | |
virtual void | reportWarning (const std ::string &s) |
Parser warning-reporting function can be overridden in subclass. | |
virtual const char * | getTokenName (int num) const =0 |
get the token name for the token number 'num' | |
virtual const char *const * | getTokenNames () const =0 |
get a vector with all token names | |
virtual int | getNumTokens (void) const =0 |
Get the number of tokens defined. | |
virtual void | traceIndent () |
Set or change the input token buffer. | |
virtual void | traceIn (const char *rname) |
virtual void | traceOut (const char *rname) |
Protected Member Functions | |
Parser (TokenBuffer &input) | |
Parser (TokenBuffer *input) | |
Parser (const ParserSharedInputState &state) | |
Protected Attributes | |
ParserSharedInputState | inputState |
ASTFactory * | astFactory |
AST support code; parser and treeparser delegate to this object. | |
int | traceDepth |
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:
After guessing, the parser state is restored by:
Definition at line 64 of file Parser.hpp.
|
inlineprotected |
Definition at line 66 of file Parser.hpp.
|
inlineprotected |
Definition at line 70 of file Parser.hpp.
|
inlineprotected |
Definition at line 74 of file Parser.hpp.
|
inlinevirtual |
Definition at line 79 of file Parser.hpp.
|
pure virtual |
Get another token object from the token stream.
Implemented in antlr::LLkParser.
|
inlinevirtual |
Consume tokens until one matches the given token set.
Definition at line 151 of file Parser.hpp.
|
inlinevirtual |
Consume tokens until one matches the given token.
Definition at line 144 of file Parser.hpp.
|
pure virtual |
|
inlinevirtual |
Return a pointer to the ASTFactory used.
So you might use it in subsequent treewalkers or to reload AST's from disk.
Definition at line 111 of file Parser.hpp.
|
inlinevirtual |
Return the filename of the input file.
Definition at line 122 of file Parser.hpp.
Referenced by reportError(), and reportWarning().
|
inlinevirtual |
Definition at line 136 of file Parser.hpp.
|
pure virtual |
Get the number of tokens defined.
This one should be overridden in subclasses.
|
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.
|
pure virtual |
Return the i-th token of lookahead.
Implemented in antlr::LLkParser.
|
inlinevirtual |
Mark a spot in the input and return the position.
Forwarded to TokenBuffer.
Definition at line 230 of file Parser.hpp.
|
inlinevirtual |
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.
Definition at line 202 of file Parser.hpp.
|
inlinevirtual |
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.
Definition at line 161 of file Parser.hpp.
|
inlinevirtual |
Definition at line 184 of file Parser.hpp.
|
inlinevirtual |
called by the generated parser to do error recovery, override to customize the behaviour.
Definition at line 242 of file Parser.hpp.
|
virtual |
Parser error-reporting function can be overridden in subclass.
Definition at line 53 of file Parser.cpp.
References antlr::RecognitionException::toString().
|
virtual |
Parser error-reporting function can be overridden in subclass.
Definition at line 59 of file Parser.cpp.
References getFilename().
|
virtual |
Parser warning-reporting function can be overridden in subclass.
Definition at line 68 of file Parser.cpp.
References getFilename().
|
inlinevirtual |
rewind to a previously marked position
Definition at line 235 of file Parser.hpp.
|
inlinevirtual |
Specify the factory to be used during tree building.
(Compulsory) Setting the factory is nowadays compulsory.
Definition at line 103 of file Parser.hpp.
|
inlinevirtual |
DEPRECATED! Specify the factory to be used during tree building.
(Compulsory) Setting the factory is nowadays compulsory.
Definition at line 96 of file Parser.hpp.
|
inlinevirtual |
Set the filename of the input file (used for error reporting).
Definition at line 127 of file Parser.hpp.
|
inlinevirtual |
Definition at line 132 of file Parser.hpp.
|
virtual |
Definition at line 85 of file Parser.cpp.
|
virtual |
Set or change the input token buffer.
Definition at line 79 of file Parser.cpp.
|
virtual |
Definition at line 98 of file Parser.cpp.
|
protected |
AST support code; parser and treeparser delegate to this object.
Definition at line 279 of file Parser.hpp.
|
protected |
Definition at line 273 of file Parser.hpp.
|
protected |
Definition at line 282 of file Parser.hpp.