01: package gnu.commonlisp.lang;
02:
03: import gnu.expr.*;
04: import kawa.lang.*;
05: import gnu.lists.*;
06:
07: public class prog1 extends Syntax {
08: /** This is 1 from prog1 and 2 for prog2. */
09: 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: this .index = index;
16: setName(name);
17: }
18:
19: public Expression rewrite(Object obj, Translator tr) {
20: int nexps = LList.length(obj);
21: if (nexps < index)
22: return tr
23: .syntaxError("too few expressions in " + getName());
24: if (index == 2) {
25: Pair pair = (Pair) obj;
26: return new BeginExp(tr.rewrite(pair.car), prog1.rewrite(
27: pair.cdr, tr));
28: } else {
29: Expression[] inits = new Expression[1];
30: LetExp let = new LetExp(inits);
31: Expression[] body = new Expression[nexps];
32: Pair pair = (Pair) obj;
33: inits[0] = tr.rewrite(pair.car);
34: obj = pair.cdr;
35: for (int i = 0; i < nexps - 1; i++) {
36: pair = (Pair) obj;
37: body[i] = tr.rewrite(pair.car);
38: obj = pair.cdr;
39: }
40: Declaration decl = let.addDeclaration((Object) null);
41: body[nexps - 1] = new ReferenceExp(decl);
42: let.body = BeginExp.canonicalize(body);
43: tr.mustCompileHere();
44: return let;
45: }
46: }
47: }
|