a = t.type;
if (a === "name") {
o = symbol_table[v];
- if (o && typeof o !== 'function') {
- a = "keyword";
- } else {
+ if (!o || typeof o === 'function') {
o = symbol_table["(name)"];
+ } else {
+ a = o.arity || "keyword";
}
} else if (a === "number") {
- o = symbol_table["(literal)"];
- a = "literal";
+ o = symbol_table["(number)"];
+ a = "literal";
} else if (a === "operator") {
o = symbol_table[v];
if (!o) {
}
};
+ try {
+ if (console && console.debug) {
+ function print() {
+ console.debug.apply(this, arguments);
+ }
+ }
+ } catch (e) {}
+
var symbol = function (id) {
var s = symbol_table[id];
if (!s) {
return s;
};
-// try {
-// if (console && console.debug) {
-// function print() {
-// console.debug.apply(this, arguments);
-// }
-// }
-// } catch (e) {}
-
var var_table;
var name_table;
return body;
};
+ var number_handler = function () {
- var itself = function () {
- return this;
};
symbol("(end)");
symbol("(name)").handler = name_handler;
- symbol("(literal)").handler = itself;
+ symbol("(number)").handler = number_handler;
symbol("let").handler = lambda_handler;
symbol("=").handler = branch_handler;
symbol("in");
var x = symbol(s);
x.handler = function () {
this.value = symbol_table[this.id].value;
- this.arity = "literal";
- return this;
+ if (this.first) {
+ return make_app(this.first.handler(), this.value);
+ } else {
+ return this.value;
+ }
};
+ // constants have their own id and arity = literal
+ // numbers have id = "(number)" and arity = literal
+ x.arity = "literal";
x.value = v;
return x;
};
n = token;
advance();
}
- if (token.id === ".") {
+ if (token.arity === "literal" && t.first.length === 0) {
+ t.first.push(n);
+ t.second = token;
+ advance();
+ } else if (token.id === ".") {
t.first.push(n);
advance();
t.second = expression(in_let);
n = token;
advance(")");
} else {
- if (token.arity !== "name") {
- token.error("Expected a variable name.");
+ if (token.arity !== "name" && token.arity !== "literal") {
+ token.error("Expected a variable name or literal.");
}
token.first = n;
n = token;