net.sourceforge.chaperon.process
Class ParserAutomaton

java.lang.Object
  extended by net.sourceforge.chaperon.process.ParserAutomaton
All Implemented Interfaces:
java.io.Serializable

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

This class represents a parser automaton, which holds all states and transition, which are used by the the parser processor.

Version:
CVS $Id: ParserAutomaton.java,v 1.10 2004/01/19 17:58:52 benedikta Exp $
Author:
Stephan Michels
See Also:
Serialized Form

Constructor Summary
ParserAutomaton(int tsymbolcount, int ntsymbolcount, int productioncount, int errorcount, int statecount)
          Constructs a empty parser automaton
 
Method Summary
 int getErrorCount()
          Return the count of errors.
 java.lang.String getErrorMessage(int index)
          Returns the message for an error.
 int getErrorTransition(int state)
          Return index of the error.
 int getErrorTransition(int state, int tsymbol)
          Return for a given error action the error message
 java.lang.String getNonterminal(int index)
          Returns the name of a nonterminal symbol.
 int getNonterminalCount()
          Returns the count of nonterminal symbols.
 int getProductionCount()
          Return the count of productions.
 int getProductionLength(int index)
          Return the length of a production.
 int getProductionSymbol(int index)
          Return the symbol of a production.
 int getReduceProduction(int state)
          Return the production, which should be reduced.
 int getReduceProduction(int state, int tsymbol)
          Return for a given reduce action the production, which should be reduced.
 int getShiftTransition(int state, int tsymbol)
          Returns the transition for a given state and terminal symbol.
 int getStateCount()
          Returns the count of states.
 java.lang.String getTerminal(int index)
          Returns the name of a terminal symbol.
 int getTerminalCount()
          Returns the count of terminal symbols.
 int getTransition(int state, int ntsymbol)
          Returns the transition for a given state and nonterminal symbol.
 boolean hasErrorTransition(int state)
           
 boolean hasErrorTransition(int state, int tsymbol)
           
 boolean isAcceptAction(int state)
          If is a accept action.
 boolean isErrorAction(int state)
          If is a error action.
 boolean isErrorAction(int state, int tsymbol)
          If is an error action
 boolean isReduceAction(int state)
          If is a reduce action.
 boolean isReduceAction(int state, int tsymbol)
          If is a reduce action
 boolean isShiftAction(int state, int tsymbol)
          If is a shift action
 void setAcceptAction(int state, int production)
          Sets a accept action for a given state and terminal symbol
 void setErrorAction(int state, int nextstate)
          Sets a error action for a given state and terminal symbol
 void setErrorAction(int state, int tsymbol, int nextstate)
          Sets a error action for a given state and terminal symbol
 void setErrorMessage(int index, java.lang.String message)
          Sets the message for an error.
 void setNonterminal(int index, java.lang.String symbol)
          Sets the name of a nonterminal symbol.
 void setProductionLength(int index, int length)
          Set the length of a production.
 void setProductionSymbol(int index, int symbol)
          Sets the symbol for a production
 void setReduceAction(int state, int production)
          Set a reduce action for a given state and for the end of the file.
 void setReduceAction(int state, int tsymbol, int production)
          Sets a reduce action for a given state and terminal symbol
 void setShiftAction(int state, int tsymbol, int nextstate)
          Sets a shift action for a given state and terminal symbol
 void setTerminal(int index, java.lang.String symbol)
          Sets the name of a terminal symbol.
 void setTransition(int state, int ntsymbol, int nextstate)
          Sets transition for a given state and nonterminal symbol.
 java.lang.String toString()
          Return a string representation of the automaton.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ParserAutomaton

public ParserAutomaton(int tsymbolcount,
                       int ntsymbolcount,
                       int productioncount,
                       int errorcount,
                       int statecount)
Constructs a empty parser automaton

Parameters:
tsymbolcount - Count of terminal symbols.
ntsymbolcount - Count of nonterminal symbols.
productioncount - Count of productions.
errorcount - Count of error types.
statecount - Count of states.
Method Detail

setTerminal

public void setTerminal(int index,
                        java.lang.String symbol)
Sets the name of a terminal symbol.

Parameters:
index - Index of the symbol.
symbol - Name of the symbol.

getTerminal

public java.lang.String getTerminal(int index)
Returns the name of a terminal symbol.

Parameters:
index - Index of the symbol.
Returns:
Name of the symbol.

getTerminalCount

public int getTerminalCount()
Returns the count of terminal symbols.

Returns:
Count of terminal symbols.

setNonterminal

public void setNonterminal(int index,
                           java.lang.String symbol)
Sets the name of a nonterminal symbol.

Parameters:
index - Index of the symbol.
symbol - Name of the symbol.

getNonterminal

public java.lang.String getNonterminal(int index)
Returns the name of a nonterminal symbol.

Parameters:
index - Index of the symbol.
Returns:
Name of the symbol.

getNonterminalCount

public int getNonterminalCount()
Returns the count of nonterminal symbols.

Returns:
Count of nonterminal symbols.

setProductionSymbol

public void setProductionSymbol(int index,
                                int symbol)
Sets the symbol for a production

Parameters:
index - Index of the production
symbolindex - Index of the nonterminal symbol

getProductionSymbol

public int getProductionSymbol(int index)
Return the symbol of a production.

Parameters:
index - Index of the production.
Returns:
Index of the nonterminal symbol

setProductionLength

public void setProductionLength(int index,
                                int length)
Set the length of a production.

Parameters:
index - Index of the production.
length - Length of the production.

getProductionLength

public int getProductionLength(int index)
Return the length of a production.

Parameters:
index - Index of a production.
Returns:
Length of the production.

getProductionCount

public int getProductionCount()
Return the count of productions.

Returns:
Count of productions.

setErrorMessage

public void setErrorMessage(int index,
                            java.lang.String message)
Sets the message for an error.

Parameters:
index - Index of the error.
message - Message of the error.

getErrorMessage

public java.lang.String getErrorMessage(int index)
Returns the message for an error.

Parameters:
index - Index of the error.
Returns:
Message of the error.

getErrorCount

public int getErrorCount()
Return the count of errors.

Returns:
Count of errors.

setErrorAction

public void setErrorAction(int state,
                           int tsymbol,
                           int nextstate)
Sets a error action for a given state and terminal symbol

Parameters:
state - Index of the state
tsymbol - Index of the terminal symbol
nextstate - Destination state

setErrorAction

public void setErrorAction(int state,
                           int nextstate)
Sets a error action for a given state and terminal symbol

Parameters:
state - Index of the state
nextstate - Destination state

setShiftAction

public void setShiftAction(int state,
                           int tsymbol,
                           int nextstate)
Sets a shift action for a given state and terminal symbol

Parameters:
state - Index of the state
tsymbol - Index of the terminal symbol
nextstate - Destination state

setReduceAction

public void setReduceAction(int state,
                            int tsymbol,
                            int production)
Sets a reduce action for a given state and terminal symbol

Parameters:
state - Index of the state
tsymbol - Index of the terminal symbol
production - Index of the production, which should be reduced

setReduceAction

public void setReduceAction(int state,
                            int production)
Set a reduce action for a given state and for the end of the file.

Parameters:
state - Index of state.
production - Production, which shoudl be reduced.

setAcceptAction

public void setAcceptAction(int state,
                            int production)
Sets a accept action for a given state and terminal symbol

Parameters:
state - Index of the state
production - Index of the production, which should be reduced

isErrorAction

public boolean isErrorAction(int state,
                             int tsymbol)
If is an error action

Parameters:
state - Index of the state
tsymbol - Index of the terminal symbol
Returns:
True, if it is a error action

isErrorAction

public boolean isErrorAction(int state)
If is a error action.

Parameters:
state - Index of the state
Returns:
True, if is an error action

isShiftAction

public boolean isShiftAction(int state,
                             int tsymbol)
If is a shift action

Parameters:
state - Index of the state
tsymbol - Index of the terminal symbol
Returns:
True, if is a shift action

isReduceAction

public boolean isReduceAction(int state,
                              int tsymbol)
If is a reduce action

Parameters:
state - Index of the state
tsymbol - Index of the terminal symbol
Returns:
True, if is a reduce action

isReduceAction

public boolean isReduceAction(int state)
If is a reduce action.

Parameters:
state - Index of the state.
Returns:
True, if is a reduce action.

isAcceptAction

public boolean isAcceptAction(int state)
If is a accept action.

Parameters:
state - Index of the state
Returns:
True, if is a accept action

getShiftTransition

public int getShiftTransition(int state,
                              int tsymbol)
Returns the transition for a given state and terminal symbol.

Parameters:
state - Index of the state
tsymbol - Index of the terminal symbol.
Returns:
Index of destination state

getReduceProduction

public int getReduceProduction(int state,
                               int tsymbol)
Return for a given reduce action the production, which should be reduced.

Parameters:
state - Index of the state
tsymbol - Index of the terminal symbol
Returns:
Index of the production, which should be reduced

getReduceProduction

public int getReduceProduction(int state)
Return the production, which should be reduced.

Parameters:
state - Index of the state.
Returns:
Index of the production.

getErrorTransition

public int getErrorTransition(int state,
                              int tsymbol)
Return for a given error action the error message

Parameters:
state - Index of the state
tsymbol - Index of the terminal symbol
Returns:
Index of the state, to continue processing

hasErrorTransition

public boolean hasErrorTransition(int state,
                                  int tsymbol)

getErrorTransition

public int getErrorTransition(int state)
Return index of the error.

Parameters:
state - Index of state.
Returns:
Index of error.

hasErrorTransition

public boolean hasErrorTransition(int state)

setTransition

public void setTransition(int state,
                          int ntsymbol,
                          int nextstate)
Sets transition for a given state and nonterminal symbol.

Parameters:
state - Index of the state.
ntsymbol - Index of the nonterminal symbol.
nextstate - Index of destination state.

getTransition

public int getTransition(int state,
                         int ntsymbol)
Returns the transition for a given state and nonterminal symbol.

Parameters:
state - Index of the state.
ntsymbol - Index of the nonterminal symbol.
Returns:
Index of destination state.

getStateCount

public int getStateCount()
Returns the count of states.

Returns:
Count of states.

toString

public java.lang.String toString()
Return a string representation of the automaton.

Overrides:
toString in class java.lang.Object
Returns:
String representation of the automaton.


Copyright ? 2003 Chaperon project. All Rights Reserved.