Grammatica
Classes | Public Member Functions | Protected Member Functions | List of all members
PerCederberg.Grammatica.Runtime.RecursiveDescentParser Class Reference

A recursive descent parser. More...

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

Public Member Functions

 RecursiveDescentParser (TextReader input)
 Creates a new parser. More...
 
 RecursiveDescentParser (TextReader input, Analyzer analyzer)
 Creates a new parser. More...
 
 RecursiveDescentParser (Tokenizer tokenizer)
 Creates a new parser. More...
 
 RecursiveDescentParser (Tokenizer tokenizer, Analyzer analyzer)
 Creates a new parser. More...
 
override void AddPattern (ProductionPattern pattern)
 Adds a new production pattern to the parser. More...
 
override void Prepare ()
 Initializes the parser. More...
 
- Public Member Functions inherited from PerCederberg.Grammatica.Runtime.Parser
Tokenizer GetTokenizer ()
 Returns the tokenizer in use by this parser. More...
 
Analyzer GetAnalyzer ()
 Returns the analyzer in use by this 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

override Node ParseStart ()
 Parses the input stream and creates a parse tree. More...
 
- Protected Member Functions inherited from PerCederberg.Grammatica.Runtime.Parser
virtual Tokenizer NewTokenizer (TextReader input)
 Creates a new tokenizer for this parser. More...
 
virtual Analyzer NewAnalyzer ()
 Creates a new analyzer for this parser. More...
 
virtual Production NewProduction (ProductionPattern pattern)
 Factory method to create a new production node. More...
 

Additional Inherited Members

- Properties inherited from PerCederberg.Grammatica.Runtime.Parser
Tokenizer Tokenizer [get]
 The tokenizer property (read-only). More...
 
Analyzer Analyzer [get]
 The analyzer property (read-only). More...
 

Detailed Description

A recursive descent parser.

This parser handles LL(n) grammars, selecting the appropriate pattern to parse based on the next few tokens. The parser is more efficient the fewer look-ahead tokens that is has to consider.

Author
Per Cederberg
Version
1.5

Constructor & Destructor Documentation

PerCederberg.Grammatica.Runtime.RecursiveDescentParser.RecursiveDescentParser ( TextReader  input)
inline

Creates a new parser.

Parameters
inputthe input stream to read from
Exceptions
ParserCreationExceptionif the tokenizer couldn't be initialized correctly
Since
1.5
PerCederberg.Grammatica.Runtime.RecursiveDescentParser.RecursiveDescentParser ( TextReader  input,
Analyzer  analyzer 
)
inline

Creates a new parser.

Parameters
inputthe input stream to read from
analyzerthe analyzer callback to use
Exceptions
ParserCreationExceptionif the tokenizer couldn't be initialized correctly
Since
1.5
PerCederberg.Grammatica.Runtime.RecursiveDescentParser.RecursiveDescentParser ( Tokenizer  tokenizer)
inline

Creates a new parser.

Parameters
tokenizerthe tokenizer to use
PerCederberg.Grammatica.Runtime.RecursiveDescentParser.RecursiveDescentParser ( Tokenizer  tokenizer,
Analyzer  analyzer 
)
inline

Creates a new parser.

Parameters
tokenizerthe tokenizer to use
analyzerthe analyzer callback to use

Member Function Documentation

override void PerCederberg.Grammatica.Runtime.RecursiveDescentParser.AddPattern ( ProductionPattern  pattern)
inlinevirtual

Adds a new production pattern to the parser.

The pattern will be added last in the list. The first pattern added is assumed to be the starting point in the grammar. The pattern will be validated against the grammar type to some extent.

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

Reimplemented from PerCederberg.Grammatica.Runtime.Parser.

override Node PerCederberg.Grammatica.Runtime.RecursiveDescentParser.ParseStart ( )
inlineprotectedvirtual

Parses the input stream and creates a parse tree.

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

Implements PerCederberg.Grammatica.Runtime.Parser.

override void PerCederberg.Grammatica.Runtime.RecursiveDescentParser.Prepare ( )
inlinevirtual

Initializes the parser.

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

Exceptions
ParserCreationExceptionif the parser couldn't be initialized correctly

Reimplemented from PerCederberg.Grammatica.Runtime.Parser.


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