Piznium public source code/Actual code

Latest change to code: 19 March 2022 9:07 UTC+7 logs = {} errorCount = 0 enableStrictMode = false allowUnifiedType = false showErrors = true

possibleModules = {} installedModules = {} vars = {}

function log(message) table.insert(logs,message) end

function error(message) log(" " .. message) if showErrors == true then print("Error at line (UNKNOWN):\n " .. message) -- "line (UNKNOWN)" temporary end end

function splitStr(inputstr,sep) local t = {} for str in string.gmatch(inputstr,"([^"..sep.."]+)") do   table.insert(t, str) end return t end

function tableLength(table) local length = 0 for i in pairs(table) do   length = length + 1 end return length end

function solveStandaloneLine(decl) -- temporary - probably all broken right now, and not used right now local splitted = splitStr(decl," ") if splitted[2] == "=" then -- Variable declaration vars[splitted[1]] = vars[splitted[3]] else return false -- It is a function! end end

function displayTable(table) -- For testing uses, also this assumes the data of all items in a table are strings io.write("{") local lenOfTable = tableLength(table) for i in pairs(table) do   if i == lenOfTable then io.write("\"" .. table[i] .. "\"") else io.write("\"" .. table[i] .. "\",") end end io.write("}") end

-- Operator solver (temporary, this just supports basic ones, no "and" "or")

function solveBasicOperator(given) local toSolve = splitStr(given," ") -- Spaces do matter in operators local oper = toSolve[2] if oper == "==" then -- Equal to   return toSolve[1] == toSolve[3] elseif oper == "<" then -- Less than return toSolve[1] < toSolve[3] elseif oper == ">" then -- More than return toSolve[1] > toSolve[3] elseif oper == "<=" then -- Less than or equal to   return toSolve[1] <= toSolve[3] elseif oper == ">=" then -- More than or equal to   return toSolve[1] >= toSolve[3] elseif oper == "~=" then -- Roughly equal to (== but case insensitive) return string.lower(toSolve[1]) == string.lower(toSolve[3]) end -- "or" ("||") and "and" ("|&") not included as this is just for basic ones, or and and are used to seperate -- This only solves things that return bools, not basic arithmetics end

-- Basic arithmetics solver function solveArithExpr(given) return load("return " .. given) -- temporary end

-- Piznium indice getter test function getIndiceData(toget) local splitted = splitStr(toget,"[") splitted[2] = string.sub(splitted[2],1,-2) return splitted end

-- Number detector function tableContains(table, element) for i in pairs(table) do   if table[i] == element then return true end end return false end

local zeroToNine = {"0","1","2","3","4","5","6","7","8","9"}

function verifyNumber(number) local gotSoFar = {} local thisChar = "" local decimalCount = 0 for i = 1, #number do   thisChar = string.sub(number,i,i) if tableContains(zeroToNine,thisChar) then table.insert(gotSoFar,"pass") elseif thisChar == "." then if decimalCount > 0 then table.insert(gotSoFar,"decimalTooMany") else table.insert(gotSoFar,"decimal") end decimalCount = decimalCount + 1 else table.insert(gotSoFar,"fail") end end return gotSoFar end

function isValidNumber(number) return verifyNumber(number) -- It's coming soon so yeah (temporary) end

-- Data storing system functions test function getByStored(toget) local firstChar = string.sub(toget,1,1) local otherChars = string.sub(toget,2,-1) if firstChar == "n" then return {"str",otherChars,"Normal string","stringLike"} elseif firstChar == "f" then return {"fstr",otherChars,"Formatted string","stringLike"} elseif firstChar == "u" then return {"unif",otherChars,"Unified value","stringLike"} elseif toget == "g-" then return {"gnric","null","Null","normalGeneric"} elseif toget == "g?" then return {"gnric","unk","Unknown value","normalGeneric"} elseif toget == "g0" then return {"gnric","nnull","Null (numeric)","numeric"} elseif toget == "g8" then return {"gnric","inf","Infinity","numeric"} elseif toget == "gn" then return {"bool","neu","Neutral","boolGeneric"} elseif toget == true then return {"bool","true","True","boolGeneric"} elseif toget == false then return {"bool","false","False","boolGeneric"} elseif isValidNumber(toget) == "w" then return {"num",toget,"Number","numericWhole"} elseif isValidNumber(toget) == "d" then return {"num",toget,"Number","numericDecimal"} else return "invalid" end -- Function returns a table -- First item = what type is it -- Second item = what data it has -- Third item = display name for ui elements -- Fourth item = group/more information end

-- Comment and unneeded space removal function removeUnneededSpaces(funcAsString) -- Removes indents and trailing spaces, which if not removed could cause some issues return string.gsub(funcAsString,"^%s*(.-)%s*$", "%1") end

function charPosition(given,need) return splitStr(string.find(given,need),"   ")[1] end

function positionOfComment(funcAsString) if string.find(funcAsString,"#") then return charPosition(funcAsString,"#") else return 0 end end

function removeComment(funcAsString) local commentPos = positionOfComment(funcAsString) if commentPos == 0 then return funcAsString else return string.sub(funcAsString,1,commentPos - 1) end end

-- Normal function splitter/param getter function splitFuncLowerer(table) for i in pairs(table) do   table[i] = string.lower(table[i]) end end

function splitFunc(funcAsString) local splitted = splitStr(funcAsString,"(") splitted[2] = string.sub(splitted[2],1,-2)  local params = splitStr(splitted[2],",")  splitted = splitStr(splitted[1],".")  local module = "Main"  local command = ""  if tableLength(splitted) == 1 then    command = splitted[1]  else    module = splitted[1]    command = splitted[2]  end  table.remove(splitted,1)  table.remove(splitted,1)  return {string.lower(module),string.lower(command),splitFuncLowerer(splitted),params,module,command,splitted} -- params doesnt need to be lowered so its just 7 items end

function runNormalFunc(funcAsString) -- "func" in here refers to "FUNCtion" -- Get data of function (vars intentionally not local) gotFuncData = splitFunc(removeUnneededSpaces(removeComment(funcAsString))) module = gotFuncData[1] command = gotFuncData[2] params = gotFuncData[4]

-- Now actually run if module == "main" then if command == "print" then end else error("Unknown module \"" .. gotFuncData[5] .. "\".") end end

-- Main loop function runPizniumCode(codeToRun) for thisLine in pairs(codeToRun) do   runNormalFunc(codeToRun[thisLine]) end end

-- Define the code and actually run it (finally!) local code = { "MANowIN.hay" }

runPizniumCode(code)