parser + asd non testé non builder
This commit is contained in:
23
src/main/java/TP2/asd/ExprEval.java
Normal file
23
src/main/java/TP2/asd/ExprEval.java
Normal 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user