in reply to Inline::Brainfck

Change: fixed incorrect code.

Bah. I just discovered this thread which includes a Brainfuck interpreter and a link to another Inline::Brainfuck module. Mine isn't redundant however because it has more features and uses the cool source filtering abilities of recent versions of perl. (Now standard in 5.8.0) It also integrates better into perl IMHO as you can assign brainfuck code to a variable etc.

I'm working this up into a proper CPAN module but before I do so, I need some advice. I would like to add some optimization i.e right now

+++++
becomes
P++; P++; P++; P++; P++;
when it should be
P += 5;
etc. What would be a good way of doing that with just regexes?

--
જલધર

Replies are listed 'Best First'.
Re: Re: Inline::Brainfck
by RMGir (Prior) on Aug 29, 2002 at 12:47 UTC
    First, let me say you're a sick, sick being for thinking of this. Good work! :)

    Change the line that reads

    $code =~ s/\+/P++; /g;
    To read:
    $code =~ s/(\++)/"P+=".length($1).";" /eg;
    You can probably do the same for \-, I'd think:
    $code =~ s/(\-+)/"P-=".length($1).";" /eg;
    By the way, wouldn't + become P++, and not $Inline::Brainfuck::p++? Maybe I'm reading your filter wrong...

    I'm guessing the same technique would apply to the < and > filters, too.
    --
    Mike

    Edit: By the way, I frontpaged this thread, THEN he posted a question I could answer. Normally, I wouldn't front page a thread I'm going to participate in.
    Edit 2: Made node title more firewall friendly

      Change the line that reads

      $code =~ s/\+/P++; /g;
      To read:
      $code =~ s/(\++)/"P+=".length($1).";" /eg;


      Ah I think I forgot the e when I tried this before. Thanks.


      By the way, wouldn't + become P++, and not $Inline::Brainfuck::p++?


      Yes you're right.

      --
      જલધર