This commit is contained in:
Tomoya Matsuura(MacBookPro) 2023-11-25 02:58:50 +09:00
parent 945b331970
commit 042ce7f9ca

View File

@ -17,7 +17,6 @@ const reader = require("readline").createInterface({
const tokenize = (str) => const tokenize = (str) =>
str.match(/[\(]|[\)]|[\+\-\*\/]|[a-zA-Z_]+|(-?\d+(\.\d+)?)/g); str.match(/[\(]|[\)]|[\+\-\*\/]|[a-zA-Z_]+|(-?\d+(\.\d+)?)/g);
const parse_token = (token, stack, res) => { const parse_token = (token, stack, res) => {
switch (token) { switch (token) {
case '(': { case '(': {
@ -40,7 +39,6 @@ const parse_token = (token, stack, res) => {
} }
} }
} }
const parse = (tokens) => { const parse = (tokens) => {
let stack = []; let stack = [];
let next_res = []; let next_res = [];
@ -52,7 +50,6 @@ const parse = (tokens) => {
const read = (str) => parse(tokenize(str)); const read = (str) => parse(tokenize(str));
const binop = (args, fn) => fn(args[0], args[1]); const binop = (args, fn) => fn(args[0], args[1]);
const env = { const env = {
"parent": null, "parent": null,
"+": args => binop(args, (a, b) => a + b), "+": args => binop(args, (a, b) => a + b),
@ -100,7 +97,7 @@ const eval = (expr, env) => {
return fn(expr.map(e => eval(e, env))) return fn(expr.map(e => eval(e, env)))
} }
} else { } else {
return fn return null
} }
} }
} }