Created
March 17, 2014 14:03
-
-
Save usysrc/9599696 to your computer and use it in GitHub Desktop.
deadfish intepreter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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