I made this around midnight and I still don’t know why but, …
Bad Lang is a 100 line long interpreter (Also inspiried by bf)
It uses character <>{?}.,: and numbers to work
Small explaination on what they do:
How to use:
Example:
local BadLang = require(game.ReplicatedStorage.BadLang)
local input = [[
{?97>}.,
{?97>}{?97<}:,
]]
BadLang.run(input) -- Runs the input
Syntax:
> add 1 to pointer value
< subtract 1 from pointer value
. print out as ascii char
{ start of loop
} end of loop
? keyword for how long to loop should go (Example {?2>.} - Runs 2 times)
, reset pointer value to 0
: print out pointer value
You can test it right now:
Or edit it:
Src
--[[
How to use:
Example:
local BadLang = require(game.ReplicatedStorage.BadLang)
local input = ""
{?97>}.,
{?97>}{?97<}:,
""
BadLang.run(input) -- Runs the input
Syntax:
> add 1 to pointer value
< subtract 1 from pointer value
. print out as ascii char
{ start of loop
} end of loop
? keyword for how long to loop should go (Example {?2>.} - Runs 2 times)
, reset pointer value to 0
: print out pointer value
]]--
local vm = {}
local function addToTable(v, t)
t[#t + 1] = v
end
function vm.run(text: string)
local out = vm.lex(text)
local p = 0
vm.parse(out, p)
end
function vm.lex(text): {string}
local split = string.split(text, "")
local out = {}
for index, token in pairs(split) do
if (token == ">") then addToTable("add", out) end
if (token == "<") then addToTable("sub", out) end
if (token == ".") then addToTable("print", out) end
if (token == "{") then addToTable("loop-begin", out) end
if (token == "}") then addToTable("loop-stop", out) end
if (token == "?") then addToTable("loop-end-when", out) end
if (token == ",") then addToTable("reset", out) end
if (token == ":") then addToTable("print-raw", out) end
if (out[index] == nil) then addToTable(token, out) end
end
return out
end
function vm.parse(out, p): number
local pointer = p
for index, token in pairs(out) do
if (token == "add") then pointer += 1 end
if (token == "sub") then pointer -= 1 end
if (token == "reset") then pointer = 0 end
if (token == "print") then print(string.char(pointer)) end
if (token == "print-raw") then print(pointer) end
if (token == "loop-begin") then
local maxThrough = 0
if (out[index + 1] == "loop-end-when") then
local num_string = ""
for i, t in pairs(out) do
if (i >= index + 2) then
if (tonumber(out[i]) ~= nil) then num_string ..= t else
break
end
end
end
num_string = string.gsub(num_string, " ", "")
local num = tonumber(num_string)
local success = num ~= nil
if (success) then
maxThrough = num
else
error("No number after '?'.")
end
else
maxThrough = math.huge
end
local loop_out = {}
local begin_add = false
for i, t in pairs(out) do
if (i == index + 3) then
begin_add = true
end
if (t == "loop-stop") then break end
if (begin_add == true) then
addToTable(t, loop_out)
end
end
-- Loop through
local through = 0
while (through < maxThrough - 1) do
pointer = vm.parse(loop_out, pointer)
through += 1
end
end
end
return pointer
end
return vm