1 20 21 22 27 class Tfun extends Texp implements AST { 28 Tident ident; Texplist explist; 31 public Tfun(Tident i, Texplist e) { 32 ident=i; 33 explist=e; 34 } 35 36 public String toString() { 37 return ident+"("+explist+")"; 38 } 39 40 public void checkcontext(SymTab st) { explist.checkcontext(st); 42 SymtabEntry ste = st.lookup(ident.toString()); 43 if (ste==null) 44 Main.error("function not defined: "+ident); 45 else if (ste.kind() != SymtabEntry.FUN) 46 Main.error("variable used as funktion: "+ident); 47 else if (((STEfun)ste).arity() != explist.length()) 48 Main.error("wrong arity at function call: "+ident); 49 } 50 51 Tdekl fundekl; 53 public void prepInterp(SymTab st) { 55 fundekl = ((STEfun)st.lookup(ident.toString())).getDekl(); 56 explist.prepInterp(st); 57 } 58 59 public int interpret(int[] in, int[] par) { 60 int[] newparams = new int[fundekl.arity()]; 61 explist.interpret(in,par,newparams,0); 62 return fundekl.interpret(in,newparams); 63 } 64 } 65 66 67 | Popular Tags |