net.percederberg.grammatica.parser
Class Parser

java.lang.Object
  |
  +--net.percederberg.grammatica.parser.Parser
Direct Known Subclasses:
RecursiveDescentParser

public abstract class Parser
extends java.lang.Object

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


Method Summary
 void addPattern(ProductionPattern pattern)
          Adds a new production pattern to the parser.
abstract  Node parse()
          Parses the token stream and returns a parse tree.
 void prepare()
          Initializes the parser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addPattern

public void addPattern(ProductionPattern pattern)
                throws ParserCreationException
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:
pattern - the pattern to add
Throws:
ParserCreationException - if the pattern couldn't be added correctly to the parser

prepare

public void prepare()
             throws ParserCreationException
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.

Throws:
ParserCreationException - if the parser couldn't be initialized correctly

parse

public abstract Node parse()
                    throws ParserCreationException,
                           ParseException
Parses the token stream and returns a parse tree. This method will call prepare() if not previously called.

Returns:
the parse tree
Throws:
ParserCreationException - if the parser couldn't be initialized correctly
ParseException - if the input couldn't be parsed correctly
See Also:
prepare()