Skip to content

Instantly share code, notes, and snippets.

@usysrc
Created March 17, 2014 14:03
Show Gist options
  • Save usysrc/9599696 to your computer and use it in GitHub Desktop.
Save usysrc/9599696 to your computer and use it in GitHub Desktop.
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