Grammatica
|
A base parser class. More...
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... | |
A base parser class.
This class provides the standard parser interface, as well as token handling.
|
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.
pattern | the pattern to add |
ParserCreationException | if the pattern couldn't be added correctly to the parser |
Reimplemented in PerCederberg.Grammatica.Runtime.RecursiveDescentParser.
|
inline |
Returns the analyzer in use by this parser.
|
inline |
Returns the tokenizer in use by this parser.
|
inlineprotectedvirtual |
Creates a new analyzer for this parser.
Can be overridden by a subclass to provide a custom implementation.
|
inlineprotectedvirtual |
Factory method to create a new production node.
This method can be overridden to provide other production implementations than the default one.
pattern | the production pattern |
|
inlineprotectedvirtual |
Creates a new tokenizer for this parser.
Can be overridden by a subclass to provide a custom implementation.
in | the input stream to read from |
ParserCreationException | if the tokenizer couldn't be initialized correctly |
|
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.
ParserCreationException | if the parser couldn't be initialized correctly |
ParserLogException | if the input couldn't be parsed correctly |
|
protectedpure virtual |
Parses the token stream and returns a parse tree.
ParseException | if the input couldn't be parsed correctly |
Implemented in PerCederberg.Grammatica.Runtime.RecursiveDescentParser.
|
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.
ParserCreationException | if the parser couldn't be initialized correctly |
Reimplemented in PerCederberg.Grammatica.Runtime.RecursiveDescentParser.
|
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.
input | the new input stream to read |
|
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.
input | the new input stream to read |
analyzer | the new analyzer callback to use |
|
inline |
Returns a string representation of this parser.
The string will contain all the production definitions and various additional information.
|
get |
The analyzer property (read-only).
This property contains the analyzer in use by this parser.
|
get |
The tokenizer property (read-only).
This property contains the tokenizer in use by this parser.