change mid to double up arrow U+2e17
[lambda.git] / code / parse.js
index 382ba02..ddc6199 100644 (file)
@@ -4,6 +4,9 @@
 //      http://javascript.crockford.com/tdop/index.html
 //      Douglas Crockford 2010-06-26
 
+//      See also http://effbot.org/zone/simple-top-down-parsing.htm
+
+
 /*jslint onevar: false
  */
 
@@ -65,6 +68,7 @@ var make_parse = function () {
         }
     };
 
+       /*
        try {
                if (console && console.debug) {
                        function print() {
@@ -72,6 +76,7 @@ var make_parse = function () {
                        }
                }
        } catch (e) {}
+       */
 
     var symbol = function (id) {
         var s = symbol_table[id];
@@ -135,6 +140,9 @@ var make_parse = function () {
     symbol("(");
     symbol("\\").handler = lambda_handler;
     symbol("lambda").handler = lambda_handler;
+    symbol("\u03bb").handler = lambda_handler;
+    // symbol("\u2203").handler = exists_handler;
+    // symbol("\u2200").handler = forall_handler;
     symbol(".");
 
        function make_constants() {
@@ -176,7 +184,11 @@ var make_parse = function () {
                                res = make_lam2(s, z, res);
                                number_table[this.value] = res;
                        }
-                       return res;
+                       if (this.first) {
+                               return make_app(this.first.handler(), res);
+                       } else {
+                               return res;
+                       }
                }
 
                var constant = function (s, v) {
@@ -199,8 +211,16 @@ var make_parse = function () {
                constant("I", make_lam(x, xx));
                constant("B", make_lam3(u, v, x, make_app(uu, make_app(vv, xx))));
                constant("C", make_lam3(u, v, x, make_app3(uu, xx, vv)));
-               constant("W", make_lam2(u, v, make_app3(uu, vv, vv)));
+
+               // trush \uv.vu = CI
                constant("T", make_lam2(u, v, make_app(vv, uu)));
+               // mockingbird \u.uu = SII
+               constant("M", make_lam(u, make_app(uu, uu)));
+               // warbler \uv.uvv = C(BM(BBT) = C(BS(C(BBI)I))I
+               constant("W", make_lam2(u, v, make_app3(uu, vv, vv)));
+               // lark \uv.u(vv) = CBM = BWB
+               constant("L", make_lam2(u, v, make_app(uu, make_app(vv, vv))));
+               // Y is SLL
 
        }
        make_constants();
@@ -224,9 +244,11 @@ var make_parse = function () {
                 return t;
             } else {
                 t.first = [];
-                while (token.arity === "name") {
-                    t.first.push(n);
-                    n = token;
+                while (token.arity === "name" || token.id === "\\") {
+                   if (token.id !== "\\") {
+                      t.first.push(n);
+                      n = token;
+                   }
                     advance();
                 }
                                if (token.arity === "literal" && t.first.length === 0) {
@@ -284,7 +306,7 @@ var make_parse = function () {
         tokens = source.tokens();
         token_nr = 0;
         advance();
-        
+
         // let n = c in b
         // (\n. b) c
 
@@ -314,7 +336,7 @@ var make_parse = function () {
             target = t;
             advance("in");
         }
-    
+
         target.second = expression(false);
 
         advance("(end)");