Main{{ public static void main(String s[]) throws Exception{ Main m = Main.parse(new FileInputStream(s[0])); System.out.println(" Start: "+str(m.term)); System.out.println(" Simple: "+str(simplify(m.term))); } static Term simplify(Term t){ return new Traversal(new Bc(){ class Zero extends Term{} class One extends Term{} Term combine(Num t, int i){ switch(i){ case 0: return new Zero(); case 1: return new One(); default: return t; } } Term combine(Mul t, One l, Term r){ return r; } Term combine(Mul t, Term l, One r){ return l; } Term combine(Mul t, Zero l, Term r){ return l; } Term combine(Mul t, Term l, Zero r){ return r; } Term combine(Add t, Zero l, Term r){ return r; } Term combine(Add t, Term l, Zero r){ return l; } }).traverse(t); } static String str(Term t){ return new Traversal(new ID(){ String combine(Num t, int n){ return ""+n; } String combine(Var t, Ident id){ return ""+id; } String combine(Mul t, String l, String r){ return infix(l,"*",r); } String combine(Add t, String l, String r){ return infix(l,"+",r); } String infix(String l, String op, String r) { return "("+l+" "+op+" "+r+")"; } }, EdgeControl.builtIns(Ident.class)).traverse(t); } }}