xtc.parser
Class EquivalenceTester

java.lang.Object
  extended by xtc.tree.Visitor
      extended by xtc.parser.EquivalenceTester

public class EquivalenceTester
extends Visitor

Visitor to test productions and elements for equivalence. This visitor tests whether two productions or two elements are structurally the same, modulo using different variable names and having different nonterminals (for productions). It should only be invoked through the areEquivalent(Production,Production) and areEquivalent(Element,Element) methods.

Version:
$Revision: 1.36 $
Author:
Robert Grimm

Field Summary
protected  Element e2
          The element to compare to.
protected  java.util.Map<java.lang.String,java.lang.String> nts
          The mapping between equivalent nonterminals.
protected  java.util.Map<java.lang.String,java.lang.String> vars
          The mapping between equivalent variables.
 
Constructor Summary
EquivalenceTester()
          Create a new equivalence tester.
 
Method Summary
 boolean areEquivalent(Element e1, Element e2)
          Determine whether the specified elements are equivalent.
protected  boolean areEquivalent(GenericValue v1, GenericValue v2)
          Determine whether the specified generic values are equivalent.
protected  boolean areEquivalent(java.util.List<Binding> l1, java.util.List<Binding> l2)
          Determine whether the specified lists of bindings are equivalent.
 boolean areEquivalent(Production p1, Production p2)
          Determine whether the specified productions are equivalent.
 java.lang.Boolean visit(ActionBaseValue v1)
          Visit the specified action base value.
 java.lang.Boolean visit(Binding b1)
          Visit the specified binding.
 java.lang.Boolean visit(BindingValue v1)
          Visit the specified binding value.
 java.lang.Boolean visit(CharSwitch s1)
          Visit the specified character switch.
 java.lang.Boolean visit(Element e1)
          Visit the specified element.
 java.lang.Boolean visit(GenericActionValue v1)
          Visit the specified generic action value.
 java.lang.Boolean visit(GenericNodeValue v1)
          Visit the specified generic node value.
 java.lang.Boolean visit(GenericRecursionValue v1)
          Visit the specified generic recursion value.
 java.lang.Boolean visit(NonTerminal nt1)
          Visit the specified nonterminal.
 java.lang.Boolean visit(OrderedChoice c1)
          Visit the specified ordered choice.
 java.lang.Boolean visit(ParseTreeNode n1)
          Visit the specified parse tree node.
 java.lang.Boolean visit(ProperListValue v1)
          Visit the specified proper list value.
 java.lang.Boolean visit(Repetition r1)
          Visit the specified repetition.
 java.lang.Boolean visit(Sequence s1)
          Visit the specified sequence.
 java.lang.Boolean visit(StringMatch m1)
          Visit the specified string match.
 java.lang.Boolean visit(UnaryOperator op1)
          Visit the specified unary operator.
 
Methods inherited from class xtc.tree.Visitor
dispatch, equals, hashCode, iterate, map, mapInPlace, unableToVisit, visit
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nts

protected java.util.Map<java.lang.String,java.lang.String> nts
The mapping between equivalent nonterminals.


vars

protected java.util.Map<java.lang.String,java.lang.String> vars
The mapping between equivalent variables.


e2

protected Element e2
The element to compare to.

Constructor Detail

EquivalenceTester

public EquivalenceTester()
Create a new equivalence tester.

Method Detail

areEquivalent

public boolean areEquivalent(Production p1,
                             Production p2)
Determine whether the specified productions are equivalent.

Parameters:
p1 - The first production.
p2 - The second production.
Returns:
true if the two productions are equivalent.

areEquivalent

public boolean areEquivalent(Element e1,
                             Element e2)
Determine whether the specified elements are equivalent.

Parameters:
e1 - The first element.
e2 - The second element.
Returns:
true if the two elements are equivalent.

areEquivalent

protected boolean areEquivalent(java.util.List<Binding> l1,
                                java.util.List<Binding> l2)
Determine whether the specified lists of bindings are equivalent.

Parameters:
l1 - The first list.
l2 - The second list.
Returns:
true if the two lists are equivalent.

areEquivalent

protected boolean areEquivalent(GenericValue v1,
                                GenericValue v2)
Determine whether the specified generic values are equivalent.

Parameters:
v1 - The first value.
v2 - The second value.
Returns:
true if the two values are equivalent.

visit

public java.lang.Boolean visit(OrderedChoice c1)
Visit the specified ordered choice.


visit

public java.lang.Boolean visit(Repetition r1)
Visit the specified repetition.


visit

public java.lang.Boolean visit(Sequence s1)
Visit the specified sequence.


visit

public java.lang.Boolean visit(Binding b1)
Visit the specified binding.


visit

public java.lang.Boolean visit(StringMatch m1)
Visit the specified string match.


visit

public java.lang.Boolean visit(NonTerminal nt1)
Visit the specified nonterminal.


visit

public java.lang.Boolean visit(CharSwitch s1)
Visit the specified character switch.


visit

public java.lang.Boolean visit(ParseTreeNode n1)
Visit the specified parse tree node.


visit

public java.lang.Boolean visit(ProperListValue v1)
Visit the specified proper list value.


visit

public java.lang.Boolean visit(BindingValue v1)
Visit the specified binding value.


visit

public java.lang.Boolean visit(ActionBaseValue v1)
Visit the specified action base value.


visit

public java.lang.Boolean visit(GenericNodeValue v1)
Visit the specified generic node value.


visit

public java.lang.Boolean visit(GenericActionValue v1)
Visit the specified generic action value.


visit

public java.lang.Boolean visit(GenericRecursionValue v1)
Visit the specified generic recursion value.


visit

public java.lang.Boolean visit(UnaryOperator op1)
Visit the specified unary operator. This method provides the default implementation for options, predicates, voided elements, and parser actions.


visit

public java.lang.Boolean visit(Element e1)
Visit the specified element. This method provides the default implementation for terminals, node markers, null literals, actions, and null, string, text, empty list, generic string, and generic text values.



Copyright © 2012. All Rights Reserved.