|P is for Practical|
Brainfunk. With Regex.by oiskuu (Hermit)
|on Dec 10, 2013 at 19:06 UTC||Need Help??|
my teacher assigned us a brainfuck interpreter. Here's what I've arrived at.
For timing and testing I have used 392quine.b. This, and some other bf programs found here.I'd say this regex based interpreter is fairly legible and uncomplicated (*cough*), though couple of snags remain.
First and foremost, the unfortunate "recursion" limit is encountered when long (but non-recursing) code is run:
It should output whatever it was fed (bf.pl itself), but goes apeshit midway through. The workaround is to use (?:(?:__)*)*; however, I find this just too disgraceful. In this thread, ikegami hints at possible upcoming fix. Well, that was four years ago, and it sure isn't fixed in v5.18.1, let alone v5.12.3. I wonder if this is solved in more recent perls?
Another annoyance is with the data sub. It can be written in several ways
The first one appears more expressive, though the array variant is no slower.
Finally, there may well be some important optimizations I've missed or somesuch. Suggestions are welcome, of course.