1 20 21 22 25 class Tifthenelse extends Texp implements AST { 26 Tboolexp boolexp; Texp exp1, exp2; 29 public Tifthenelse(Tboolexp b, Texp e1, Texp e2) { 30 boolexp=b; 31 exp1=e1; 32 exp2=e2; 33 } 34 35 public String toString() { 36 return "if "+boolexp+" then "+exp1+" else "+exp2+" fi"; 37 } 38 39 public void checkcontext(SymTab st) { 40 boolexp.checkcontext(st); 41 exp1.checkcontext(st); 42 exp2.checkcontext(st); 43 } 44 45 public void prepInterp(SymTab st) { 46 boolexp.prepInterp(st); 47 exp1.prepInterp(st); 48 exp2.prepInterp(st); 49 } 50 51 public int interpret(int[] in, int[] par) { 52 boolean b = boolexp.interpret(in,par); 53 if (b) 54 return exp1.interpret(in,par); 55 else 56 return exp2.interpret(in,par); 57 } 58 } 59 60 | Popular Tags |