marf.nlp.Parsing
Class TransitionTable

java.lang.Object
  extended by marf.nlp.Parsing.TransitionTable
All Implemented Interfaces:
java.io.Serializable

public class TransitionTable
extends java.lang.Object
implements java.io.Serializable

TransitionTable class stores transition table for the main parser. Can be serialized and deserialized as a binary gzipped object.

$Id: TransitionTable.java,v 1.15 2007/12/18 21:37:56 mokhov Exp $

Since:
0.3.0.2
Version:
$Revision: 1.15 $
Author:
Serguei Mokhov
See Also:
Serialized Form

Field Summary
protected  int iEOFTerminalID
           
protected  int iStartNonTerminalID
           
protected  java.util.Vector oNonTerminals
          Vector of NonTerminals as "row-pointers" to TT.
protected  java.util.Vector oTerminals
          Vector of Terminals as "column-pointers" to TT.
protected  java.util.Vector oTT
          Transition Table (TT) is a Vector of Vectors of Objects, such as Rules and SyntaxErrors.
protected  java.lang.String strTableFile
          Prepared file name of a file with the saved table (if available).
 
Constructor Summary
TransitionTable()
          Default Constructor.
TransitionTable(java.lang.String pstrTableFileName)
          Constructor with params.
 
Method Summary
 java.lang.Object getEntryAt(NonTerminal poNonTerminal, Terminal poTerminal)
          Gets a table entry at a given position (NonTerminal, Terminal).
 java.lang.Object getEntryAt(NonTerminal poNonTerminal, Token poToken)
          Gets a table entry at a given position (NonTerminal, Token).
 Terminal getEOFTerminal()
          Allows querying for the EOF terminal.
 GrammarElement getGrammarElement(java.lang.String pstrName)
          Gets grammar element by its name (lexeme).
static java.lang.String getMARFSourceCodeRevision()
          Retrieves class' revision.
 java.util.Vector getNonTerminals()
          NonTerminals property accessor.
 NonTerminal getStartNonTerminal()
          Allows querying for the starting non-terminal.
 java.lang.String getTableFile()
          TableFile property accessor.
 java.util.Vector getTerminals()
          Terminals property accessor.
 boolean init(int piRows, int piCols)
          This is a standard attempt to initialize.
 boolean save()
          Saves current state of the TT (itself).
 boolean serialize(int piOperation)
          Serialize in text mode.
 void setEntryAt(NonTerminal poNonTerminal, Terminal poTerminal, java.lang.Object poEntry)
          Sets the entry of a table.
 void setEOFTerminalID(int piID)
          Allows setting the ID of an EOF terminal.
 void setNonTerminals(java.util.Vector poNonTerminalList)
          Sets NonTerminals property.
 void setStartNonTerminalID(int piID)
          Allows setting the ID of the Start non-terminal.
 void setTableFile(java.lang.String pstrTableFileName)
          Sets TableFile property.
 void setTerminals(java.util.Vector poTerminalList)
          Sets Terminals property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

oTT

protected java.util.Vector oTT
Transition Table (TT) is a Vector of Vectors of Objects, such as Rules and SyntaxErrors.

See Also:
Rule, SyntaxError

oNonTerminals

protected java.util.Vector oNonTerminals
Vector of NonTerminals as "row-pointers" to TT.


oTerminals

protected java.util.Vector oTerminals
Vector of Terminals as "column-pointers" to TT.


iEOFTerminalID

protected int iEOFTerminalID

iStartNonTerminalID

protected int iStartNonTerminalID

strTableFile

protected transient java.lang.String strTableFile
Prepared file name of a file with the saved table (if available). Should not be serialized.

Constructor Detail

TransitionTable

public TransitionTable()
Default Constructor.


TransitionTable

public TransitionTable(java.lang.String pstrTableFileName)
Constructor with params.

Parameters:
pstrTableFileName -
Method Detail

init

public boolean init(int piRows,
                    int piCols)
This is a standard attempt to initialize. Must be called only by GrammarCompiler or when dimensions of the table are well known.

Parameters:
piRows - rows number in the table
piCols - columns number in the table
Returns:
true if initialization was successful
See Also:
GrammarCompiler

save

public boolean save()
Saves current state of the TT (itself).

Returns:
true if serialization was successful

serialize

public boolean serialize(int piOperation)
Serialize in text mode. Loading is not implemented. TODO: migrate to MARF's dump/store mechanism.

Parameters:
piOperation - - 0 - LOAD, 1 - SAVE
Returns:
true if serialization was successful

getTerminals

public java.util.Vector getTerminals()
Terminals property accessor.

Returns:
Terminals list

getNonTerminals

public java.util.Vector getNonTerminals()
NonTerminals property accessor.

Returns:
NonTerminals list

setTerminals

public void setTerminals(java.util.Vector poTerminalList)
Sets Terminals property.

Parameters:
poTerminalList - Vector with terminals

setNonTerminals

public void setNonTerminals(java.util.Vector poNonTerminalList)
Sets NonTerminals property.

Parameters:
poNonTerminalList - Vector with non-terminals

getEntryAt

public java.lang.Object getEntryAt(NonTerminal poNonTerminal,
                                   Terminal poTerminal)
Gets a table entry at a given position (NonTerminal, Terminal).

Parameters:
poNonTerminal - non-terminal as a line number
poTerminal - terminal as a column
Returns:
the entry at the specified position

getEntryAt

public java.lang.Object getEntryAt(NonTerminal poNonTerminal,
                                   Token poToken)
Gets a table entry at a given position (NonTerminal, Token).

Parameters:
poNonTerminal - non-terminal as a line number
poToken - token corresponding to a terminal as a column
Returns:
the entry at the specified position

setEntryAt

public void setEntryAt(NonTerminal poNonTerminal,
                       Terminal poTerminal,
                       java.lang.Object poEntry)
Sets the entry of a table.

Parameters:
poNonTerminal - the non-terminal as a row index
poTerminal - the terminal as a column index
poEntry - the entry to set
Throws:
java.lang.ArrayIndexOutOfBoundsException - if either index does not exist

getTableFile

public java.lang.String getTableFile()
TableFile property accessor.

Returns:
table file name

setTableFile

public void setTableFile(java.lang.String pstrTableFileName)
Sets TableFile property.

Parameters:
pstrTableFileName - the new filename to set

getGrammarElement

public GrammarElement getGrammarElement(java.lang.String pstrName)
Gets grammar element by its name (lexeme).

Parameters:
pstrName - a name to search
Returns:
GrammarElement, if found; null, if not found

setEOFTerminalID

public void setEOFTerminalID(int piID)
Allows setting the ID of an EOF terminal.

Parameters:
piID - the ID corresponding to the end-of-file marker

setStartNonTerminalID

public void setStartNonTerminalID(int piID)
Allows setting the ID of the Start non-terminal.

Parameters:
piID - the ID corresponding to the Start non-terminal

getEOFTerminal

public Terminal getEOFTerminal()
Allows querying for the EOF terminal. If the token currently unset, attempts to locate the default by trying to lookup the "$" entry.

Returns:
the terminal object acting as an indicator of end-of-file

getStartNonTerminal

public NonTerminal getStartNonTerminal()
Allows querying for the starting non-terminal. If the token currently unset, attempts to locate the default by trying to lookup the "<prog>" entry.

Returns:
the non-terminal object acting as an indicator of the beginning of the parse

getMARFSourceCodeRevision

public static java.lang.String getMARFSourceCodeRevision()
Retrieves class' revision.

Returns:
revision string


SourceForge Logo