Grammatica
Public Member Functions | Protected Member Functions | Properties | List of all members
PerCederberg.Grammatica.Runtime.Parser Class Referenceabstract

A base parser class. More...

Inheritance diagram for PerCederberg.Grammatica.Runtime.Parser:
PerCederberg.Grammatica.Runtime.RecursiveDescentParser

Public Member Functions

Tokenizer GetTokenizer ()
 Returns the tokenizer in use by this parser. More...
 
Analyzer GetAnalyzer ()
 Returns the analyzer in use by this parser. More...
 
virtual void AddPattern (ProductionPattern pattern)
 Adds a new production pattern to the parser. More...
 
virtual void Prepare ()
 Initializes the parser. More...
 
void Reset (TextReader input)
 Resets this parser for usage with another input stream. More...
 
void Reset (TextReader input, Analyzer analyzer)
 Resets this parser for usage with another input stream. More...
 
Node Parse ()
 Parses the token stream and returns a parse tree. More...
 
override string ToString ()
 Returns a string representation of this parser. More...
 

Protected Member Functions

virtual Tokenizer NewTokenizer (TextReader input)
 Creates a new tokenizer for this parser. More...
 
virtual Analyzer NewAnalyzer ()
 Creates a new analyzer for this parser. More...
 
abstract Node ParseStart ()
 Parses the token stream and returns a parse tree. More...
 
virtual Production NewProduction (ProductionPattern pattern)
 Factory method to create a new production node. More...
 

Properties

Tokenizer Tokenizer [get]
 The tokenizer property (read-only). More...
 
Analyzer Analyzer [get]
 The analyzer property (read-only). More...
 

Detailed Description

A base parser class.

This class provides the standard parser interface, as well as token handling.

Author
Per Cederberg
Version
1.6

Member Function Documentation

virtual void PerCederberg.Grammatica.Runtime.Parser.AddPattern ( ProductionPattern  pattern)
inlinevirtual

Adds a new production pattern to the parser.

The first pattern added is assumed to be the starting point in the grammar. The patterns added may be validated to some extent.

Parameters
patternthe pattern to add
Exceptions
ParserCreationExceptionif the pattern couldn't be added correctly to the parser

Reimplemented in PerCederberg.Grammatica.Runtime.RecursiveDescentParser.

Analyzer PerCederberg.Grammatica.Runtime.Parser.GetAnalyzer ( )
inline

Returns the analyzer in use by this parser.

Returns
the analyzer in use by this parser
Since
1.4
See also
Analyzer
Deprecated:
Use the Analyzer property instead.
Tokenizer PerCederberg.Grammatica.Runtime.Parser.GetTokenizer ( )
inline

Returns the tokenizer in use by this parser.

Returns
the tokenizer in use by this parser
Since
1.4
See also
Tokenizer
Deprecated:
Use the Tokenizer property instead.
virtual Analyzer PerCederberg.Grammatica.Runtime.Parser.NewAnalyzer ( )
inlineprotectedvirtual

Creates a new analyzer for this parser.

Can be overridden by a subclass to provide a custom implementation.

Returns
the analyzer created
Since
1.5
virtual Production PerCederberg.Grammatica.Runtime.Parser.NewProduction ( ProductionPattern  pattern)
inlineprotectedvirtual

Factory method to create a new production node.

This method can be overridden to provide other production implementations than the default one.

Parameters
patternthe production pattern
Returns
the new production node
Since
1.5
virtual Tokenizer PerCederberg.Grammatica.Runtime.Parser.NewTokenizer ( TextReader  input)
inlineprotectedvirtual

Creates a new tokenizer for this parser.

Can be overridden by a subclass to provide a custom implementation.

Parameters
inthe input stream to read from
Returns
the tokenizer created
Exceptions
ParserCreationExceptionif the tokenizer couldn't be initialized correctly
Since
1.5
Node PerCederberg.Grammatica.Runtime.Parser.Parse ( )
inline

Parses the token stream and returns a parse tree.

This method will call Prepare() if not previously called. It will also call the Reset() method, to make sure that only the Tokenizer.Reset() method must be explicitly called in order to reuse a parser for multiple input streams. In case of a parse error, the parser will attempt to recover and throw all the errors found in a parser log exception in the end.

Returns
the parse tree
Exceptions
ParserCreationExceptionif the parser couldn't be initialized correctly
ParserLogExceptionif the input couldn't be parsed correctly
See also
Prepare
Reset
Tokenizer::Reset
abstract Node PerCederberg.Grammatica.Runtime.Parser.ParseStart ( )
protectedpure virtual

Parses the token stream and returns a parse tree.

Returns
the parse tree
Exceptions
ParseExceptionif the input couldn't be parsed correctly

Implemented in PerCederberg.Grammatica.Runtime.RecursiveDescentParser.

virtual void PerCederberg.Grammatica.Runtime.Parser.Prepare ( )
inlinevirtual

Initializes the parser.

All the added production patterns will be analyzed for ambiguities and errors. This method also initializes internal data structures used during the parsing.

Exceptions
ParserCreationExceptionif the parser couldn't be initialized correctly

Reimplemented in PerCederberg.Grammatica.Runtime.RecursiveDescentParser.

void PerCederberg.Grammatica.Runtime.Parser.Reset ( TextReader  input)
inline

Resets this parser for usage with another input stream.

The associated tokenizer and analyzer will also be reset. This method will clear all the internal state and the error log in the parser. It is normally called in order to reuse a parser and tokenizer pair with multiple input streams, thereby avoiding the cost of re-analyzing the grammar structures.

Parameters
inputthe new input stream to read
See also
Tokenizer::Reset
Analyzer::Reset
Since
1.5
void PerCederberg.Grammatica.Runtime.Parser.Reset ( TextReader  input,
Analyzer  analyzer 
)
inline

Resets this parser for usage with another input stream.

The associated tokenizer will also be reset and the analyzer replaced. This method will clear all the internal state and the error log in the parser. It is normally called in order to reuse a parser and tokenizer pair with multiple input streams, thereby avoiding the cost of re-analyzing the grammar structures.

Parameters
inputthe new input stream to read
analyzerthe new analyzer callback to use
See also
Tokenizer::Reset
Since
1.6
override string PerCederberg.Grammatica.Runtime.Parser.ToString ( )
inline

Returns a string representation of this parser.

The string will contain all the production definitions and various additional information.

Returns
a detailed string representation of this parser

Property Documentation

Analyzer PerCederberg.Grammatica.Runtime.Parser.Analyzer
get

The analyzer property (read-only).

This property contains the analyzer in use by this parser.

Since
1.5
Tokenizer PerCederberg.Grammatica.Runtime.Parser.Tokenizer
get

The tokenizer property (read-only).

This property contains the tokenizer in use by this parser.

Since
1.5

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