Skip to content

Instantly share code, notes, and snippets.

@ranjanistic
Created October 8, 2025 12:05
Show Gist options
  • Select an option

  • Save ranjanistic/fca26b41881020dd5aed053677b6c6c0 to your computer and use it in GitHub Desktop.

Select an option

Save ranjanistic/fca26b41881020dd5aed053677b6c6c0 to your computer and use it in GitHub Desktop.
const fs = require("fs");
const progfile = process.argv.find(
(arg) => arg.split(".").reverse()[0] === "math",
);
const file = fs.readFileSync(progfile);
zola = file.toString();
states = zola
.replaceAll("\n", ";")
.split(";")
.filter((x) => x.trim());
defines = states.filter((st) => st.startsWith("where "));
varmap = defines
.map((d) => d.replace("where ", ""))
.map((d) => ({ [d.split(" is ")[0]]: d.split(" is ")[1] }))
.reduce((acc, a) => ({ ...acc, ...a }));
uses = states.filter((st) => !defines.includes(st));
uses = uses.map((use) => {
Object.keys(varmap).forEach(
(key) => (use = use.replaceAll(`${key}`, `${varmap[key]}`)),
);
return use;
});
exprs = uses.filter((use) => use.includes("=") && !use.includes('"'));
exprs.map(
(expr) => (varmap[expr.split("=")[0].trim()] = eval(expr.split("=")[1])),
);
uses = uses.filter((use) => !exprs.includes(use));
prints = uses.filter((use) => use.startsWith("is "));
prints = prints
.map((print) => {
Object.keys(varmap).forEach(
(key) => (print = print.replaceAll(`${key}`, `${varmap[key]}`)),
);
return print;
})
.map((print) => print.replaceAll("is ", ""));
prints.map((print) => console.log(`${print}`));
m = y - x;
f = b * x;
where x is 4;
where b is 33;
where y is 5;
is b;
is f;
is aa;
where aa is hello world;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment