Post version history/View/0.1.0 BT1

[previous] &verbar; Post version history &verbar; [next] // Read and parse entered code const fs = require("fs");

const code = fs.readFileSync("code.txt").toString.split("\n");

// Variables var logs = []; var d = ""; var olr = []; var mtr = [];

var params = []; var module = ""; var command = ""; var params = [];

const posmodules = [ "sys", "main", ] // Preinstalled modules var installed = [ "sys", "main", ];

// Configs const displayerrors = true;

// General functions function log(msg) { d = new Date; logs.push(`${d.getHours}:${d.getMinutes}:${d.getSeconds}: ${msg}`); }

function push(msg) { // out.push(msg); console.log(msg); log(`Added text ${msg} into output prompt.`); }

function dispLines { push("---"); log("Displayed some lines with displiens.") }

function error(msg) { if (displayerrors) { dispLines; push(`Error at line ${i + 1}:\n ${msg}`); log(`ERROR at line ${i + 1}: ${msg}`); dispLines; } }

// Operator helper functions function getType(msg) { if (msg == "none" || msg == "NN") { return "none"; } else if (msg.startsWith("\"") && msg.endsWith("\"")) { return "str"; } else if (msg.startsWith("'") && msg.endsWith("'")) { return "varInput"; } else if (isNaN(msg)) { return "invalid"; } else { return "int"; } }

function remvStrQuotes(msg) { return msg.substring(1,msg.length - 1); }

function requiresParams(params,params2,params3) { return "Coming soon! Sorry." }

// Single-line code function runOneLine(cur) { olr = []; if (cur.replace(" ","").length < 1) { log("Blank line has been passed over.") } else if (cur.startsWith("#")) { log("Comment has been passed over.") } else if (cur.replace(" ","").includes(".")) { params = cur.split("."); module = params[0]; command = params[1]; params.shift; params.shift; log(`Module of this line is ${module}, and command is ${command}. Length of params is ${params.length}.`)

if (installed.includes(module)) { if (module == "sys") { if (command == "print") { if (getType(params[0]) == "str") { push(remvStrQuotes(params[0])); } else if (getType(params[0]) != "varInput") { error(`Positional parameter "1" of sys.print must be type str, not the given ${getType(params[0])}`) }       } else if (command == "print-checktype") { push(`${params[0]} is a ${getType(params[0])}`); } else if (command == "clearmlr") { mlr = []; }     }    } else if (posmodules.includes(module)) { error(`Module "${module}" is not installed.`); } else { error(`Module "${module}" is not installed and doesn't exist.`); } } else { error("Unexpected undotted command."); } }

// Main loop for (i = 0; i < code.length; i++) { runOneLine(code[i]); } dispLines