01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package iterator.exprtwo;
import java.util.Iterator;
import enumeration.Op;

public class Main {
  public static void main (String[] args) {
    AbsExpr one = new Const(1);
    AbsExpr onePtwo = new BinOp (new Const(1), Op.ADD, new Const(2));
    AbsExpr threeMfour = new BinOp (new Const(3), Op.MUL, new Const(4));
    AbsExpr m = new BinOp (onePtwo, Op.SUB, threeMfour);
    Expr n = new BinOp (m, Op.DIV, new Const(5));

    for (Iterator<Object> i = n.postorderIterator(); i.hasNext(); )
      System.out.print (i.next() + " ");
    System.out.println ("");

    for (Iterator<Object> i = n.preorderIterator(); i.hasNext(); )
      System.out.print (i.next() + " ");
    System.out.println ("");

    for (Iterator<Object> i = n.breadthIterator(); i.hasNext(); )
      System.out.print (i.next() + " ");
    System.out.println ("");

    System.out.println ("Value: " + n.evaluate());
  }
}