Fixed some bugs, began adding a Script class

This commit is contained in:
Daniel Xie
2016-11-21 00:11:14 -06:00
parent 8d87b74eaf
commit d372ce5980
7 changed files with 89 additions and 41 deletions
+3 -3
View File
@@ -51,7 +51,7 @@ function evaluate(exp, env) {
cond = evaluate(exp.cond, env);
}
//TODO Return somethin?
//TODO I don't think I need to return anything..but I might be wrong
break;
case "while":
cond = evaluate(exp.cond, env);
@@ -61,7 +61,7 @@ function evaluate(exp, env) {
cond = evaluate(exp.cond, env);
}
//TODO DO i need to return anything?
//TODO I don't think I need to return anything..but I might be wrong
break;
case "prog":
var val = false;
@@ -85,7 +85,7 @@ function evaluate(exp, env) {
} else if (exp.func.value == "sleep") {
console.log("Execute sleep()");
} else if (exp.func.value == "print") {
console.log(evaluate(exp.args[0], env));
post(evaluate(exp.args[0], env).toString());
}
break;
+7 -3
View File
@@ -104,8 +104,12 @@ function Tokenizer(input) {
return str;
}
function read_string() {
return { type: "str", value: read_escaped('"') };
function read_string(ch) {
if (ch == '"') {
return { type: "str", value: read_escaped('"') };
} else if (ch == '\'') {
return { type: "str", value: read_escaped('\'') };
}
}
//Only supports single-line comments right now
@@ -130,7 +134,7 @@ function Tokenizer(input) {
return read_next();
}
if (ch == '"') return read_string();
if (ch == '"' || ch == '\'') return read_string(ch);
if (is_digit(ch)) return read_number();
if (is_id_start(ch)) return read_ident();
if (is_punc(ch)) return {