@Test public void testDerive() { Epsilon epsilon = Epsilon.get(); Empty empty = Empty.get(); ERE ab = Concat.get(a, b); assertEquals(b, ab.derive(a)); assertEquals(empty, ab.derive(b)); ERE aStar = Kleene.get(a); ERE aStarb = Concat.get(aStar, b); assertEquals(aStarb, aStarb.derive(a)); assertEquals(epsilon, aStarb.derive(b)); assertEquals(empty, aStarb.derive(c)); }
@Override public ERE derive(Symbol s){ ERE left = children.get(0); ERE right = children.get(1); if(left.containsEpsilon()) { ArrayList<ERE> orChildren = new ArrayList<ERE>(2); orChildren.add(Concat.get(left.derive(s), right.copy())); orChildren.add(right.derive(s)); return Or.get(orChildren); } return Concat.get(left.derive(s), right.copy()); }
Concat extends ERE { @Override public ERE derive(Symbol s){ ERE left = children.get(0); ERE right = children.get(1); if(left.containsEpsilon()) { ArrayList<ERE> orChildren = new ArrayList<ERE>(2); orChildren.add(Concat.get(left.derive(s), right.copy())); orChildren.add(right.derive(s)); return Or.get(orChildren); } return Concat.get(left.derive(s), right.copy()); } }
Concat extends ERE { @Override public ERE derive(Symbol s){ ERE left = children.get(0); ERE right = children.get(1); if(left.containsEpsilon()) { ArrayList<ERE> orChildren = new ArrayList<ERE>(2); orChildren.add(Concat.get(left.derive(s), right.copy())); orChildren.add(right.derive(s)); return Or.get(orChildren); } return Concat.get(left.derive(s), right.copy()); } private  Concat(ERE left, ERE right); }
Concat extends ERE { @Override public ERE derive(Symbol s){ ERE left = children.get(0); ERE right = children.get(1); if(left.containsEpsilon()) { ArrayList<ERE> orChildren = new ArrayList<ERE>(2); orChildren.add(Concat.get(left.derive(s), right.copy())); orChildren.add(right.derive(s)); return Or.get(orChildren); } return Concat.get(left.derive(s), right.copy()); } private  Concat(ERE left, ERE right); static ERE get(ERE left, ERE right); @Override EREType getEREType(); @Override String toString(); @Override ERE copy(); @Override boolean containsEpsilon(); @Override ERE derive(Symbol s); }
Concat extends ERE { @Override public ERE derive(Symbol s){ ERE left = children.get(0); ERE right = children.get(1); if(left.containsEpsilon()) { ArrayList<ERE> orChildren = new ArrayList<ERE>(2); orChildren.add(Concat.get(left.derive(s), right.copy())); orChildren.add(right.derive(s)); return Or.get(orChildren); } return Concat.get(left.derive(s), right.copy()); } private  Concat(ERE left, ERE right); static ERE get(ERE left, ERE right); @Override EREType getEREType(); @Override String toString(); @Override ERE copy(); @Override boolean containsEpsilon(); @Override ERE derive(Symbol s);  }