38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/inline-ook.rb', line 38
def ook(a = nil)
if a
s = (Ook.stack || []).join
raise "Ook? Ook? Ook?" unless s.size.even?
h = {
".?" => "a[i+=1]||=0;",
"?." => "a[i-=1]||=0;",
".." => "a[i]+=1;",
"!!" => "a[i]-=1;",
".!" => "a[i]=$stdin.getc;",
"!." => "putc(a[i]);",
"!?" => "while(a[i]>0);",
"?!" => "end;",
}
c = "a=[i=0];"
s.scan(/../) { c << (h[$&] || raise("Ook? Ook?")) }
eval c
Ook::Stacks.delete(Thread.current)
end
:ook
end
|