Last active
August 29, 2015 14:02
-
-
Save soccermitchy/387cd5ac17865fc2e993 to your computer and use it in GitHub Desktop.
Stack Graphing Language (graphing part not done)
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
1 {64;+}l | |
1 {26;+d}l |
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
1 {104;+}l.{105;+}l | |
2 {10;+}l.{13;+}l | |
1d2d1d |
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
1 | |
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++. | |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
2++++++++++.+++++++++++++ | |
1d2d1d |
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
stacks={} | |
current_stack=1 | |
funcs={} | |
positions={} | |
skip=0 | |
internal_hooks={ | |
char={} | |
} | |
chunk="" | |
inChunk=false | |
for i=1,10 do positions[i]=0 end | |
for i=1,10 do stacks[i]={} end | |
---------------------- | |
-- Functions -- | |
---------------------- | |
function selstack1() | |
current_stack=1 | |
end | |
function selstack2() | |
current_stack=2 | |
end | |
function selstack3() | |
current_stack=3 | |
end | |
function selstack4() | |
current_stack=4 | |
end | |
function selstack5() | |
current_stack=5 | |
end | |
function selstack6() | |
current_stack=6 | |
end | |
function selstack7() | |
current_stack=7 | |
end | |
function selstack8() | |
current_stack=8 | |
end | |
function selstack9() | |
current_stack=9 | |
end | |
function selstack10() | |
current_stack=10 | |
end | |
function add() | |
if not stacks[current_stack][positions[current_stack]] then stacks[current_stack][positions[current_stack]]=0 end | |
stacks[current_stack][positions[current_stack]]=stacks[current_stack][positions[current_stack]]+1 | |
end | |
function sub() | |
if not stacks[current_stack][positions[current_stack]] then stacks[current_stack][positions[current_stack]]=0 end | |
stacks[current_stack][positions[current_stack]]=stacks[current_stack][positions[current_stack]]-1 | |
end | |
function addpos() | |
positions[current_stack]=positions[current_stack]+1 | |
end | |
function subpos() | |
positions[current_stack]=positions[current_stack]-1 | |
end | |
function respos() | |
positions[current_stack]=1 | |
end | |
function dstack() | |
for i=0,#stacks[current_stack] do io.write(string.char(stacks[current_stack][i])) end | |
end | |
function dstackchar() | |
for i=1,#stacks[current_stack] do io.write(stacks[current_stack][i]) end | |
end | |
function beginc() | |
inChunk=true | |
chunk="" | |
local function gen_chunk(c) | |
chunk=chunk..c | |
end | |
internal_hooks.char.chunk=gen_chunk | |
end | |
function endc() | |
inChunk=false | |
internal_hooks.char.chunk=nil | |
end | |
function loopc() | |
if not chunk:match("%d;.+") then | |
error'Bad loop syntax' | |
end | |
local times,code=chunk:match("(%d+);(.+)$") | |
print(times,code) | |
for i=-0,times-1 do | |
for i=1,#code do | |
local c=code:sub(i,i) | |
if funcs[c] then | |
funcs[c]() | |
end | |
end | |
end | |
end | |
---------------------- | |
-- Command Defs. -- | |
---------------------- | |
funcs={ | |
["0"]=selstack1, | |
["1"]=selstack2, | |
["2"]=selstack3, | |
["3"]=selstack4, | |
["4"]=selstack5, | |
["5"]=selstack6, | |
["6"]=selstack7, | |
["7"]=selstack8, | |
["8"]=selstack9, | |
["9"]=selstack10, | |
["+"]=add, | |
["-"]=sub, | |
["."]=addpos, | |
[","]=subpos, | |
["r"]=respos, | |
["d"]=dstack, | |
["{"]=beginc, | |
["}"]=endc, | |
["l"]=loopc, | |
["f"]=dstackchar | |
} | |
---------------------- | |
-- Parser -- | |
---------------------- | |
function checkSkip(c) | |
if skip~=0 then | |
skip=skip-1 | |
return true | |
elseif c=="}" then | |
return false | |
elseif inChunk then | |
return true | |
end | |
return false | |
end | |
function hook_char_caller(c) | |
for k,v in pairs(internal_hooks.char) do | |
v(c) | |
end | |
end | |
function parse_line(line) -- fucking newlines, cba to add a dud command. | |
for i=1,#line do | |
c=line:sub(i,i) | |
if funcs[c] and not checkSkip(c) then | |
funcs[c]() | |
elseif inChunk then | |
hook_char_caller(c) | |
end | |
end | |
end | |
for line in io.lines(arg[1]) do parse_line(line) end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment