Files
tp2-vsl-pds/src/main/java/TP2/asd/ExprEval.java
2025-04-01 16:52:50 +02:00

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();
}
}
}