Created
August 7, 2020 21:32
-
-
Save lleyton/e04af69bb8bcf6d04fead0a8f192dd40 to your computer and use it in GitHub Desktop.
PenisScript
This file contains 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
local instructions = { | |
['>'] = '8=D', | |
['<'] = '8==D', | |
['+'] = '8===D', | |
['-'] = '8====D', | |
['.'] = '8=====D', | |
[','] = '8======D', | |
['['] = '8=======D', | |
[']'] = '8========D' | |
} | |
local reversed_instructions = {} | |
for i, v in pairs(instructions) do | |
reversed_instructions[v] = i | |
end | |
local function to_bf(program) | |
program = program:gsub('[^8=D]', '') | |
for i, v in pairs(reversed_instructions) do | |
program = program:gsub(i, v) | |
end | |
return program | |
end | |
local function from_bf(program) | |
program = program:gsub('[^><%+%-%.,%[%]]', '') | |
for i, v in pairs(instructions) do | |
program = program:gsub('%' .. i, v) | |
end | |
return program | |
end | |
local input = io.open(arg[2]) | |
local program = input:read("a") | |
input:close() | |
if arg[1] == 'compile' then | |
local output = io.open('out.bf', 'w') | |
output:write(to_bf(program)) | |
output:close() | |
elseif arg[1] == 'reverse' then | |
local output = io.open('out.pp', 'w') | |
output:write(from_bf(program)) | |
output:close() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fuck