grammar.cfg
Class MyProduction

java.lang.Object
  extended by grammar.Production
      extended by grammar.cfg.MyProduction
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<java.lang.Object>

public class MyProduction
extends Production
implements java.lang.Comparable<java.lang.Object>

The class for productions of context-free grammars with index numbers.

Author:
XZW
See Also:
Serialized Form

Constructor Summary
MyProduction()
          Creates an empty instance of production
MyProduction(java.lang.String lhs, java.lang.String rhs)
          Creates an instance of production Tokens on the right hand side are delimited by blanks.
MyProduction(java.lang.String lhs, java.lang.String[] rhs)
          Creates an instance of production
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares this object with the specified object for order.
 int compareTokens(java.lang.String s, java.lang.String t)
          Compares two tokens.
 int[] getIndexesOfRHS()
          Returns the indices of the right hand side
 int getIndexOfLHS()
          Returns the index of the left hand side
 int[] getRHSVariableIndexes()
          Returns the indices of variables at the right hand side
 int getRHSVariableNumber()
          Returns the number of variables at the right hand side
 void setIndex(java.lang.String[] terminals, java.lang.String[] variables)
          Sets the indeies of the tokens at the production w.r.t.
 void setLHS(java.lang.String lhs)
          Sets the left hand side
 void setRHS(java.lang.String rhs)
          Sets the right hand side (in string format)
 
Methods inherited from class grammar.Production
equals, getLHS, getRHS, getRHSTerminals, getRHSTokenNumber, getRHSTokens, getRHSVariables, getTerminals, getVariables, hashCode, setRHSTokens, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MyProduction

public MyProduction()
Creates an empty instance of production


MyProduction

public MyProduction(java.lang.String lhs,
                    java.lang.String rhs)
Creates an instance of production Tokens on the right hand side are delimited by blanks.

Parameters:
lhs - the left hand side of the production rule, in string format.
rhs - the right hand side of the production rule, in string format.

MyProduction

public MyProduction(java.lang.String lhs,
                    java.lang.String[] rhs)
Creates an instance of production

Parameters:
lhs - the left hand side of the production rule, in string format.
rhs - the right hand side of the production rule, in tokens(string[]) format.
Method Detail

setLHS

public void setLHS(java.lang.String lhs)
Description copied from class: Production
Sets the left hand side

Overrides:
setLHS in class Production
Parameters:
lhs - the left hand side to set

setRHS

public void setRHS(java.lang.String rhs)
Description copied from class: Production
Sets the right hand side (in string format)

Overrides:
setRHS in class Production
Parameters:
rhs - the right hand side to set

setIndex

public void setIndex(java.lang.String[] terminals,
                     java.lang.String[] variables)
Sets the indeies of the tokens at the production w.r.t. terminals and variables

Parameters:
terminals - the correlative terminals
variables - the correlative variables
Throws:
java.lang.IllegalArgumentException - if some token is in neither terminals nor variables.

getIndexOfLHS

public int getIndexOfLHS()
Returns the index of the left hand side

Returns:
the index of the left hand side

getIndexesOfRHS

public int[] getIndexesOfRHS()
Returns the indices of the right hand side

Returns:
the indices of the right hand side

getRHSVariableIndexes

public int[] getRHSVariableIndexes()
Returns the indices of variables at the right hand side

Returns:
the indices of variables at the right hand side

getRHSVariableNumber

public int getRHSVariableNumber()
Returns the number of variables at the right hand side

Returns:
the number of variables at the right hand side
Throws:
java.lang.Exception - if the production is not indexed.

compareTo

public int compareTo(java.lang.Object o)
Compares this object with the specified object for order. Terminals and variables are sorted by lexicographic respectively. Terminals is less than variables. Terminal productions are less than variable productions. If the LHS of a production is less than that of another, than the production is less than another. If the LHSes are the same, than compare their RHSes.

Specified by:
compareTo in interface java.lang.Comparable<java.lang.Object>
Parameters:
o - the specified object
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object

compareTokens

public int compareTokens(java.lang.String s,
                         java.lang.String t)
Compares two tokens.

Parameters:
s - the first token
t - the second token
Returns:
a negative integer, zero, or a positive integer as the first token is less than, equal to, or greater than the second token