23 lines
733 B
Java
23 lines
733 B
Java
package TP2.asd;
|
|
|
|
import java.util.Map;
|
|
|
|
public class ExprEval implements ExprVisitor<Map<String, Type>,Integer> {
|
|
|
|
@Override
|
|
public Integer visitConst(Const c, Map<String, Type> h) {
|
|
return c.c();
|
|
}
|
|
|
|
@Override
|
|
public Integer visitBinOp(BinopExpression e, Map<String, Type> h) {
|
|
switch(e.op()){
|
|
case Op.PLUS: return e.e1().accept(this, h)+e.e2().accept(this, h);
|
|
case Op.MINUS: return e.e1().accept(this, h)-e.e2().accept(this, h);
|
|
case Op.TIMES: return e.e1().accept(this, h)*e.e2().accept(this, h);
|
|
case Op.DIV: return e.e1().accept(this, h)/e.e2().accept(this, h);
|
|
default: throw new IllegalArgumentException();
|
|
}
|
|
}
|
|
|
|
} |