laser.regularlanguage.regularexpression.util
Class RESimplifier<L extends LabelInterface>

java.lang.Object
  extended by laser.regularlanguage.regularexpression.AbstractREVisitor<L>
      extended by laser.regularlanguage.regularexpression.util.AbstractREConverter<L>
          extended by laser.regularlanguage.regularexpression.util.RESimplifier<L>
Type Parameters:
L - The type of Label associated with the REs.
All Implemented Interfaces:
REVisitor<L>

public class RESimplifier<L extends LabelInterface>
extends AbstractREConverter<L>

The RESimplifier class simplifies the given RE by applying identities to remove terms.

Author:
Heather M. Conboy (laser-software@cs.umass.edu)

Field Summary
 
Fields inherited from class laser.regularlanguage.regularexpression.util.AbstractREConverter
reFactory_
 
Fields inherited from class laser.regularlanguage.regularexpression.AbstractREVisitor
result
 
Constructor Summary
RESimplifier(REFactory<L> reFactory)
          Creates a new RESimplifier.
 
Method Summary
 void caseChoiceNode(ChoiceNode<L> node, java.lang.Object context)
          Simplifies the given ChoiceNode.
 void caseClassSetNode(ClassSetNode<L> node, java.lang.Object context)
          Simplifies the given ClassSetNode.
 void caseConcatenationNode(ConcatenationNode<L> node, java.lang.Object context)
          Simplifies the given ConcatenationNode.
 void caseDotNode(DotNode<L> node, java.lang.Object context)
          Simplifes the given DotNode.
 void caseEmptyNode(EmptyNode<L> node, java.lang.Object context)
          Simplifies the given EmptyNode.
 void caseEpsilonNode(EpsilonNode<L> node, java.lang.Object context)
          Simplifies the given EpsilonNode.
 void caseExponentNode(ExponentNode<L> node, java.lang.Object context)
          Simplifies the given ExponentNode.
 void caseKleenePlusNode(KleenePlusNode<L> node, java.lang.Object context)
          Simplifies the given KleenePlusNode.
 void caseKleeneStarNode(KleeneStarNode<L> node, java.lang.Object context)
          Simplifies the given KleeneStarNode.
 void caseLabelNode(LabelNode<L> node, java.lang.Object context)
          Creates a new LabelNode.
 void caseNotClassSetNode(NotClassSetNode<L> node, java.lang.Object context)
          Simplifies the given NotClassSetNode.
 void caseOptionNode(OptionNode<L> node, java.lang.Object context)
          Simplifies the given OptionNode.
 RE<L> simplify(RE<L> theRE)
          Simplifies the given RE.
 
Methods inherited from class laser.regularlanguage.regularexpression.util.AbstractREConverter
convert, convert, getCreateREArgs, getResult, setResult, setUp, tearDown
 
Methods inherited from class laser.regularlanguage.regularexpression.AbstractREVisitor
defaultCase, setResult
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RESimplifier

public RESimplifier(REFactory<L> reFactory)
Creates a new RESimplifier.

Parameters:
reFactory - The REFactory to be used to create new REs (non-null)
Method Detail

simplify

public RE<L> simplify(RE<L> theRE)
                                      throws REException
Simplifies the given RE.

PRECONDITIONS:

Parameters:
theRE - The RE to be simplified
Returns:
The simplified RE
Throws:
REException - if an error occurs

caseChoiceNode

public void caseChoiceNode(ChoiceNode<L> node,
                           java.lang.Object context)
                    throws REVisitorException
Simplifies the given ChoiceNode.

RULES:

  1. (EMPTY | R) = (R | EMPTY) = R

Specified by:
caseChoiceNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseChoiceNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The ChoiceNode to be simplified
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseClassSetNode

public void caseClassSetNode(ClassSetNode<L> node,
                             java.lang.Object context)
                      throws REVisitorException
Simplifies the given ClassSetNode.

NOTE: This is a base case.

Specified by:
caseClassSetNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseClassSetNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The ClassSetNode to be simplified
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseConcatenationNode

public void caseConcatenationNode(ConcatenationNode<L> node,
                                  java.lang.Object context)
                           throws REVisitorException
Simplifies the given ConcatenationNode.

RULES:

  1. (EMPTY ; R) = (R ; EMPTY) = EMPTY
  2. (EPSILON ; R) = (R ; EPSILON) = R

Specified by:
caseConcatenationNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseConcatenationNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The ConcatenationNode to be simplified
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseDotNode

public void caseDotNode(DotNode<L> node,
                        java.lang.Object context)
                 throws REVisitorException
Simplifes the given DotNode.

NOTE: This is a base case.

Specified by:
caseDotNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseDotNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The DotNode to be simplified
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseEmptyNode

public void caseEmptyNode(EmptyNode<L> node,
                          java.lang.Object context)
Simplifies the given EmptyNode.

NOTE: This is a base case.

Specified by:
caseEmptyNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseEmptyNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The EmptyNode to be simplified
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseEpsilonNode

public void caseEpsilonNode(EpsilonNode<L> node,
                            java.lang.Object context)
Simplifies the given EpsilonNode.

NOTE: This is a base case.

Specified by:
caseEpsilonNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseEpsilonNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The EpsilonNode to be simplified
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseExponentNode

public void caseExponentNode(ExponentNode<L> node,
                             java.lang.Object context)
                      throws REVisitorException
Simplifies the given ExponentNode.

RULES:

  1. (EMPTY)^(L(-H)) = EPSILON when L is zero
  2. (EMPTY)^(L(-H)) = EMPTY when L is greater than zero
  3. (EPSILON)^(L(-H)) = EPSILON

Specified by:
caseExponentNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseExponentNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The ExponentNode to be simplified
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseKleenePlusNode

public void caseKleenePlusNode(KleenePlusNode<L> node,
                               java.lang.Object context)
                        throws REVisitorException
Simplifies the given KleenePlusNode.

RULES:

  1. (EMPTY)+ = EMPTY
  2. (EPSILON)+ = EPSILON

Specified by:
caseKleenePlusNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseKleenePlusNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The KleenePlusNode to be simplified
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseKleeneStarNode

public void caseKleeneStarNode(KleeneStarNode<L> node,
                               java.lang.Object context)
                        throws REVisitorException
Simplifies the given KleeneStarNode.

RULES:

  1. (EMPTY)* = EPSILON
  2. (EPSILON)* = EPSILON

Specified by:
caseKleeneStarNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseKleeneStarNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The KleeneStarNode to be simplified
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseLabelNode

public void caseLabelNode(LabelNode<L> node,
                          java.lang.Object context)
                   throws REVisitorException
Creates a new LabelNode.

NOTE: This is a base case.

Specified by:
caseLabelNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseLabelNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The LabelNode to be simplified
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseNotClassSetNode

public void caseNotClassSetNode(NotClassSetNode<L> node,
                                java.lang.Object context)
                         throws REVisitorException
Simplifies the given NotClassSetNode.

Specified by:
caseNotClassSetNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseNotClassSetNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The NotClassSetNode to be simplified
context - This is currently not being used
Throws:
REVisitorException - if an error occurs

caseOptionNode

public void caseOptionNode(OptionNode<L> node,
                           java.lang.Object context)
                    throws REVisitorException
Simplifies the given OptionNode.

RULES:

  1. (EMPTY)? = EPSILON
  2. (EPSILON)? = EPSILON

Specified by:
caseOptionNode in interface REVisitor<L extends LabelInterface>
Overrides:
caseOptionNode in class AbstractREVisitor<L extends LabelInterface>
Parameters:
node - The OptionNode to be simplified
context - This is currently not being used
Throws:
REVisitorException - if an error occurs