<s>
Befunge	B-Language
is	O
a	O
two-dimensional	O
stack-based	B-Language
,	O
reflective	B-Language
,	O
esoteric	O
programming	O
language	O
.	O
</s>
<s>
It	O
has	O
been	O
described	O
as	O
"	O
a	O
cross	O
between	O
Forth	B-Application
and	O
Lemmings	B-Application
"	O
.	O
</s>
<s>
Befunge	B-Language
was	O
created	O
by	O
Chris	O
Pressey	O
in	O
1993	O
for	O
the	O
Amiga	B-Device
.	O
</s>
<s>
The	O
language	O
was	O
designed	O
to	O
be	O
as	O
hard	O
to	O
compile	B-Language
as	O
possible	O
,	O
featuring	O
self-modifying	B-Application
code	I-Application
and	O
a	O
multi-dimensional	O
playfield	O
.	O
</s>
<s>
Despite	O
this	O
,	O
several	O
compilers	B-Language
have	O
been	O
written	O
for	O
the	O
language	O
.	O
</s>
<s>
The	O
original	O
Befunge-93	B-Language
specification	O
limited	O
programs	O
to	O
an	O
80x25	O
grid	O
,	O
and	O
while	O
not	O
Turing-complete	O
,	O
subsequent	O
extensions	O
like	O
Funge-98	O
expanded	O
the	O
concept	O
to	O
achieve	O
Turing	O
completeness	O
.	O
</s>
<s>
The	O
name	O
"	O
Befunge	B-Language
"	O
originated	O
from	O
a	O
typing	O
error	O
in	O
an	O
online	O
discussion	O
.	O
</s>
<s>
While	O
it	O
was	O
designed	O
to	O
be	O
difficult	O
to	O
compile	B-Language
,	O
compilers	B-Language
such	O
as	O
bef2c	O
and	O
Betty	O
have	O
managed	O
to	O
implement	O
the	O
language	O
using	O
various	O
techniques	O
.	O
</s>
<s>
Befunge	B-Language
programs	O
are	O
characterized	O
by	O
their	O
use	O
of	O
arrows	O
to	O
change	O
control	O
flow	O
,	O
and	O
they	O
can	O
produce	O
outputs	O
like	O
random	O
number	O
sequences	O
or	O
classic	O
"	O
Hello	O
,	O
World	O
!	O
"	O
</s>
<s>
The	O
language	O
was	O
originally	O
created	O
by	O
Chris	O
Pressey	O
in	O
1993	O
for	O
the	O
Amiga	B-Device
,	O
as	O
an	O
attempt	O
to	O
devise	O
a	O
language	O
which	O
is	O
as	O
hard	O
to	O
compile	B-Language
as	O
possible	O
.	O
</s>
<s>
Note	O
that	O
the	O
p	O
command	O
allows	O
for	O
self-modifying	B-Application
code	I-Application
.	O
</s>
<s>
Nevertheless	O
,	O
a	O
number	O
of	O
compilers	B-Language
have	O
subsequently	O
been	O
written	O
.	O
</s>
<s>
A	O
number	O
of	O
extensions	O
to	O
the	O
original	O
"	O
Befunge-93	B-Language
"	O
specification	O
also	O
exist	O
,	O
most	O
notably	O
Funge-98	O
,	O
which	O
extends	O
the	O
concept	O
to	O
an	O
arbitrary	O
number	O
of	O
dimensions	O
and	O
can	O
be	O
multithreaded	B-General_Concept
,	O
with	O
multiple	O
instruction	B-General_Concept
pointers	I-General_Concept
operating	O
simultaneously	O
on	O
the	O
same	O
space	O
.	O
</s>
<s>
Befunge-extensions	O
and	O
variants	O
are	O
called	O
Fungeoids	O
or	O
just	O
Funges	O
.	O
</s>
<s>
The	O
Befunge-93	B-Language
specification	O
restricts	O
each	O
valid	O
program	O
to	O
a	O
grid	O
of	O
80	O
instructions	O
horizontally	O
by	O
25	O
instructions	O
vertically	O
.	O
</s>
<s>
Program	O
execution	O
which	O
exceeds	O
these	O
limits	O
"	B-Error_Name
wraps	I-Error_Name
around	I-Error_Name
"	I-Error_Name
to	O
a	O
corresponding	O
point	O
on	O
the	O
other	O
side	O
of	O
the	O
grid	O
;	O
a	O
Befunge	B-Language
program	O
is	O
in	O
this	O
manner	O
topologically	B-Architecture
equivalent	O
to	O
a	O
torus	O
.	O
</s>
<s>
Since	O
a	O
Befunge-93	B-Language
program	O
can	O
only	O
have	O
a	O
single	O
stack	B-Application
and	O
its	O
storage	O
array	O
is	O
bounded	O
,	O
the	O
Befunge-93	B-Language
language	O
is	O
not	O
Turing-complete	O
(	O
however	O
,	O
it	O
has	O
been	O
shown	O
that	O
Befunge-93	B-Language
is	O
Turing	O
Complete	O
with	O
unbounded	O
stack	B-Application
word	O
size	O
)	O
.	O
</s>
<s>
The	O
later	O
Funge-98	O
specification	O
provides	O
Turing	O
completeness	O
by	O
removing	O
the	O
size	O
restrictions	O
on	O
the	O
program	O
;	O
rather	O
than	O
wrapping	O
around	O
at	O
a	O
fixed	O
limit	O
,	O
the	O
movement	O
of	O
a	O
Funge-98	O
instruction	B-General_Concept
pointer	I-General_Concept
follows	O
a	O
model	O
dubbed	O
"	O
Lahey-space	O
"	O
after	O
its	O
originator	O
,	O
Chris	O
Lahey	O
.	O
</s>
<s>
The	O
word	O
Befunge	B-Language
is	O
derived	O
from	O
a	O
typing	O
error	O
in	O
an	O
online	O
discussion	O
,	O
where	O
the	O
word	O
'	O
before	O
 '	O
was	O
intended	O
.	O
</s>
<s>
As	O
stated	O
,	O
the	O
design	O
goal	O
for	O
Befunge	B-Language
was	O
to	O
create	O
a	O
language	O
which	O
was	O
difficult	O
to	O
compile	B-Language
.	O
</s>
<s>
This	O
was	O
attempted	O
with	O
the	O
implementation	O
of	O
self-modifying	B-Application
code	I-Application
(	O
the	O
'	O
p	O
 '	O
instruction	O
can	O
write	O
new	O
instructions	O
into	O
the	O
playfield	O
)	O
and	O
a	O
multi-dimensional	O
playfield	O
(	O
the	O
same	O
instruction	O
can	O
be	O
executed	O
in	O
four	O
different	O
directions	O
)	O
.	O
</s>
<s>
Nevertheless	O
,	O
these	O
obstacles	O
have	O
been	O
overcome	O
,	O
to	O
some	O
degree	O
,	O
and	O
Befunge	B-Language
compilers	B-Language
have	O
been	O
written	O
using	O
appropriate	O
techniques	O
.	O
</s>
<s>
The	O
bef2c	O
compiler	B-Language
included	O
with	O
the	O
standard	O
Befunge-93	B-Language
distribution	O
uses	O
threaded	B-Application
code	I-Application
:	O
each	O
instruction	O
is	O
compiled	B-Language
to	O
a	O
snippet	O
of	O
C	O
code	O
,	O
and	O
control	O
flows	O
through	O
the	O
snippets	O
just	O
as	O
it	O
does	O
in	O
a	O
Befunge	B-Language
interpreter	O
(	O
that	O
is	O
,	O
conditionally	O
on	O
the	O
value	O
of	O
some	O
'	O
direction	O
 '	O
register	O
)	O
.	O
</s>
<s>
Note	O
that	O
the	O
bef2c	O
compiler	B-Language
is	O
not	O
correct	O
since	O
it	O
does	O
not	O
handle	O
either	O
'	O
p	O
 '	O
or	O
string	O
mode	O
,	O
but	O
it	O
would	O
not	O
be	O
impossible	O
to	O
make	O
it	O
do	O
so	O
(	O
although	O
the	O
C	O
language	O
might	O
not	O
be	O
well-suited	O
for	O
this	O
)	O
.	O
</s>
<s>
The	O
Betty	O
compiler	B-Language
,	O
for	O
example	O
,	O
treats	O
every	O
possible	O
straight	O
line	O
of	O
instructions	O
as	O
a	O
subprogram	O
,	O
and	O
if	O
a	O
'	O
p	O
 '	O
instruction	O
alters	O
that	O
subprogram	O
,	O
that	O
subprogram	O
is	O
recompiled	B-Language
.	O
</s>
<s>
This	O
is	O
an	O
interesting	O
variation	O
on	O
just-in-time	O
compilation	B-Language
,	O
and	O
it	O
results	O
in	O
a	O
much	O
better	O
advantage	O
over	O
an	O
interpreter	O
,	O
since	O
many	O
instructions	O
can	O
be	O
executed	O
in	O
native	O
code	O
without	O
making	O
intervening	O
decisions	O
on	O
the	O
'	O
direction	O
 '	O
register	O
.	O
</s>
<s>
The	O
Befunge	B-Language
instruction	B-General_Concept
pointer	I-General_Concept
begins	O
in	O
the	O
upper	O
left	O
corner	O
and	O
will	O
travel	O
to	O
the	O
right	O
if	O
not	O
redirected	O
.	O
</s>
<s>
instructions	O
send	O
the	O
instruction	B-General_Concept
pointer	I-General_Concept
in	O
random	O
cardinal	O
directions	O
until	O
the	O
pointer	O
hits	O
a	O
digit	O
,	O
pushing	O
it	O
to	O
the	O
stack	B-Application
.	O
</s>
<s>
to	O
output	O
the	O
digit	O
from	O
the	O
stack	B-Application
and	O
return	O
the	O
pointer	O
to	O
the	O
first	O
directional	O
randomiser	O
.	O
</s>
<s>
First	O
the	O
letters	O
"	O
olleH	O
"	O
are	O
pushed	O
onto	O
the	O
stack	B-Application
as	O
ASCII	B-Protocol
numbers	O
.	O
</s>
<s>
These	O
are	O
then	O
popped	O
from	O
the	O
stack	B-Application
in	O
LIFO	B-Application
order	O
and	O
output	O
as	O
text	O
characters	O
to	O
give	O
"	O
Hello	O
"	O
.	O
</s>
<s>
A	O
space	O
is	O
character	O
number	O
32	O
in	O
ASCII	B-Protocol
,	O
which	O
here	O
is	O
constructed	O
by	O
multiplying	O
4	O
and	O
8	O
,	O
before	O
being	O
output	O
as	O
text	O
.	O
</s>
<s>
in	O
a	O
similar	O
way	O
,	O
followed	O
by	O
ASCII	B-Protocol
character	I-Protocol
10	O
(	O
a	O
line	O
feed	O
character	O
,	O
moving	O
the	O
output	O
cursor	O
to	O
a	O
new	O
line	O
)	O
.	O
</s>
<s>
It	O
adds	O
the	O
ASCII	B-Protocol
character	I-Protocol
10	O
(	O
a	O
line	O
feed	O
character	O
)	O
to	O
the	O
stack	B-Application
,	O
and	O
then	O
pushes	O
"	O
!	O
dlrow	O
,	O
olleH	O
"	O
to	O
the	O
stack	B-Application
.	O
</s>
<s>
Again	O
,	O
LIFO	B-Application
ordering	O
means	O
that	O
"	O
H	O
"	O
is	O
now	O
the	O
top	O
of	O
the	O
stack	B-Application
and	O
will	O
be	O
the	O
first	O
printed	O
,	O
"	O
e	O
"	O
is	O
second	O
,	O
and	O
so	O
on	O
.	O
</s>
<s>
To	O
print	O
the	O
characters	O
,	O
the	O
program	O
enters	O
a	O
loop	O
that	O
first	O
duplicates	O
the	O
top	O
value	O
on	O
the	O
stack	B-Application
(	O
so	O
now	O
the	O
stack	B-Application
would	O
look	O
like	O
"	O
\n!dlrow	O
,	O
olleHH	O
"	O
)	O
.	O
</s>
<s>
(	O
This	O
assumes	O
a	O
compliant	O
interpreter	O
that	O
"	O
returns	O
"	O
0	O
when	O
popping	O
an	O
empty	O
stack	B-Application
.	O
)	O
</s>
<s>
When	O
it	O
goes	O
left	O
,	O
it	O
pops	O
and	O
prints	O
the	O
top	O
value	O
as	O
an	O
ASCII	B-Protocol
character	I-Protocol
.	O
</s>
<s>
It	O
then	O
duplicates	O
the	O
next	O
character	O
and	O
loops	O
back	O
to	O
the	O
"	O
_	O
"	O
test	O
,	O
continuing	O
to	O
print	O
the	O
rest	O
of	O
the	O
stack	B-Application
until	O
it	O
is	O
empty	O
and	O
so	O
the	O
next	O
value	O
popped	O
is	O
0	O
,	O
at	O
which	O
point	O
"	O
@	O
"	O
ends	O
the	O
program	O
.	O
</s>
<s>
0-9	O
Push	O
this	O
number	O
on	O
the	O
stack	B-Application
+	O
Addition	O
:	O
Pop	O
a	O
and	O
b	O
,	O
then	O
push	O
a+b	O
-	O
Subtraction	O
:	O
Pop	O
a	O
and	O
b	O
,	O
then	O
push	O
b-a	O
*	O
Multiplication	O
:	O
Pop	O
a	O
and	O
b	O
,	O
then	O
push	O
a*b	O
/	O
Integer	O
division	O
:	O
Pop	O
a	O
and	O
b	O
,	O
then	O
push	O
b/a	O
,	O
rounded	O
towards	O
0	O
.	O
</s>
<s>
Start	O
moving	O
in	O
a	O
random	O
cardinal	O
direction	O
_	O
Pop	O
a	O
value	O
;	O
move	O
right	O
if	O
value	O
=	O
0	O
,	O
left	O
otherwise	O
|	O
Pop	O
a	O
value	O
;	O
move	O
down	O
if	O
value	O
=	O
0	O
,	O
up	O
otherwise	O
"	O
Start	O
string	O
mode	O
:	O
push	O
each	O
character	O
's	O
ASCII	B-Protocol
value	I-Protocol
all	O
the	O
way	O
up	O
to	O
the	O
next	O
"	O
:	O
Duplicate	O
value	O
on	O
top	O
of	O
the	O
stack	B-Application
\	O
Swap	O
two	O
values	O
on	O
top	O
of	O
the	O
stack	B-Application
$	O
Pop	O
value	O
from	O
the	O
stack	B-Application
and	O
discard	O
it	O
.	O
</s>
<s>
Pop	O
value	O
and	O
output	O
as	O
an	O
integer	O
followed	O
by	O
a	O
space	O
,	O
Pop	O
value	O
and	O
output	O
as	O
ASCII	B-Protocol
character	I-Protocol
#	O
Bridge	O
:	O
Skip	O
next	O
cell	O
p	O
A	O
"	O
put	O
"	O
call	O
(	O
a	O
way	O
to	O
store	O
a	O
value	O
for	O
later	O
use	O
)	O
.	O
</s>
<s>
Pop	O
y	O
,	O
x	O
,	O
and	O
v	O
,	O
then	O
change	O
the	O
character	O
at	O
(	O
x	O
,	O
y	O
)	O
in	O
the	O
program	O
to	O
the	O
character	O
with	O
ASCII	B-Protocol
value	I-Protocol
v	O
g	O
A	O
"	O
get	O
"	O
call	O
(	O
a	O
way	O
to	O
retrieve	O
data	O
in	O
storage	O
)	O
.	O
</s>
<s>
Pop	O
y	O
and	O
x	O
,	O
then	O
push	O
ASCII	B-Protocol
value	I-Protocol
of	O
the	O
character	O
at	O
that	O
position	O
in	O
the	O
program	O
&	O
Ask	O
user	O
for	O
a	O
number	O
and	O
push	O
it	O
~	O
Ask	O
user	O
for	O
a	O
character	O
and	O
push	O
its	O
ASCII	B-Protocol
value	I-Protocol
@	O
End	O
program	O
(	O
space	O
)	O
No-op	O
.	O
</s>
<s>
Most	O
one-dimensional	O
programming	O
languages	O
require	O
some	O
syntactic	O
distinction	O
between	O
comment	O
text	O
and	O
source	O
code	O
although	O
that	O
distinction	O
may	O
be	O
as	O
trivial	O
as	O
Brainfuck	B-Language
's	O
rule	O
that	O
any	O
character	O
not	O
in	O
the	O
set	O
+-[]xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1,	O
.	O
</s>
<s>
Languages	O
like	O
Lisp	B-Language
and	O
Python	B-Language
treat	O
strings	O
as	O
comments	O
in	O
contexts	O
where	O
the	O
values	O
are	O
not	O
used	O
.	O
</s>
<s>
Similarly	O
,	O
in	O
Befunge	B-Language
,	O
there	O
is	O
no	O
comment	O
syntax	O
:	O
to	O
embed	O
documentation	O
in	O
the	O
code	O
,	O
the	O
programmer	O
simply	O
routes	O
the	O
control	O
flow	O
around	O
the	O
"	O
comment	O
"	O
area	O
,	O
so	O
that	O
the	O
text	O
in	O
that	O
area	O
is	O
never	O
executed	O
.	O
</s>
