Computer Science Canada Brainfuck Interpreter (Perl) |
Author: | Degensquared [ Thu Dec 18, 2008 10:33 pm ] | ||
Post subject: | Brainfuck Interpreter (Perl) | ||
An interpreter for Brainfuck that I wrote in perl as a challenge to myself. I had trouble implementing this while I was using turing, but I found that the dynamic arrays and regex really helped out. I'm looking for some critique here. What could I have done differently, what did I do well? I'm very new to perl, so if I went about certain problems in a way that could be solved much easier using some feature of perl of which I'm not aware, I'd appreciate the information. Usage: perl bfi.pl input.txt
|
Author: | wtd [ Thu Dec 18, 2008 11:45 pm ] | ||
Post subject: | RE:Brainfuck Interpreter (Perl) | ||
You could store operations as anonymous subroutine references in a hash, where indexes for the hash are the character. Something like:
|
Author: | Insectoid [ Fri Dec 19, 2008 9:00 am ] |
Post subject: | RE:Brainfuck Interpreter (Perl) |
Wow, just had a look at the brainfuck wiki. Looks like it could be fun to learn! though it would be a pain in the arse to debug... |
Author: | Degensquared [ Fri Dec 19, 2008 11:45 am ] |
Post subject: | Re: Brainfuck Interpreter (Perl) |
wtd: That sounds interesting, could you explain the syntax a little bit? Where did $a come from? Perhaps that was supposed to be $ops, which would make sense. Why does it require the -> to the anonymous sub? I thought that changing the % to a $ made it a reference to the value of whatever is at that index? Or am I confused about what the meaning of that arrow is? I'd really appreciate the clarification. insectoid: I'd suggest using the Brainfuck Machine (http://www.kacper.kwapisz.eu/index.php?i=19) if you want to do programming in Brainfuck. It has a step-through debugger and a table with the memory values. |
Author: | Insectoid [ Fri Dec 19, 2008 12:21 pm ] |
Post subject: | RE:Brainfuck Interpreter (Perl) |
No, I don't want to learn it. I just said it could be fun. The language is too odd to learn now. I might get brainfucked. |
Author: | wtd [ Fri Dec 19, 2008 2:25 pm ] | ||
Post subject: | RE:Brainfuck Interpreter (Perl) | ||
Oh, that was me mixing up decent naming with my experimentation.
%ops is the name of the hash. The % sigil becomes $ when it's accessed. As for the -> well that dereferences the subroutine references and the () calls the subroutine. |