grammar
Class Grammar

java.lang.Object
  extended by grammar.Grammar
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
MyGrammar

public abstract class Grammar
extends java.lang.Object
implements java.io.Serializable

The abstract class for general grammars.

Author:
XZW
See Also:
Serialized Form

Constructor Summary
Grammar()
          Creates an instance of grammar.
 
Method Summary
 void addProduction(Production production)
          Adds a production to the set of productions in the grammar.
 void addProductions(Production[] productions)
          Adds productions to grammar
abstract  void checkProduction(Production production)
          Checks whether a production is invalid
 boolean equals(java.lang.Object obj)
           
 Production[] getProductions()
          Returns all productions in the grammar.
 int getProductionsNumber()
          Returns the productions' number in the grammar.
 java.lang.String getStartVariable()
          Returns the start variable.
 java.lang.String[] getTerminals()
          Returns all terminals in the grammar.
 int getTerminalsNumber()
          Returns the terminals' number in the grammar.
 java.lang.String[] getVariables()
          Returns all variables in the grammar.
 int getVariablesNumber()
          Returns the variables' number in the grammar.
 int hashCode()
           
 boolean isEmpty()
          Returns true if the grammar is empty.
 java.lang.String reachability()
          Finds out the unreachable variables.
 void setStartVariable(java.lang.String variable)
          Sets the start variable
 java.lang.String toString()
          Returns a string representation of the grammar object,
 java.lang.String usefulness()
          Finds out the useless variables.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Grammar

public Grammar()
Creates an instance of grammar. The created instance has no productions, no terminals, no variables, and specifically no start variable.

Method Detail

isEmpty

public boolean isEmpty()
Returns true if the grammar is empty.

Returns:
true if the grammar is empty.

getStartVariable

public java.lang.String getStartVariable()
Returns the start variable.

Returns:
the start variable.

setStartVariable

public void setStartVariable(java.lang.String variable)
Sets the start variable

Parameters:
variable - the start variable to set

getTerminals

public java.lang.String[] getTerminals()
Returns all terminals in the grammar.

Returns:
all terminals in the grammar.

getTerminalsNumber

public int getTerminalsNumber()
Returns the terminals' number in the grammar.

Returns:
the terminals' number in the grammar.

getVariables

public java.lang.String[] getVariables()
Returns all variables in the grammar.

Returns:
all variables in the grammar.

getVariablesNumber

public int getVariablesNumber()
Returns the variables' number in the grammar.

Returns:
the variables' number in the grammar.

checkProduction

public abstract void checkProduction(Production production)
Checks whether a production is invalid

Parameters:
production - the production to check
Throws:
java.lang.IllegalArgumentException - if the production is in some way faulty

addProduction

public void addProduction(Production production)
Adds a production to the set of productions in the grammar.

Parameters:
production - the production to be added.
Throws:
java.lang.IllegalArgumentException - if the production is unsuitable somehow

addProductions

public void addProductions(Production[] productions)
Adds productions to grammar

Parameters:
productions - the set of productions to add

getProductions

public Production[] getProductions()
Returns all productions in the grammar.

Returns:
all productions in the grammar.

getProductionsNumber

public int getProductionsNumber()
Returns the productions' number in the grammar.

Returns:
the productions' number in the grammar.

usefulness

public java.lang.String usefulness()
Finds out the useless variables.

Returns:
the useless variables.

reachability

public java.lang.String reachability()
Finds out the unreachable variables.

Returns:
the unreachable variables.

toString

public java.lang.String toString()
Returns a string representation of the grammar object,

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the grammar object.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object