Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
52
Task/Execute-Brain----/Phix/execute-brain----.phix
Normal file
52
Task/Execute-Brain----/Phix/execute-brain----.phix
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
procedure bfi(string pgm)
|
||||
sequence jumptable = repeat(0,length(pgm)),
|
||||
loopstack = {},
|
||||
data = repeat(0,10) -- size??
|
||||
integer skip = 0, ch, loopstart, pc, dp
|
||||
--
|
||||
-- compile (pack/strip comments and link jumps)
|
||||
--
|
||||
for i=1 to length(pgm) do
|
||||
ch = pgm[i]
|
||||
switch ch do
|
||||
case '[': loopstack = append(loopstack,i-skip);
|
||||
pgm[i-skip] = ch;
|
||||
case ']': loopstart = loopstack[$];
|
||||
loopstack = loopstack[1..-2];
|
||||
jumptable[i-skip] = loopstart;
|
||||
jumptable[loopstart] = i-skip;
|
||||
fallthrough
|
||||
case '+','-','<','>',',','.': pgm[i-skip] = ch;
|
||||
default: skip += 1
|
||||
end switch
|
||||
end for
|
||||
if length(loopstack) then ?9/0 end if
|
||||
pgm = pgm[1..-1-skip]
|
||||
|
||||
--
|
||||
-- main execution loop
|
||||
--
|
||||
pc = 1
|
||||
dp = 1
|
||||
while pc<=length(pgm) do
|
||||
ch = pgm[pc]
|
||||
switch ch do
|
||||
case '>': dp += 1 if dp>length(data) then dp = 1 end if
|
||||
case '<': dp -= 1 if dp<1 then dp = length(data) end if
|
||||
case '+': data[dp] += 1
|
||||
case '-': data[dp] -= 1
|
||||
case ',': data[dp] = getc(0)
|
||||
case '.': puts(1,data[dp])
|
||||
case '[': if data[dp]=0 then pc = jumptable[pc] end if
|
||||
case ']': if data[dp]!=0 then pc = jumptable[pc] end if
|
||||
default: ?9/0
|
||||
end switch
|
||||
pc += 1
|
||||
end while
|
||||
end procedure
|
||||
|
||||
constant bf="++++++++[>++++[>++>++++>+++>+<<<<-]>++>->+>>+[<]<-]>>.>>.+.<.>>.<<<++.>---------.>------.<----.++++++++.>>+.>++.+++."
|
||||
constant fb="++++++++[>++++[>++>++++>+++>+<<<<-]>++>->+>>+[<]<-]>>.>>.+.<.>>.<<<+++.>---.>------.++++++++.<--.>>+.>++.+++.,"
|
||||
|
||||
bfi(bf)
|
||||
bfi(fb)
|
||||
Loading…
Add table
Add a link
Reference in a new issue