| 1 package gnu.commonlisp.lang; 2 import gnu.expr.*; 3 import kawa.lang.*; 4 import gnu.lists.*; 5 6 public class prog1 extends Syntax 7 { 8 9 int index; 10 11 public static final prog1 prog1 = new prog1("prog1", 1); 12 public static final prog1 prog2 = new prog1("prog2", 2); 13 14 public prog1 (String name, int index) 15 { 16 this.index = index; 17 setName(name); 18 } 19 20 public Expression rewrite (Object obj, Translator tr) 21 { 22 int nexps = LList.length(obj); 23 if (nexps < index) 24 return tr.syntaxError("too few expressions in "+getName()); 25 if (index == 2) 26 { 27 Pair pair = (Pair) obj; 28 return new BeginExp(tr.rewrite(pair.car), 29 prog1.rewrite(pair.cdr, tr)); 30 } 31 else 32 { 33 Expression[] inits = new Expression[1]; 34 LetExp let = new LetExp(inits); 35 Expression[] body = new Expression[nexps]; 36 Pair pair = (Pair) obj; 37 inits[0] = tr.rewrite(pair.car); 38 obj = pair.cdr; 39 for (int i = 0; i < nexps-1; i++) 40 { 41 pair = (Pair) obj; 42 body[i] = tr.rewrite(pair.car); 43 obj = pair.cdr; 44 } 45 Declaration decl = let.addDeclaration((Object ) null); 46 body[nexps-1] = new ReferenceExp(decl); 47 let.body = BeginExp.canonicalize(body); 48 tr.mustCompileHere(); 49 return let; 50 } 51 } 52 } 53 | Popular Tags |