tribble.io
Interface Lr1ParserTablesI


public interface Lr1ParserTablesI

Generic LR(1) parser tables interface.

This interface is used to implement any kind of class containing state transition tables for an LR(k) parser DFA. (Such a parsing machine should implement the ParserI interface.)

Since:
2001-08-11
Version:
$Revision: 1.1 $ $Date: 2001/08/11 20:53:03 $
Author:
David R. Tribble, david@tribble.com.
Copyright ©2001-2002 by David R. Tribble, all rights reserved.
Permission is granted to freely use and distribute this source code provided that the original copyright and authorship notices remain intact.
See Also:
ParserI, Lr1ParserI

Field Summary
static java.lang.String REV
          Revision information.
 
Method Summary
 int action(int state, int laTok)
          Retrieves the action to perform on a transition from a given state on a given terminal (lookahead) symbol.
 java.lang.String getNonterminalName(int n)
          Retrieves the name of a nonterminal symbol (LHS) of the grammar.
 int getRhslength(int rule)
          Retrieves the length of (i.e., the number of symbols in) the right-hand side (RHS) of a production rule of the grammar.
 java.lang.String getRuleText(int rule)
          Retrieves the text of production rule of the grammar.
 java.lang.String getTerminalName(int n)
          Retrieves the name of a terminal symbol (token) of the grammar.
 int goTo(int state, int sym)
          Retrieves the next state to transition to (i.e., the goto state) after a reduce action.
 java.lang.Object reduce(int rule, java.lang.Object[] vStack, int rhsIndex)
          Execute an action code block associated with the reduction of a production rule of the grammar.
 

Field Detail

REV

static final java.lang.String REV
Revision information.

See Also:
Constant Field Values
Method Detail

getTerminalName

java.lang.String getTerminalName(int n)
Retrieves the name of a terminal symbol (token) of the grammar.

Parameters:
n - The serial number of the terminal symbol.
Returns:
The name of a terminal symbol.
Since:
1.1, 2001-08-11

getNonterminalName

java.lang.String getNonterminalName(int n)
Retrieves the name of a nonterminal symbol (LHS) of the grammar.

Parameters:
n - The serial number of the nonterminal symbol.
Returns:
The name of a nonterminal symbol.
Since:
1.1, 2001-08-11

getRuleText

java.lang.String getRuleText(int rule)
Retrieves the text of production rule of the grammar.

Parameters:
rule - The rule number.
Returns:
The text of a production rule, which resembles the contents of the grammar definition source file.
Since:
1.1, 2001-08-11

getRhslength

int getRhslength(int rule)
Retrieves the length of (i.e., the number of symbols in) the right-hand side (RHS) of a production rule of the grammar.

Parameters:
rule - The rule number.
Returns:
The number of symbols in the RHS of the production rule.
Since:
1.1, 2001-08-11

action

int action(int state,
           int laTok)
Retrieves the action to perform on a transition from a given state on a given terminal (lookahead) symbol.

Parameters:
state - The state number to transition from.
laTok - The token code of the lookahead terminal symbol to transition on.
Returns:
A positive number representing the next state number to transition to after a shift action; or a negative number representing the production rule number of a reduce action; or zero representing an accept action, indicating that the input sentence (i.e., sequence of input tokens) is a valid sentence of the grammar and parsing should terminate successfully.
Since:
1.1, 2001-08-11

goTo

int goTo(int state,
         int sym)
Retrieves the next state to transition to (i.e., the goto state) after a reduce action.

Parameters:
state - The state number exposed on the top of the push-down DFA stack after the reduce action has occurred.
sym - The nonterminal LHS symbol of the rule that was reduced.
Returns:
The next (goto) state number.
Since:
1.1, 2001-08-11

reduce

java.lang.Object reduce(int rule,
                        java.lang.Object[] vStack,
                        int rhsIndex)
                        throws java.lang.Exception
Execute an action code block associated with the reduction of a production rule of the grammar.

Parameters:
rule - The rule number to reduce.
vStack - The parser's value stack.
rhsIndex - The index into the parser's value stack of the leftmost symbol of the RHS of the rule to reduce by.
Returns:
The resulting value of the RHS of the reduced rule, which is to be pushed onto the top of the parser's push-down value stack, replacing the zero or more RHS symbols previously on the top of the stack.
Throws:
java.lang.Exception - Thrown if a semantic error occurs and parsing should terminate unsuccessfully.
Since:
1.1, 2001-08-11