|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--geneseo.cs.compiler.LRParser
Represents general LR parsers. This class provides those features that all LR parsers have in common; subclasses for parsers for individual languages should provide language-specific features. This class is therefore an abstract base class that can be extended to provide complete parsers. In particular, this class provides a "parse" method, while subclasses have to provide the action and goto tables that drive it. Both tables are arrays of integers -- in the case of the goto table, these integers are simply parser state numbers. In the case of the action table, they also encode the kind of action, as follows:
Constructor Summary | |
protected |
LRParser(int[][] actions,
int[][] go)
Initialize an LR parser from its action and goto tables. |
Method Summary | |
protected static int |
a()
Construct a parse table entry for the "accept" action. |
protected static int |
e(int code)
Construct a parse table entry for an "error" action. |
protected abstract void |
error(int code,
TokenSeq input,
java.util.Stack parseStack)
Handle an error in an LR parser. |
protected abstract int |
leftSide(int production)
Figures out the non-terminal on the left side of a production, given the production number. |
ParseNode |
parse(TokenSeq tokens)
Parse a sequence of tokens. |
java.lang.Object |
popSymbol()
Remove and return the top-most symbol from the parser's stack. |
protected static int |
r(int prod)
Construct a parse table entry for a "reduce" action. |
protected abstract ParseNode |
reduce(int production)
Reduce by a specified production during a parse. |
protected static int |
s(int state)
Construct a parse table entry for a "shift" action. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
protected LRParser(int[][] actions, int[][] go)
actions
- The action table.go
- The goto table.Method Detail |
protected static int s(int state)
state
- The state to enter after shifting.protected static int r(int prod)
prod
- The production number to reduce by.protected static int e(int code)
code
- A code for the specific error.protected static int a()
public ParseNode parse(TokenSeq tokens) throws CompilerException
parse
in interface Parser
tokens
- The token sequence to parse.CompilerException
- If the token sequence doesn't represent
a legal input to this parser.public java.lang.Object popSymbol() throws CompilerException
CompilerException
- If there is no symbol on the stack.protected abstract ParseNode reduce(int production) throws CompilerException
production
- The number of the production by which to reduce.CompilerException
- If the parse stack doesn't have enough items
on it to complete the reduction, or if the production number is invalid.protected abstract void error(int code, TokenSeq input, java.util.Stack parseStack) throws CompilerException
code
- The error code from the parse table.input
- The sequence of tokens being processed when the error was detected.parseStack
- The parser's stack at the time of the error.CompilerException
- If the error cannot be repaired.protected abstract int leftSide(int production)
production
- The production number.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |