org.inxar.syntacs.translator.lr
Interface LRTranslatorGrammar

All Superinterfaces:
Serializable, TranslatorGrammar
All Known Implementing Classes:
StandardLRTranslatorGrammar, ProxyLRTranslatorGrammar, RegexpGrammar, SyntacsGrammar, AbbGrammar, EtfGrammar, SccGrammar

public interface LRTranslatorGrammar
extends TranslatorGrammar

The LRTranslatorGrammar interface describes the symbolic components of a grammar, relevant to LR parsing algorithms. The LRTranslatorGrammar contains all the structural information of the original grammar.


Field Summary
static int ACTION_PEEK
          Constant returned by getContextAction(int, int) to signal a context stack peek, meaning "change to the context given at the top of stack".
static int ACTION_PEEL
          Constant returned by getContextAction(int, int) to signal a context stack peel, meaning "execute ACTION_POP until the top of the stack is equal to the return value of getContextRegister(int, int).
static int ACTION_POP
          Constant returned by getContextAction(int, int) to signal a context stack pop, meaning "change back to the previous stack context".
static int ACTION_POUNCE
          Constant returned by getContextAction(int, int) to signal a context stack pounce, meaning "execute an ACTION_POP, then an ACTION_PUSH".
static int ACTION_PUSH
          Constant returned by getContextAction(int, int) to signal a context stack push, meaning "shift to the context having the ID given by the return value of getContextRegister(int, int)".
static int UNDEFINED
          Constant used to indicate general undefined conditions.
static int UNDEFINED_CONTEXT
          Constant used to indicate the non-definition of a particular context.
static int UNDEFINED_NONTERMINAL
          Constant used to indicate the non-definition of a particular nonterminal.
static int UNDEFINED_PRODUCTION
          Constant used to indicate the non-definition of a particular production.
static int UNDEFINED_SYMBOL
          Constant used to indicate the non-definition of a particular grammar symbol (where a grammar symbol defined as a terminal or a nonterminal).
static int UNDEFINED_TERMINAL
          Constant used to indicate the non-definition of a particular terminal.
 
Method Summary
 String getContext(int ID)
          Returns the name of the context having the given ID or null if no such ID is known.
 int getContextAction(int contextID, int symbolID)
          Returns the action defined for the given grammar symbol in the given context as one of the ACTION_XXX constants in this interface.
 int getContextRegister(int contextID, int symbolID)
          Returns an integer stored at the value of the given contextID and symbolID.
 IntArray getContexts()
          Returns the list of context ID numbers as an IntArray.
 IntArray getContextTerminals(int contextID)
          Returns a list of terminals defined within the context having the given ID or null if no such ID is known.
 int getGoalNonTerminal()
          Returns the ID of the goal symbol (a nonterminal) or UNDEFINED_NONTERMINAL is no such goal symbol has been set.
 String getNonTerminal(int ID)
          Returns the name of the nonterminal having the given ID or null if no such ID is known.
 IntArray getNonTerminals()
          Returns the list of nonterminal ID numbers as an IntArray.
 String getProduction(int ID)
          Returns the name of the production having the given ID or null if no such ID is known.
 int getProductionLength(int productionID)
          Returns the length of the list of grammar symbols of the right-hand-side of the production having the given ID or UNDEFINED_PRODUCTION if no such ID is known.
 int getProductionNonTerminal(int productionID)
          Returns the ID of the nonterminal obtained by reduction of the given productionID or UNDEFINED_PRODUCTION if no such production is known.
 IntArray getProductions()
          Returns the list of production ID numbers as an IntArray.
 IntArray getProductionSymbols(int productionID)
          Returns the list of grammar symbols of the right-hand-side of the production having the given ID as an IntArray or null if no such ID is known.
 int getStartContext()
          Returns the ID of the initial context.
 String getTerminal(int ID)
          Returns the name of the terminal having the given ID or null if no such ID is known.
 IntArray getTerminalContexts(int terminalID)
          Returns a list of contexts in which this terminal is defined.
 Object getTerminalRegexp(int terminalID)
          Returns the regular expression String for the terminal having the given ID or null if no such ID is known.
 IntArray getTerminals()
          Returns the list of terminal ID numbers as an IntArray.
 
Methods inherited from interface org.inxar.syntacs.translator.TranslatorGrammar
getName, getVersion, newTranslator, newTranslator
 

Field Detail

ACTION_PEEK

public static final int ACTION_PEEK
Constant returned by getContextAction(int, int) to signal a context stack peek, meaning "change to the context given at the top of stack". This effectively means "no change" and is the most common context stack action.

ACTION_POP

public static final int ACTION_POP
Constant returned by getContextAction(int, int) to signal a context stack pop, meaning "change back to the previous stack context".

ACTION_PUSH

public static final int ACTION_PUSH
Constant returned by getContextAction(int, int) to signal a context stack push, meaning "shift to the context having the ID given by the return value of getContextRegister(int, int)".

ACTION_PEEL

public static final int ACTION_PEEL
Constant returned by getContextAction(int, int) to signal a context stack peel, meaning "execute ACTION_POP until the top of the stack is equal to the return value of getContextRegister(int, int). If the stack becomes empty, PUSH the register value." This has the effect of removing plates from the buffet table until the top plate is blue, or if all plates are gone, put a single blue plate on the table. This action is useful during error recovery synchronization routines where the stack should be put in a known and minimal state.

ACTION_POUNCE

public static final int ACTION_POUNCE
Constant returned by getContextAction(int, int) to signal a context stack pounce, meaning "execute an ACTION_POP, then an ACTION_PUSH". The name "pounce" is derived from two points: (1) stack instructions starting with "p" have a certain ring to them, (2) the action of pouncing resembles something that goes down (a crouching tiger, perhaps) and then goes back up. The effect is ACTION_POUNCE is to change the context without having to POP it later. Exclusive use of ACTION_POUNCE makes the context stack appear like a single scalar value as demonstrated by other lexers having start states (such as flex).

UNDEFINED

public static final int UNDEFINED
Constant used to indicate general undefined conditions.

UNDEFINED_CONTEXT

public static final int UNDEFINED_CONTEXT
Constant used to indicate the non-definition of a particular context.

UNDEFINED_TERMINAL

public static final int UNDEFINED_TERMINAL
Constant used to indicate the non-definition of a particular terminal.

UNDEFINED_NONTERMINAL

public static final int UNDEFINED_NONTERMINAL
Constant used to indicate the non-definition of a particular nonterminal.

UNDEFINED_PRODUCTION

public static final int UNDEFINED_PRODUCTION
Constant used to indicate the non-definition of a particular production.

UNDEFINED_SYMBOL

public static final int UNDEFINED_SYMBOL
Constant used to indicate the non-definition of a particular grammar symbol (where a grammar symbol defined as a terminal or a nonterminal).
Method Detail

getContexts

public IntArray getContexts()
Returns the list of context ID numbers as an IntArray.

getTerminals

public IntArray getTerminals()
Returns the list of terminal ID numbers as an IntArray.

getNonTerminals

public IntArray getNonTerminals()
Returns the list of nonterminal ID numbers as an IntArray.

getProductions

public IntArray getProductions()
Returns the list of production ID numbers as an IntArray.

getContext

public String getContext(int ID)
Returns the name of the context having the given ID or null if no such ID is known.

getTerminal

public String getTerminal(int ID)
Returns the name of the terminal having the given ID or null if no such ID is known.

getNonTerminal

public String getNonTerminal(int ID)
Returns the name of the nonterminal having the given ID or null if no such ID is known.

getProduction

public String getProduction(int ID)
Returns the name of the production having the given ID or null if no such ID is known. The String has the format "nonterminal: sym1 sym2 sym3" such that the nonterminal name is the first part of the string, followed by a colon, followed by a space delimited list of symbols.

getContextTerminals

public IntArray getContextTerminals(int contextID)
Returns a list of terminals defined within the context having the given ID or null if no such ID is known.

getContextAction

public int getContextAction(int contextID,
                            int symbolID)
Returns the action defined for the given grammar symbol in the given context as one of the ACTION_XXX constants in this interface. If the contextID or symbolID is not known, UNDEFINED_CONTEXT or UNDEFINED_SYMBOL will be returned. Note: If UNDEFINED_SYMBOL is returned the ID may still be a valid terminal or nonterminal, but it not a member of the given context.

getContextRegister

public int getContextRegister(int contextID,
                              int symbolID)
Returns an integer stored at the value of the given contextID and symbolID. This is used in conjunction with getContextAction(int, int) such that the second member in the tuple (action, register) is returned. If the contextID or symbolID is not known, UNDEFINED_CONTEXT or UNDEFINED_SYMBOL will be returned.

getStartContext

public int getStartContext()
Returns the ID of the initial context.

getTerminalContexts

public IntArray getTerminalContexts(int terminalID)
Returns a list of contexts in which this terminal is defined.

getTerminalRegexp

public Object getTerminalRegexp(int terminalID)
Returns the regular expression String for the terminal having the given ID or null if no such ID is known. If the terminal ID is valid but no definition has been provided for that terminal, the empty string "" will be returned.

getProductionNonTerminal

public int getProductionNonTerminal(int productionID)
Returns the ID of the nonterminal obtained by reduction of the given productionID or UNDEFINED_PRODUCTION if no such production is known.

getProductionSymbols

public IntArray getProductionSymbols(int productionID)
Returns the list of grammar symbols of the right-hand-side of the production having the given ID as an IntArray or null if no such ID is known.

getProductionLength

public int getProductionLength(int productionID)
Returns the length of the list of grammar symbols of the right-hand-side of the production having the given ID or UNDEFINED_PRODUCTION if no such ID is known.

getGoalNonTerminal

public int getGoalNonTerminal()
Returns the ID of the goal symbol (a nonterminal) or UNDEFINED_NONTERMINAL is no such goal symbol has been set.