edits
[lambda.git] / code / parse.js
index 382ba02..72fda3e 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];
@@ -176,7 +181,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) {
@@ -225,8 +234,8 @@ var make_parse = function () {
             } else {
                 t.first = [];
                 while (token.arity === "name") {
-                    t.first.push(n);
-                    n = token;
+                      t.first.push(n);
+                      n = token;
                     advance();
                 }
                                if (token.arity === "literal" && t.first.length === 0) {