001package visitor.expr;
002import enumeration.Op;
003
004public interface Expr {
005        <T> T accept(ExprVisitor<T> v);
006}
007
008class Const implements Expr {
009        private final int c;
010        public Const(int c) {
011                this.c = c;
012        }
013        public <T> T accept(ExprVisitor<T> v) {
014                return v.visitConst(c);
015        }
016}
017
018class BinOp implements Expr {
019        private final Expr l;
020        private final Expr r;
021        private final Op op;
022
023        public BinOp(Expr l, Op op, Expr r) {
024                if ((l == null) || (op == null) || (r == null)) {
025                        throw new IllegalArgumentException();
026                }
027                this.op = op;
028                this.l = l;
029                this.r = r;
030        }
031        public <T> T accept(ExprVisitor<T> v) {
032                return v.visitBinOp(l, op, r);
033        }
034}