01: package gnu.commonlisp.lang;
02:
03: import gnu.mapping.*;
04: import gnu.expr.*;
05: import gnu.lists.*;
06: import kawa.lang.*;
07:
08: public class function extends Syntax {
09: Syntax lambda;
10:
11: public function(Syntax lambda) {
12: this .lambda = lambda;
13: }
14:
15: public Expression rewriteForm(Pair form, Translator tr) {
16: Object obj = form.cdr;
17: if (obj instanceof Pair) {
18: Pair pair = (Pair) obj;
19: if (pair.cdr != LList.Empty)
20: return tr
21: .syntaxError("too many forms after 'function'");
22: Object name = pair.car;
23: if (name instanceof String || name instanceof Symbol) {
24: ReferenceExp rexp = new ReferenceExp(name);
25: rexp.setProcedureName(true);
26: rexp.setFlag(ReferenceExp.PREFER_BINDING2);
27: return rexp;
28: }
29: if (name instanceof Pair) {
30: pair = (Pair) name;
31: name = pair.car;
32: if (name instanceof String ? "lambda".equals(name)
33: : (name instanceof Symbol && "lambda"
34: .equals(((Symbol) name).getName())))
35: return lambda.rewriteForm(pair, tr);
36: }
37: }
38: return tr
39: .syntaxError("function must be followed by name or lambda expression");
40: }
41: }
|