|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.percederberg.grammatica.parser.Parser
A base parser class. This class provides the standard parser interface, as well as token handling.
Constructor Summary | |
protected |
Parser(Tokenizer tokenizer)
Creates a new parser. |
protected |
Parser(Tokenizer tokenizer,
Analyzer analyzer)
Creates a new parser. |
Method Summary | |
protected void |
addNode(Production node,
Node child)
Handles the parser adding a child node to a production. |
void |
addPattern(ProductionPattern pattern)
Adds a new production pattern to the parser. |
protected void |
enterNode(Node node)
Handles the parser entering a production. |
protected Node |
exitNode(Node node)
Handles the parser leaving a production. |
protected ProductionPattern |
getPattern(int id)
Returns the production pattern with the specified id. |
protected java.util.Collection |
getPatterns()
Returns the unordered set of production patterns. |
protected ProductionPattern |
getStartPattern()
Returns the production pattern for the starting production. |
protected Token |
nextToken()
Reads and consumes the next token in the queue. |
protected Token |
nextToken(int id)
Reads and consumes the next token in the queue. |
abstract Node |
parse()
Parses the token stream and returns a parse tree. |
protected Token |
peekToken(int steps)
Returns a token from the queue. |
void |
prepare()
Initializes the parser. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
protected Parser(Tokenizer tokenizer)
tokenizer
- the tokenizer to useprotected Parser(Tokenizer tokenizer, Analyzer analyzer)
tokenizer
- the tokenizer to useanalyzer
- the analyzer callback to useMethod Detail |
public void addPattern(ProductionPattern pattern) throws ParserCreationException
pattern
- the pattern to add
ParserCreationException
- if the pattern couldn't be
added correctly to the parserpublic void prepare() throws ParserCreationException
ParserCreationException
- if the parser couldn't be
initialized correctlypublic abstract Node parse() throws ParserCreationException, ParseException
ParserCreationException
- if the parser couldn't be
initialized correctly
ParseException
- if the input couldn't be parsed
correctlyprepare()
protected ProductionPattern getPattern(int id)
id
- the production pattern id
protected ProductionPattern getStartPattern()
protected java.util.Collection getPatterns()
protected void enterNode(Node node) throws ParseException
node
- the parse tree node
ParseException
- if the node couldn't be handled
correctlyprotected Node exitNode(Node node) throws ParseException
node
- the parse tree node
ParseException
- if the node couldn't be handled
correctlyprotected void addNode(Production node, Node child) throws ParseException
node
- the parent parse tree nodechild
- the child parse tree node, or null
ParseException
- if the node couldn't be handled
correctlyprotected Token nextToken() throws ParseException
ParseException
- if the input stream couldn't be read or
parsed correctlyprotected Token nextToken(int id) throws ParseException
id
- the expected token id
ParseException
- if the input stream couldn't be parsed
correctly, or if the token wasn't expectedprotected Token peekToken(int steps) throws ParseException
steps
- the token queue number, zero (0) for first
ParseException
- if the input stream couldn't be read or
parsed correctly
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |