Main { {{ static ClassGraph cg; public static void main(String args[]) throws Exception { Exps es = Exps.parse(System.in); ClassGraph g = new ClassGraph(true,false); cg = new ClassGraph(true, false); cg = new ClassGraph(cg, "from Exps bypassing -> *,tail,* to *"); cg.traverse(es,"from Exps to Simple", new Visitor() { // cg.traverse(es,"from Exps to-stop Exp", new Visitor() { public void start() {System.out.println("Testing the evaluator");}; public void before(Exp host){ host.print(); System.out.println(" new Exp ========================= "); List l = host.eval(); for(Iterator i = l.iterator(); i.hasNext();) { System.out.print(" ClassName "); ((ClassName)i.next()).print(); System.out.println(); }; } public void before(Equation host){ System.out.println(" start of Equation-object +++++++++++++ "); } ;}); cg.traverse(es,"from Exps via Sequential to ClassName", new Visitor() { public void start() {System.out.println("start with ClassName printing");}; public void before(ClassName host){ host.print(); System.out.println(); } public void finish() {System.out.println("done with ClassName printing");}; }); TraversalGraph tg = new TraversalGraph("from Exps via Sequential to ClassName", cg); System.out.println("TraversalGraph"); System.out.println(); System.out.println(tg); cg.traverse(es,"from Exps to {Forward, Backward}", new Visitor() { public void before(Forward host){ if (host.steps == null) host.set_steps(new Unlimited()); } public void before(Backward host){ if (host.steps == null) host.set_steps(new Unlimited()); } }); System.out.println(" modified Exps-object "); es.print(); System.out.println(); System.out.println(" displayed object "); es.display(); System.out.println(" done "); } }} } ClassName { void print() to * (PrintVisitor); } Exp { void print() to * (PrintVisitor); } Exps { void print() to * (PrintVisitor); void display() to * (DisplayVisitor); } Exp { {{ abstract List eval(); }} } Simple { {{ abstract List eval(); }} } Forward { {{ List eval(){ ArrayList t = new ArrayList(); t.add(source); return t; }; }} } Backward { {{ List eval(){ ArrayList t = new ArrayList(); t.add(source); t.add(target); return t; }; }} } Sequential { {{ List eval(){ return new ArrayList();}; }} } Later { {{ List eval(){ ArrayList t = new ArrayList(); t.add(source); t.add(target); return t; }; }} } UpOverDown { {{ List eval(){ ArrayList t = new ArrayList(); t.add(target); return t; }; }} } Exists { {{ List eval(){ return new ArrayList();}; }} } Op { {{ abstract List apply(List t); }} } Union { {{ List apply(List args){ List r = new ArrayList(); for(Iterator i = args.iterator(); i.hasNext();) r.addAll((List)i.next()); return r; } }} } Join { {{ List apply(List args){ List r = new ArrayList(); for(Iterator i = args.iterator(); i.hasNext();) r.addAll((List)i.next()); return r; } }} } Compound { {{ List eval(){ List t = new ArrayList(); for(Enumeration e = args.elements();e.hasMoreElements();) t.add(((Exp)e.nextElement()).eval()); return op.apply(t); } }} }