diff --git a/lib/javascript/gflib.js b/lib/javascript/gflib.js index 630c01a3d..194fe57db 100644 --- a/lib/javascript/gflib.js +++ b/lib/javascript/gflib.js @@ -3,12 +3,12 @@ function Fun(name) { this.name = name; } -Fun.prototype.toString = function () { return this.show(0); } ; +Fun.prototype.print = function () { return this.show(0); } ; Fun.prototype.show = function (prec) { var s = this.name; var cs = this.getChildren(); - for (var c in cs) { - s += " " + c.show(1); + for (var i in cs) { + s += " " + cs[i].show(1); } if (prec > 0 && cs.length > 0) { s = "(" + s + ")" ; @@ -36,7 +36,7 @@ Fun.prototype.getChildren = function () { /* Hack to get around the fact that our SISR doesn't build real Fun objects. */ function copyTree(x) { if (typeof x == 'string' && x == '?') { - return '?'; + return new Fun('?'); } else { var t = new Fun(x.name); for (var i = 0; ; i++) { @@ -116,7 +116,7 @@ Linearizer.prototype.rule = function (name, cs) { return this.rules[name](cs); } Linearizer.prototype.addRule = function (name, f) { this.rules[name] = f; }; Linearizer.prototype.linearize = function (tree) { return this.linearizeToTerm(tree).print(); }; Linearizer.prototype.linearizeToTerm = function (tree) { - if (typeof tree == 'string' && tree == '?') { + if (tree.name == '?') { return new Meta(); } else { var cs = tree.getChildren();