1 20 21 22 25 class Tboolexp implements AST { 26 Texp exp1, exp2; char kind; 29 public Tboolexp(Texp e1, char k, Texp e2) { 30 exp1=e1; 31 kind=k; 32 exp2=e2; 33 } 34 35 public String toString() { 36 if (kind!='!') 37 return(""+exp1+kind+exp2); 38 else 39 return(exp1+"<="+exp2); 40 } 41 42 public void checkcontext(SymTab st) { exp1.checkcontext(st); 44 exp2.checkcontext(st); 45 } 46 47 public void prepInterp(SymTab st) { exp1.prepInterp(st); 49 exp2.prepInterp(st); 50 } 51 52 public boolean interpret(int[] in, int[] par) { 53 int e1 = exp1.interpret(in,par); 54 int e2 = exp2.interpret(in,par); 55 switch(kind) { 56 case '=': return(e1==e2); 57 case '<': return(e1<e2); 58 case '!': return(e1<=e2); 59 } 60 61 return(false); } 63 } 64 65 | Popular Tags |