Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Parser Class Reference

#include <Parser.hpp>

Inheritance diagram for Parser:

TextHandler ArabicParser BrillPOSParser ChineseCharParser ChineseParser IdentifinderParser InqArabicParser InQueryOpParser LLkParser ReutersParser TrecParser WebParser List of all members.

Public Methods

virtual ~Parser ()
virtual int LA (unsigned int i)=0
virtual RefToken LT (unsigned int i)=0
 Return the i-th token of lookahead.

virtual void setASTNodeFactory (ASTFactory *factory)
virtual void setASTFactory (ASTFactory *factory)
virtual ASTFactory * getASTFactory ()
virtual RefAST getAST ()
virtual ANTLR_USE_NAMESPACE (std) string getFilename() const
 Return the filename of the input file.

virtual void setFilename (const ANTLR_USE_NAMESPACE(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)
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

virtual void reportError (const RecognitionException &ex)
 Parser error-reporting function can be overridden in subclass.

virtual void reportError (const ANTLR_USE_NAMESPACE(std) string &s)
 Parser error-reporting function can be overridden in subclass.

virtual void reportWarning (const ANTLR_USE_NAMESPACE(std) string &s)
 Parser warning-reporting function can be overridden in subclass.

virtual void panic ()
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
virtual void traceIndent ()
virtual void traceIn (const char *rname)
virtual void traceOut (const char *rname)
 Parser ()
virtual ~Parser ()
virtual void parse (const string &filename)
virtual void parseFile (const string &filename)=0
virtual void parseBuffer (char *buf, int len)=0
 Parse a buffer.

virtual void setAcroList (const WordSet *acronyms)
virtual void setAcroList (string filename)
 Set the acronym list from this file.

virtual long fileTell () const=0
 return the current byte position of the file being parsed

virtual long getDocBytePos () const
 return the byte position at the beginning of the current document

virtual const string getParseFile () const
 return the name of the file being parsed


Static Public Attributes

const string category = "Parser"
const string identifier = "parser"

Protected Methods

 Parser (TokenBuffer &input_)
 Parser (TokenBuffer *input_)
 Parser (const ParserSharedInputState &state)
bool isAcronym (const char *word)
void clearAcros ()
 clears internal acronym list


Protected Attributes

ParserSharedInputState inputState
ASTFactory * astFactory
 AST support code; parser and treeparser delegate to this object.

int traceDepth
long docpos
string parsefile

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.


Constructor & Destructor Documentation

Parser::Parser (  TokenBuffer &    input_ )  [protected]
 

Parser::Parser (  TokenBuffer *    input_ )  [protected]
 

Parser::Parser (  const ParserSharedInputState &    state )  [protected]
 

Parser::~Parser (    )  [virtual]
 

Parser::Parser (    ) 
 

virtual Parser::~Parser (    )  [virtual]
 


Member Function Documentation

virtual Parser::ANTLR_USE_NAMESPACE (  std    )  const [inline, virtual]
 

Return the filename of the input file.

void Parser::clearAcros (    )  [protected]
 

clears internal acronym list

virtual void Parser::consume (    )  [pure virtual]
 

Get another token object from the token stream.

Implemented in LLkParser.

void Parser::consumeUntil (  const BitSet &    set )  [virtual]
 

Consume tokens until one matches the given token set.

Consume tokens until one matches the given token set

void Parser::consumeUntil (  int    tokenType )  [virtual]
 

Consume tokens until one matches the given token.

Consume tokens until one matches the given token

virtual long Parser::fileTell (    )  [pure virtual]
 

return the current byte position of the file being parsed

Implemented in ArabicParser, BrillPOSParser, ChineseCharParser, ChineseParser, IdentifinderParser, InqArabicParser, InQueryOpParser, ReutersParser, TrecParser, and WebParser.

virtual RefAST Parser::getAST (    )  [inline, 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* 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 long Parser::getDocBytePos (    )  const [inline, virtual]
 

return the byte position at the beginning of the current document

virtual ParserSharedInputState Parser::getInputState (    )  const [inline, virtual]
 

virtual int Parser::getNumTokens (  void    )  const [pure virtual]
 

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

virtual const string Parser::getParseFile (    )  const [inline, virtual]
 

return the name of the file being parsed

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

get the token name for the token number 'num'

virtual const char* const* Parser::getTokenNames (    )  [pure virtual]
 

get a vector with all token names

bool Parser::isAcronym (  const char *    word )  [protected]
 

Checks to see if the word is in the acronym list. Returns false if the list is not set.

virtual int 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 LLkParser.

virtual RefToken Parser::LT (  unsigned int    i )  [pure virtual]
 

Return the i-th token of lookahead.

Implemented in LLkParser.

virtual unsigned int Parser::mark (    )  [inline, virtual]
 

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

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

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

void Parser::matchNot (  int    t )  [virtual]
 

void Parser::panic (    )  [virtual]
 

Give panic message and exit the program. can be overridden in subclass

Deprecated:
this method is unused and will dissappear in the next release

void Parser::parse (  const string &    filename )  [virtual]
 

Parse a file. use parseFile. this method will be deprecated in future

virtual void Parser::parseBuffer (  char *    buf,
int    len
)  [pure virtual]
 

Parse a buffer.

Implemented in ArabicParser, BrillPOSParser, ChineseCharParser, ChineseParser, IdentifinderParser, InqArabicParser, InQueryOpParser, ReutersParser, TrecParser, and WebParser.

virtual void Parser::parseFile (  const string &    filename )  [pure virtual]
 

Parse a file. implementing subclasses should set parsefile string

Implemented in ArabicParser, BrillPOSParser, ChineseCharParser, ChineseParser, IdentifinderParser, InqArabicParser, InQueryOpParser, ReutersParser, TrecParser, and WebParser.

void Parser::reportError (  const ANTLR_USE_NAMESPACE(std) string &    s )  [virtual]
 

Parser error-reporting function can be overridden in subclass.

Parser error-reporting function can be overridden in subclass

void Parser::reportError (  const RecognitionException &    ex )  [virtual]
 

Parser error-reporting function can be overridden in subclass.

Parser error-reporting function can be overridden in subclass

void Parser::reportWarning (  const ANTLR_USE_NAMESPACE(std) string &    s )  [virtual]
 

Parser warning-reporting function can be overridden in subclass.

Parser warning-reporting function can be overridden in subclass

virtual void Parser::rewind (  unsigned int    pos )  [inline, virtual]
 

rewind to a previously marked position

void Parser::setAcroList (  string    filename )  [virtual]
 

Set the acronym list from this file.

void Parser::setAcroList (  const WordSet *    acronyms )  [virtual]
 

Set the acronym list. Can be an empty implementation if the parser is not designed to deal with acronyms by using a list. WordSet still belongs to the caller

virtual void Parser::setASTFactory (  ASTFactory *    factory )  [inline, virtual]
 

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

virtual void 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 Parser::setFilename (  const ANTLR_USE_NAMESPACE(std) string &    f )  [inline, virtual]
 

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

virtual void Parser::setInputState (  ParserSharedInputState    state )  [inline, virtual]
 

void Parser::traceIn (  const char *    rname )  [virtual]
 

Reimplemented in LLkParser.

void Parser::traceIndent (    )  [virtual]
 

Set or change the input token buffer

void Parser::traceOut (  const char *    rname )  [virtual]
 

Reimplemented in LLkParser.


Member Data Documentation

ASTFactory* Parser::astFactory [protected]
 

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

const string Parser::category = "Parser" [static]
 

Reimplemented from TextHandler.

long Parser::docpos [protected]
 

const string Parser::identifier = "parser" [static]
 

Reimplemented from TextHandler.

Reimplemented in ArabicParser, BrillPOSParser, ChineseCharParser, ChineseParser, IdentifinderParser, InqArabicParser, InQueryOpParser, ReutersParser, TrecParser, and WebParser.

ParserSharedInputState Parser::inputState [protected]
 

string Parser::parsefile [protected]
 

int Parser::traceDepth [protected]
 


The documentation for this class was generated from the following files:
Generated on Wed Nov 3 12:59:50 2004 for Lemur Toolkit by doxygen1.2.18