Skip to content

Latest commit

 

History

History
240 lines (154 loc) · 5.9 KB

Brainfuck.pod

File metadata and controls

240 lines (154 loc) · 5.9 KB

������

Acme::Brainfuck - perl��潟�若�����������莨若�障�����Brainfuck

网�荀�

#!/usr/bin/env perl
use Acme::Brainfuck;

print 'Hello world!', chr ++++++++++. ; 

茯㋛�

Brainfuck is about the tiniest Turing-complete programming language you can get. A language is Turing-complete if it can model the operations of a Turing machine--an abstract model of a computer defined by the British mathematician Alan Turing in 1936. A Turing machine consists only of an endless sequence of memory cells and a pointer to one particular memory cell. Yet it is theoretically capable of performing any computation. With this module, you can embed Brainfuck instructions delimited by whitespace into your perl code. It will be translated into Perl as parsed. Brainfuck has just just 8 instructions (well more in this implementation, see "Extensions to ANSI Brainfuck" below.) which are as follows

Brainfuck��壔����ユ���櫝�純�ʋ�����絨������������ャ�若�ŝ�潟�医����������㏍�違�í��荐�茯���̹�∫�c�������� ������荐�茯���������ャ�若�ŝ�潟�違����激�� --1936綛眼����怨�純�勖�医⑥���Alan Turing��˨����c� 絎�臂í����������潟�潟����ャ�若�帥�勖�処院��≪�����-- ��勖��篏������≪����������с�������翫���������� 荐�茯���壔����ャ�若�ŝ�潟�医�������с����������������������ャ�若�ŝ�潟�違����激�潟�壔����♂����̥���� ��<�≪�ŝ�祉�˨�勰�c�ŝ��������������筝���ゃ�勉�<�≪�ŝ�祉�˨��腓冴�������ゃ�潟�帥�����������罕���������������� ��������������勉����激�潟�壔����í����ŝ�潟�潟����ャ�若�粋��膊���勐��茵�������茫������˨�壠櫝�純�с�������� �����勉�≪�吾�ャ�若�˨��篏帥����違�������ŝ�����perl��潟�若����勌賢��˨��腥榊�純�у�阪����������� Brainfuck��巡擦���������莨若����������������壔����若�鴻��������Perl��̥浸荐潟����������� Brainfuck��壔�������c��8�����勐�巡擦��������ゃ�������ŝ�勉��鐚������勐�巡擦������紊������勉������� ��ゃ����⓾�壠��菴違��"Extensions to ANSI Brainfuck"��������с�勉����Ǎ����� ��������壚札筝���勐��������

��巡擦

+ Increment鐚����膊�鐚�

Increase the value of the current memory cell by one.

�憜����勉�<�≪�ŝ�祉�˨��1������������

- Decrement鐚�羝�膊�鐚�

Decrease the value of the current memory cell by one.

�憜����勉�<�≪�ŝ�祉�˨�����1綣�������

> Forward鐚������駕��

Move the pointer to the next memory cell.

�����ゃ�潟�帥��罨<�勉�<�≪�ŝ�祉�˨�̥Щ������������

< Back鐚�緇���駕��

Move the pointer to the previous memory cell.

�����ゃ�潟�帥�������勉�<�≪�ŝ�祉�˨�̥Щ������������

, Input鐚���ュ��鐚�

Read a byte from Standard Input and store it in the current memory cell.

罔�羣���ュ�������������ゃ�����茯㏍�粋昭��帥���憜����勉�<�≪�ŝ�祉�˨�˩��絖����������

. Output鐚���阪��鐚�

Write the value of the current memory cell to standard output.

�憜����勉�<�≪�ŝ�祉�˨�勐�ゃ��罔�羣���阪�������吾����冴�����

[ Loop鐚�膵違��菴����鐚�

If the value of the current memory cell is 0, continue to the cell after the next ']'.

�憜����勉�<�≪�ŝ�祉�˨�勐�ゃ��0��с�������ŝ�����罨<��']'��勐�������勉�祉�˨�����膓����������

] Next鐚�罨<�醐��

Go back to the last previous '['.

��翫�����'['�����祉�����

ANSI Brainfuck��吾�勖�≦宍

This implementation has extra instructions available. In order to avoid such terrible bloat, they are only available if you use the verbose pragma like so:

�����勉�≪�吾�ャ�若�˨�勐��茖���с�虁申�����勐�巡擦�����ñ����с�������������勉�������ŝ�蚊�í����∞���� ���綣泣����帥��������������篁ヤ����勉��������verbose�����í�違�����篏帥�c����翫����˨�勉� ��ñ���櫝�純�˨�ŝ�c�⓾�����鐚�

use Acme::Brainfuck qw/verbose/;

The extra instructions are:

菴遵����勐�巡擦鐚�

~ Reset

Resets the pointer to the first memory cell and clear all memory cells.

�����ゃ�潟�帥����������勉�<�≪�ŝ�祉�˨�̥舟�����ŝ����������<�≪�ŝ�祉�˨�������⓾�壔�ŝ�≪��������

# Peek

Prints the values of the memory pointer and the current memory cell to STDERR. See also "Debugging" below.

��<�≪�ŝ����ゃ�潟�帥�������括憜����勉�<�≪�ŝ�祉�˨�勐�ゃ��罔�羣������í�若����阪����������� 筝�荐����"Debugging"��������с�勉��������

�����������

By using the debug pragma like this:

篁ヤ����勉��������debug�����í�違�����篏帥��鐚�

use Acme::Brainfuck qw/debug/;

you can dump out the generated perl code. (Caution: it is not pretty.) The key to understanding it is that the memory pointer is represented by $p, and the memory array by @m Therefore the value of the current memory cell is $m[$p].

���������������perl��潟�若����������潟����с�����鐚�羈���澾���������夌矯藝���с�壔�ŝ��鐚���� �����勉����潟��������茹c�������泣�壔����<�≪�ŝ����ゃ�潟�帥��$p��ц;�����������<�≪�ʒ��������@m�� 茵������������������������������������c�⓾���憜����勉�<�≪�ŝ�祉�˨�勐�ゃ��$m[$p]�����ŝ�����

��祉����

Each sequence of Brainfuck instructions becomes a Perl block and returns the value of the current memory cell.

Brainfuck��巡擦��勰�c�ŝ����壔�����������Perl��勉����㏍����壔����ŝ�������������☎憜���� ��<�≪�ŝ�祉�˨�勐�ゃ��菴�������

箴�

JABH

#!/usr/bin/env perl
use Acme::Brainfuck;
print "Just another ";
++++++[>++++++++++++++++<-]>
++.--
>+++[<++++++>-]<.>[-]+++[<------>-]<
+.-
+++++++++.---------
++++++++++++++.--------------
++++++.------
>+++[<+++++++>-]<.>[-]+++[<------->-]<
+++.---
+++++++++++.-----------
print " hacker.\n";

Countdown

#!/usr/bin/env perl
use strict;
use Acme::Brainfuck qw/verbose/;

print "Countdown commencing...\n";
++++++++++[>+>+<<-]
>>+++++++++++++++++++++++++++++++++++++++++++++++<<
++++++++++[>>.-<.<-]
print "We have liftoff!\n";

Reverse

#!/usr/bin/env perl
use Acme::Brainfuck qw/verbose/;

while(1)
{
  print "Say something to Backwards Man and then press enter: ";
  +[->,----------]<
  print 'Backwards Man says, "';
  [+++++++++++.<]<
  print "\" to you too.\n";
  ~
}

Math

#!/usr/bin/env perl
use Acme::Brainfuck;
use strict;
use warnings;

my $answer = +++[>++++++<-]> ;

print "3 * 6 = $answer \n";

�����若�吾�с�

1.1.1 Apr 06, 2004

篏����

Jaldhar H. Vyas E<lt>jaldhar@braincells.comE<gt>

茗�莨�

Urban Mueller - Brainfuck��勛����帥�勤Κ

Damian Conway - ��喝�����腟吟�����絅�絋�絅�紊ñ����勰����帥�˨�障��perl�����祉�c�⓾�����������

Marco Nippula <http://www.hut.fi/~mnippula/> - �����勉�≪�吾�ャ�若�˨� ��������ゃ����勉�潟�若����壠充���brainfuck.pl��̥�掩�ャ��������

Mr. Rock - http://www.cydathria.com/bf/��х����眼��������Brainfuck�����ャ�若����ŝ�≪�˨�� ��㋞�������⓾����������泣�潟����˨�勉�������ゃ����壔����������̥�掩�ャ��������

���篏�罔í����í�ゃ�祉�潟�

Copyright (c) 2004, Consolidated Braincells Inc.
Licensed with no warranties under the Crowley Public License:

"Do what thou wilt shall be the whole of the license."

���羆���勖⓲������������茵���������� ��壔�������í�ゃ�祉�潟�鴻�勐����⓾����ŝ��������