Instantly share code, notes, and snippets.

Embed
What would you like to do?
deadfish intepreter
-- deadfish interpreter
-- also accepts xkcd
local acc = 0
local commands = {
i = function() acc = acc + 1 end,
d = function() acc = acc - 1 end,
s = function() acc = acc * acc end,
o = function() print(tonumber(acc)) end,
}
local alts = {
x = "i", c = "o", k = "s"
}
while true do
io.write(">>")
local line = io.read("*line")
for i=1,#line do
local c = line:sub(i,i)
if commands[c] then commands[c]()
elseif alts[c] and commands[alts[c]] then commands[alts[c]]()
else
--ignore
end
if acc == -1 or acc == 256 then
acc = 0
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment