OpenMD  2.5
Molecular Dynamics in the Open
antlr::Parser Class Referenceabstract

#include <Parser.hpp>

Inheritance diagram for antlr::Parser:
antlr::LLkParser

Classes

class  Tracer
 

Public Member Functions

virtual ~Parser ()
 
virtual int LA (unsigned int i)=0
 
virtual RefToken LT (unsigned int i)=0
 Return the i-th token of lookahead. More...
 
virtual void setASTNodeFactory (ASTFactory *factory)
 
virtual void setASTFactory (ASTFactory *factory)
 
virtual ASTFactorygetASTFactory ()
 
virtual RefAST getAST ()=0
 
virtual std ::string getFilename () const
 Return the filename of the input file. More...
 
virtual void setFilename (const std ::string &f)
 Set the filename of the input file (used for error reporting). More...
 
virtual void setInputState (ParserSharedInputState state)
 
virtual ParserSharedInputState getInputState () const
 
virtual void consume ()=0
 Get another token object from the token stream. More...
 
virtual void consumeUntil (int tokenType)
 Consume tokens until one matches the given token. More...
 
virtual void consumeUntil (const BitSet &set)
 Consume tokens until one matches the given token set. More...
 
virtual void match (int t)
 
virtual void matchNot (int t)
 
virtual void match (const BitSet &b)
 
virtual unsigned int mark ()
 
virtual void rewind (unsigned int pos)
 rewind to a previously marked position More...
 
virtual void recover (const RecognitionException &ex, const BitSet &tokenSet)
 
virtual void reportError (const RecognitionException &ex)
 Parser error-reporting function can be overridden in subclass. More...
 
virtual void reportError (const std ::string &s)
 Parser error-reporting function can be overridden in subclass. More...
 
virtual void reportWarning (const std ::string &s)
 Parser warning-reporting function can be overridden in subclass. More...
 
virtual const char * getTokenName (int num) const =0
 get the token name for the token number 'num' More...
 
virtual const char *const * getTokenNames () const =0
 get a vector with all token names More...
 
virtual int getNumTokens (void) const =0
 
virtual void traceIndent ()
 
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
 
ASTFactoryastFactory
 AST support code; parser and treeparser delegate to this object. More...
 
int traceDepth
 

Private Member Functions

 Parser (const Parser &)
 
const Parseroperator= (const Parser &)
 

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:

  1. saving the lookahead cache.
  2. marking the current position in the TokenBuffer.
  3. increasing the guessing level.

After guessing, the parser state is restored by:

  1. restoring the lookahead cache.
  2. rewinding the TokenBuffer.
  3. decreasing the guessing level.
See also
antlr.Token
antlr.TokenBuffer
antlr.TokenStream
antlr.LL1Parser
antlr.LLkParser
Todo:
add constructors with ASTFactory.

Definition at line 64 of file Parser.hpp.

Constructor & Destructor Documentation

◆ Parser() [1/4]

antlr::Parser::Parser ( TokenBuffer input)
inlineprotected

Definition at line 66 of file Parser.hpp.

◆ Parser() [2/4]

antlr::Parser::Parser ( TokenBuffer input)
inlineprotected

Definition at line 70 of file Parser.hpp.

◆ Parser() [3/4]

antlr::Parser::Parser ( const ParserSharedInputState state)
inlineprotected

Definition at line 74 of file Parser.hpp.

◆ ~Parser()

virtual antlr::Parser::~Parser ( )
inlinevirtual

Definition at line 79 of file Parser.hpp.

◆ Parser() [4/4]

antlr::Parser::Parser ( const Parser )
private

Member Function Documentation

◆ consume()

virtual void antlr::Parser::consume ( )
pure virtual

Get another token object from the token stream.

Implemented in antlr::LLkParser.

◆ consumeUntil() [1/2]

virtual void antlr::Parser::consumeUntil ( int  tokenType)
inlinevirtual

Consume tokens until one matches the given token.

Definition at line 144 of file Parser.hpp.

References antlr::Token::EOF_TYPE.

◆ consumeUntil() [2/2]

virtual void antlr::Parser::consumeUntil ( const BitSet set)
inlinevirtual

Consume tokens until one matches the given token set.

Definition at line 151 of file Parser.hpp.

References antlr::Token::EOF_TYPE.

◆ getAST()

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.

◆ getASTFactory()

virtual ASTFactory* antlr::Parser::getASTFactory ( )
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.

◆ getFilename()

virtual std ::string antlr::Parser::getFilename ( ) const
inlinevirtual

Return the filename of the input file.

Definition at line 122 of file Parser.hpp.

Referenced by reportError(), and reportWarning().

◆ getInputState()

virtual ParserSharedInputState antlr::Parser::getInputState ( ) const
inlinevirtual

Definition at line 136 of file Parser.hpp.

◆ getNumTokens()

virtual int antlr::Parser::getNumTokens ( void  ) const
pure virtual

Get the number of tokens defined. This one should be overridden in subclasses.

◆ getTokenName()

virtual const char* antlr::Parser::getTokenName ( int  num) const
pure virtual

get the token name for the token number 'num'

◆ getTokenNames()

virtual const char* const* antlr::Parser::getTokenNames ( ) const
pure virtual

get a vector with all token names

◆ LA()

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.

◆ LT()

virtual RefToken antlr::Parser::LT ( unsigned int  i)
pure virtual

Return the i-th token of lookahead.

Implemented in antlr::LLkParser.

Referenced by traceIn(), and traceOut().

◆ mark()

virtual unsigned int antlr::Parser::mark ( )
inlinevirtual

Mark a spot in the input and return the position. Forwarded to TokenBuffer.

Definition at line 230 of file Parser.hpp.

◆ match() [1/2]

virtual void antlr::Parser::match ( int  t)
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.

References ANTLR_USE_NAMESPACE.

◆ match() [2/2]

virtual void antlr::Parser::match ( const BitSet b)
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.

References ANTLR_USE_NAMESPACE, and antlr::BitSet::member().

◆ matchNot()

virtual void antlr::Parser::matchNot ( int  t)
inlinevirtual

Definition at line 184 of file Parser.hpp.

◆ operator=()

const Parser& antlr::Parser::operator= ( const Parser )
private

◆ recover()

virtual void antlr::Parser::recover ( const RecognitionException ex,
const BitSet tokenSet 
)
inlinevirtual

called by the generated parser to do error recovery, override to customize the behaviour.

Definition at line 242 of file Parser.hpp.

References ANTLR_USE_NAMESPACE.

◆ reportError() [1/2]

void antlr::Parser::reportError ( const RecognitionException ex)
virtual

Parser error-reporting function can be overridden in subclass.

Parser error-reporting function can be overridden in subclass

Definition at line 53 of file Parser.cpp.

References ANTLR_USE_NAMESPACE, and antlr::RecognitionException::toString().

◆ reportError() [2/2]

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

Definition at line 59 of file Parser.cpp.

References ANTLR_USE_NAMESPACE, and getFilename().

◆ reportWarning()

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

Definition at line 68 of file Parser.cpp.

References ANTLR_USE_NAMESPACE, and getFilename().

◆ rewind()

virtual void antlr::Parser::rewind ( unsigned int  pos)
inlinevirtual

rewind to a previously marked position

Definition at line 235 of file Parser.hpp.

◆ setASTFactory()

virtual void antlr::Parser::setASTFactory ( ASTFactory factory)
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.

◆ setASTNodeFactory()

virtual void antlr::Parser::setASTNodeFactory ( ASTFactory factory)
inlinevirtual

DEPRECATED! Specify the factory to be used during tree building. (Compulsory) Setting the factory is nowadays compulsory.

See also
setASTFactory

Definition at line 96 of file Parser.hpp.

◆ setFilename()

virtual void antlr::Parser::setFilename ( const std ::string &  f)
inlinevirtual

Set the filename of the input file (used for error reporting).

Definition at line 127 of file Parser.hpp.

◆ setInputState()

virtual void antlr::Parser::setInputState ( ParserSharedInputState  state)
inlinevirtual

Definition at line 132 of file Parser.hpp.

◆ traceIn()

void antlr::Parser::traceIn ( const char *  rname)
virtual

◆ traceIndent()

void antlr::Parser::traceIndent ( )
virtual

Set or change the input token buffer

Definition at line 79 of file Parser.cpp.

References ANTLR_USE_NAMESPACE, and traceDepth.

Referenced by antlr::LLkParser::trace().

◆ traceOut()

void antlr::Parser::traceOut ( const char *  rname)
virtual

Member Data Documentation

◆ astFactory

ASTFactory* antlr::Parser::astFactory
protected

AST support code; parser and treeparser delegate to this object.

Definition at line 279 of file Parser.hpp.

◆ inputState

ParserSharedInputState antlr::Parser::inputState
protected

Definition at line 273 of file Parser.hpp.

Referenced by antlr::LLkParser::trace(), traceIn(), and traceOut().

◆ traceDepth

int antlr::Parser::traceDepth
protected

The documentation for this class was generated from the following files: