PerCederberg.Grammatica.Parser
Class RecursiveDescentParser
System.Object
|
+--Parser
|
+--RecursiveDescentParser
in RecursiveDescentParser.cs
- class RecursiveDescentParser
- extends Parser
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.
Method Summary |
override void |
AddPattern( ProductionPattern pattern )
Adds a new production pattern to the parser. |
protected override Node |
ParseStart()
Parses the input stream and creates a parse tree. |
override void |
Prepare()
Initializes the parser. |
Methods inherited from class Parser |
SetInitialized, AddPattern, Prepare, Parse, ParseStart, AddError, GetPattern, GetStartPattern, GetPatterns, EnterNode, ExitNode, AddNode, NextToken, NextToken, PeekToken, ToString, GetTokenDescription |
RecursiveDescentParser
public RecursiveDescentParser( Tokenizer tokenizer );
- Creates a new parser.
- Parameters:
tokenizer
- the tokenizer to use
RecursiveDescentParser
public RecursiveDescentParser( Tokenizer tokenizer, Analyzer analyzer );
- Creates a new parser.
- Parameters:
tokenizer
- the tokenizer to use
analyzer
- the analyzer callback to use
AddPattern
public override void AddPattern( ProductionPattern pattern );
- 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:
pattern
- the pattern to add
- Throws:
ParserCreationException
- if the pattern couldn't be
added correctly to the parser
ParseStart
protected override Node ParseStart();
- Parses the input stream and creates a parse tree.
- Returns:
- the parse tree
- Throws:
ParseException
- if the input couldn't be parsed
correctly
Prepare
public override void Prepare();
- 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.
- Throws:
ParserCreationException
- if the parser couldn't be
initialized correctly