Parser Class Reference

Inheritance diagram for Parser:
AnnotationParser GLSLParser PreprocessorParser

List of all members.

Classes

class  ParserSymbol

Public Member Functions

 Parser (Lexer *const lexer, const bool deleteLexer=false)
bool hasLexer () const
const std::ostringstream & getLog () const
ParseTreeNodeparse ()
 Parses the given input.
void setDebugging (const bool debug)

Protected Member Functions

virtual ParserActionaction (const int state, const int symbol) const =0
 Action-Table for this parser.
virtual void expandParseTree (const int productionID, const std::vector< Parser::ParserSymbol * > &reductionBody)=0
 Nodes-stack operations to perform when reducing the production related to the given ID.
virtual ProductionStubfindProduction (const int productionID) const =0
 Returns a ProductionStub which is consists of the ID of the head symbol and the IDs of the symbol from the body.
virtual int gotoState (const int state, const int symbol) const =0
 Goto-Table for this parser.
virtual std::string symbolID2String (const int symbolID) const =0
 Returns the corresponding lexeme for the symbol with the given ID if such a symbol exists.
template<class NODE >
NODE * popNode ()
 Pops the top node from the nodes-stack, casts it to the given template parameter and returns it, if the statck is not empty.
ParseTreeNodepopNode ()
void pushNode (ParseTreeNode *const node)
 Pushes the given node onto the nodes-stack, if it is not NULL.
virtual bool isProxySymbol (const int, const int) const
 While reducing a production to its head, this method is called in case that the considered symbol's ID does not match the required one from the body of the prodcution.
virtual TokennextToken ()
 Called within parse() to provide the next token for parsing.

Friends

bool operator== (const Parser::ParserSymbol &lhs, const Parser::ParserSymbol &rhs)
bool operator!= (const Parser::ParserSymbol &lhs, const Parser::ParserSymbol &rhs)

Detailed Description

Definition at line 42 of file parser.h.


Member Function Documentation

virtual ParserAction* action ( const int  state,
const int  symbol 
) const [protected, pure virtual]

Action-Table for this parser.

The caller has to delete the returned object using C++ delete-operator.

Implemented in AnnotationParser, GLSLParser, and PreprocessorParser.

virtual void expandParseTree ( const int  productionID,
const std::vector< Parser::ParserSymbol * > &  reductionBody 
) [protected, pure virtual]

Nodes-stack operations to perform when reducing the production related to the given ID.

This actually builds the ParseTreeNodes which hold the semantics of the parsed input.

virtual ProductionStub* findProduction ( const int  productionID  )  const [protected, pure virtual]

Returns a ProductionStub which is consists of the ID of the head symbol and the IDs of the symbol from the body.

The production stub is used to check integrity while reducing the states-stack.

This method is called by Parser::reduce() and calls expandParseTree() itself.

Implemented in AnnotationParser, GLSLParser, and PreprocessorParser.

virtual int gotoState ( const int  state,
const int  symbol 
) const [protected, pure virtual]

Goto-Table for this parser.

Determines the transition for the parser's state according to the given state and the symbol (the symbol ID to be more precise).

Implemented in AnnotationParser, GLSLParser, and PreprocessorParser.

virtual bool isProxySymbol ( const   int,
const   int 
) const [inline, protected, virtual]

While reducing a production to its head, this method is called in case that the considered symbol's ID does not match the required one from the body of the prodcution.

If the symbol within the body of the production is a wildcard symbol, the reduction will continue instead of raising a fatal error.

This is useful in case of the GLSL preprocessor where there productions containing a terminal symbol called TOKEN which is actually a wildcard for all possible tokens which might have been emitted by the driving lexical analysator (lexer).

Reimplemented in GLSLParser, and PreprocessorParser.

Definition at line 178 of file parser.h.

Token * nextToken (  )  [protected, virtual]

Called within parse() to provide the next token for parsing.

The default implementation takes the next token from the lexer. If the returned token is NULL, the parser will stop parsing after it has performed all possible reductions left.

Reimplemented in AnnotationParser, and PreprocessorParser.

Definition at line 152 of file parser.cpp.

ParseTreeNode * parse (  ) 

Parses the given input.

Returns:
Pointer to the root node of the parse tree, which is identified with that root node. The node may have children.

Definition at line 60 of file parser.cpp.

ParseTreeNode * popNode (  )  [inline, protected]

Pops the top node from the nodes-stack, casts it to the given template parameter and returns it, if the statck is not empty.

If the nodes-stack is empty or the topmost node cannot be casted to the desired type, the method returns NULL.

Definition at line 143 of file parser.h.

virtual std::string symbolID2String ( const int  symbolID  )  const [protected, pure virtual]

Returns the corresponding lexeme for the symbol with the given ID if such a symbol exists.

Otherwise the returned string is empty.

Implemented in AnnotationParser, GLSLParser, and PreprocessorParser.