parser + asd non testé non builder

This commit is contained in:
Vu Tuan Minh
2025-04-01 16:52:50 +02:00
parent 95fee3f1ae
commit 02d57fa858
13 changed files with 1374 additions and 60 deletions

View File

@@ -0,0 +1,23 @@
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();
}
}
}