Browse Source

progress on test evaluator

pull/23/head
nisstyre56 10 years ago
parent
commit
cc035dc383
  1. 30
      vm.js

30
vm.js

@ -7,18 +7,36 @@ var pprint = require("./pprint.js");
//var istr = fs.readFileSync('/dev/stdin').toString();
var istr = "lambda a b -> (a + b)";
var istr = "(a + b)";
var ast = parse.parseFull(tokenizer.tokenize(istr));
function apply(func, p, environment) {
var full_func = evaluate(func, environment);
return [full_func, evaluate(p, environment)];
}
function evaluate(ast, environment) {
function evaluateAll(ast, environment) {
var l = ast.length;
var evaled = [];
for (var i = 0; i < l; i++) {
if (ast[i].exprType == "Function") {
console.log(ast[i]);
}
evaled.push(evaluate(ast[i], environment));
}
return evaled;
}
evaluate(ast[0], false);
function evaluate(ast, environment) {
if (ast.exprType == "Application") {
return apply(ast.func, ast.p, environment);
}
else if (ast.exprType === "Unary") { /* Unary function application */
return apply(ast.op, ast.val, environment);
}
else if (ast.exprType === "Name") {
return ast.ident;
}
else {
return ast.val;
}
}
console.log("%j", evaluateAll(ast[0], false));

Loading…
Cancel
Save