Discussion:
Befunge-93 interpreter
(too old to reply)
Rugxulo
2010-05-28 05:41:41 UTC
Permalink
{$standard-pascal}
{$transparent-file-names}
{$case-value-checking}

{ ====================================================================

Wednesday, May 26, 2010

Befunge-93 in standard-ish Pascal -- public domain, nenies proprajxo

(GPC 20070904 via DJGPP + GCC 3.4.4)

rugxulo _AT_ gmail _DOT_ com

!! Christus Rex !!

BUGS:
= most of the examples that I tested work fine (except NEGMOD.BEF)
= random via '?' is still not implemented (how???) :-/

LINKS:
= http://catseye.tc/projects/bef.html
= http://www.esolangs.org/wiki/Befunge
= http://board.flatassembler.net/topic.php?t=10810
= #esoteric on irc.freenode.net

HISTORY:
= v1.0 : initial (pre)release

==================================================================== }


program Befunge93(input,output,example);
label 9999;
const xmax = 80; ymax = 25; stackmax=1000;
type int = integer; {longint}
var
example: text;
x, y, i, j, k, l, m, numlines, a, b, c, sp, xdelta, ydelta: int;
stack: packed array [1..stackmax] of int;
bspace: packed array [1..xmax, 1..ymax] of char;
ch, chartemp: char;
strmode: boolean;

procedure incr(var k: int); begin k := succ(k) end;
procedure decr(var l: int); begin l := pred(l) end;

procedure push(m: int); begin stack[sp] := m;
if sp > 1 then decr(sp); end;
procedure pop(var m: int); begin
if sp < stackmax then begin incr(sp); m := stack[sp]; end
else m := 0; end;

{procedure unimplemented(r: array of char);
begin writeln(r,': *** not implemented yet ***'); end;}

begin {Befunge93}

for i := 1 to stackmax do stack[i] := 0;

for j := 1 to ymax do for i := 1 to xmax do bspace[i,j] := ' ';
i := 0; j := 1; numlines := 0; sp := stackmax;

{assign(example,'example');}
reset(example);
while not eof(example) do
begin
incr(i);
if eoln(example) then
begin
read(example,chartemp); i := 0; incr(numlines); incr(j);
end
else read(example,bspace[i,j]);
end;

{for j := 1 to ymax do for i := 1 to xmax do
if i < xmax then write(bspace[i,j]) else writeln;}

x := -1; y := 0; xdelta := 1; ydelta := 0; strmode := false;


while true do begin {main loop}

x := x + xdelta; y := y + ydelta;
if x > 79 then x := 0; if y > 24 then y := 0;
if x < 0 then x := 79; if y < 0 then y := 24;

ch := bspace[x+1,y+1];


{ *************************************************** }
{if paramstr(1) = '-d' then begin
write(' x,y = ',x:2,',',y:2);
if ch <> '"' then write(' ch = "',ch,'"')
else write(' ch = ''',ch,'''');
for i := 1 to 5 do if sp+i < stackmax then write(' ',stack[sp+i]);
if strmode then writeln(' """"') else writeln; end;}
{ *************************************************** }


{for i := sp downto 1 do stack[i] := 0;}

if strmode then if ch <> '"' then push(ord(ch));

if ch = '"' then strmode := not strmode;

{writeln(' ch = ''',ch,'''');}

if not strmode then
if ch in ['0'..'9'] then push(ord(ch)-ord('0')) else
if ch in ['+','-','*','/','%','!','`','^','v','<','>','|','_','?','#',
',','.','~','&','$',':','\','g','p','"','@',' '] then

case ch of

' ': a := 0; {nop}
'"': a := 0; {already taken care of strmode}

{'0'..'9': push(ord(ch)-ord('0'));}

'.': begin pop(a); write(a:1,' '); end;
',': begin pop(a); if a=10 then writeln else write(chr(a)); end;

'v': begin xdelta := 0; ydelta := 1; end;
'^': begin xdelta := 0; ydelta := -1; end;
'<': begin xdelta := -1; ydelta := 0; end;
'>': begin xdelta := 1; ydelta := 0; end;
'#': begin {writeln('xd=',xdelta:1,'yd=',ydelta:1);}
case ydelta of -1: decr(y); 1: incr(y); 0: a := 0; end;
case xdelta of -1: decr(x); 1: incr(x); 0: a := 0; end; end;
'_': begin pop(a); ydelta := 0; if a <> 0 then xdelta := -1
else xdelta := 1; end;
'|': begin pop(a); xdelta := 0; if a <> 0 then ydelta := -1
else ydelta := 1; end;

'`': begin pop(b); pop(a); if a > b then push(1) else push(0); end;
'!': begin pop(a); if a = 0 then push(1) else push(0); end;
'\': begin pop(a); pop(b); push(a); push(b); end;
':': begin pop(a); push(a); push(a); end;
'$': pop(a);

'+': begin pop(b); pop(a); push(a + b); end;
'-': begin pop(b); pop(a); push(a - b); end;
'*': begin pop(b); pop(a); push(a * b); end;
'/': begin pop(b); pop(a); push(a div b); end;
'%': begin pop(b); pop(a); push(a mod b); end;

'~': begin read(input,chartemp); push(ord(chartemp)); end;
'&': begin read(input,a); push(a); end;

'g': begin pop(b); pop(a); c := ord(bspace[a+1,b+1]); push(c); end;
'p': begin pop(b); pop(a); pop(c); bspace[a+1,b+1] := chr(c); end;

'?': a := 0; {unimplemented('rand');}

'@': goto 9999; {exit;}

{otherwise write('ch = ',ch);}

end {case ch}
else a := 0; {write('*** unknown ch = ''',ch,''' ***');}

end; {while true do}

9999: a := 0;
end. {Befunge93}
Rugxulo
2010-05-31 22:04:50 UTC
Permalink
Hi,
Post by Rugxulo
Befunge-93 in standard-ish Pascal
Okay, here's a sed script for some non-standard Pascals (DOS). But the
examples (e.g. from BEFI package at FASM link above) have to be in CR
+LF format, so you'll have to convert them first.

#n

# ---------------------------------------------------------
# fpc -XXs -Os bef93.pas
# upx --best --lzma --all-filters bef93.exe 45,568 => 21,868 bytes
# ---------------------------------------------------------
# TP55, same for TMTPC 3.90, doesn't support Win9x LFNs
# tpc bef93.pas
# upx --best --8086 bef93.exe 5,280 => 3,603 bytes
# ---------------------------------------------------------
# tmtpc -$logo- -stub:tmt32.exe bef93.pas
# tmtpack bef93.exe 25,102 => 16,762 bytes
# ---------------------------------------------------------

/{\$/d
/program Befunge93/s/unge//
s/integer; {\(longint\)}/\1;/
/assign/{
s/{//
s/}//
s/'example'/paramstr(1)/
}
# ignore both CR and LF from .BEF file
s/\(example\)\(,chartemp\)/\1\2\2/
w bef93.pas
Rugxulo
2010-05-31 22:22:48 UTC
Permalink
Hi again,
Post by Rugxulo
Befunge-93 in standard-ish Pascal
I really should benchmark more (esp. on my 586), but here's what I've
got so far (Pentium 4 Celeron, 2.40 Ghz, WinXP SP3 machine) from a few
days ago:


v bench2.bef
^ <


GPC 20070904, DJGPP, GCC 3.4.4
gpc -s -O2 -mtune=i686 -fomit-frame-pointer --no-range-checking
runtime bef93 bench2.bef : 18.74 seconds elapsed

FPC 2.4.0, DOS/GO32v2
fpc -XXs -O2 -Oppentium4
runtime bef93 bench2.bef : 21.15 seconds elapsed

IP Pascal (demo)
pc /s (after removing "k,l,m: int")
runtime bef93 bench2.bef : 03:28.90 elapsed

ACK on DOS-Minix 2.0.4 (i386) under FreeDOS
mv bef93.pas bef93.p ; pc bef93.p -o bef93
time bef93 bench2.bef : 1:02.00 real 1:01.26 user 0.00 sys
Rugxulo
2010-06-02 09:36:49 UTC
Permalink
Hi,
Post by Rugxulo
Post by Rugxulo
Befunge-93 in standard-ish Pascal
# ignore both CR and LF from .BEF file
s/\(example\)\(,chartemp\)/\1\2\2/
w bef93.pas
A better solution (that seems to work in my tests) is apparently this
(but corrections welcome!):

if eoln(example) then
begin readln(example);
i := 0; incr(numlines); incr(j);
end

ANSI/ISO just reads in a single blank space for EOL whereas Borland-
ish ones apparently read the actual chars (#13 and #10 for DOS).
Rugxulo
2010-06-06 23:43:03 UTC
Permalink
Hi, back by popular demand (not)! ;-)
Post by Rugxulo
Befunge-93 in standard-ish Pascal -- public domain, nenies proprajxo
  = v1.0 : initial (pre)release
This one below should be better. I cleaned it up, and it should
compile out-of-the-box on most compilers. The obvious difference is
that ISO 7185 has no randomize/random, plus the way it handles cmdline
is implementation defined. Nevertheless, everything should still
(mostly) "just work" there too.

------------------------------------------------
{language=turbo}{ansic=1}{headername="p2c.h"}
{randomizename=srand(time(0));//}{randintname=rand()%6;//}

{"gpc -s -O --standard-pascal --transparent-file-names"}
{then at runtime: "--gpc-rts -n example:guesswho.bef"}

{sed -n -e "/program/s/,example//" -e "/reset(/d" -e "/ple: text/d" \
-e "s/example/input/" -e "w b-p5.pas"}

{ *) (*$M Thank you for using ISO 7185*) (* }

{ ====================================================================

Sunday, June 6, 2010 6:14pm

Befunge-93 in standard Pascal -- public domain, nenies proprajxo

preferred: GPC 20070904 (DJGPP + GCC 3.4.4)
also fixed to work: FPC, TP55, TMT, P2C, VP, IP, P5 (see sed above)
need testing again: IRIE, ALICE, ACK
test later: Vector, Javascal, Prospero

rugxulo _AT_ gmail _DOT_ com

!! Christus Rex !!

BUGS:
= TP, TMT, probably others only understand CR+LF .BEF files !!
- be sure to convert unless you want it to hang :-/
= TMT fails EDGETEST.BEF (but others don't ??)
- in fairness, even BEFI and "official" BEF do too!
- but FBBI and CCBI handle it correctly, so ...
= requires ASCII charset
- would a xlat table fix this? (I don't have EBCDIC to test!)
= B93 always expects signed 32-bit stack
- use "longint" if necessary and available (but not on GPC !)
= NEGMOD.BEF success seems to depend on the compiler
- ISO error? nobody complains, but yeah, it's unreliable
= random via '?' is still not fully implemented (how???) :-/
- probably no ISO 7185 method w/o making user seed manually
- pipe time into stdin and act on that?? (separate version?)
- use implementation defined (e.g. ptr data uninitialized)??
- note that it is just ignored, it doesn't fail !!
- hence it should still work (except for broken scripts
(SALUTON4.BEF, oops) that assume it will eventually find its
way out, which is never guaranteed!)

LINKS:
= http://catseye.tc/projects/bef.html
= http://www.esolangs.org/wiki/Befunge
= http://board.flatassembler.net/topic.php?t=10810
= #esoteric on irc.freenode.net

HISTORY:
= v1.0 : initial (pre)release
= v1.1 : minor cleanups (but still using "goto")
= v1.2 : mixed comment compatibility tricks, still needs cleanups
= v1.3 : more cleanups, put some stuff into procedures for clarity

==================================================================== }

program bef93(input,output,example);
label 9999;
const xmax = 80; ymax = 25; stackmax=1000;
type
{ *) longint = integer; (* } {ignored by non-ISO (TP-ish) compilers}
int = longint;
var
{ *) paramcount: int; (* }
example: text;
x, y, i, j, a, b, c, sp, xdelta, ydelta: int;
stack: packed array [1..stackmax] of int;
bspace: packed array [1..xmax, 1..ymax] of char;
ch, chartemp: char;
strmode: boolean;

procedure nop; begin {a := 0} end;
procedure clearstack; var i: int; begin for i := 1 to stackmax do
stack[i] := 0 end;
procedure clearbspace; var i,j: int; begin for j := 1 to ymax do
for i := 1 to xmax do bspace[i,j] := ' ' end;
procedure incr(var k: int); begin k := k+1 end;
procedure decr(var l: int); begin l := l-1 end;
procedure push(m: int); begin stack[sp] := m;
if sp > 1 then decr(sp); end;
procedure pop(var m: int); begin
if sp < stackmax then begin incr(sp);
m := stack[sp]; end else m := 0; end;
procedure delta(xd, yd: int); begin
xdelta := xd; ydelta := yd; end;
{ *) procedure randomize; begin end; (* }
{ *) function random(r: int):int; begin r := r; random := 0; end; (* }
{ *) procedure assign(var e:text; i:int);begin reset(e);i:=i end; (* }
{ *) function paramstr(n:int):int; begin n:=n; paramstr:=1; end; (* }
{ *) procedure halt; begin goto 9999 end; (* }
{procedure debug; var i: int; begin
write(' x,y = ',x:2,',',y:2);
if ch <> '"' then write(' ch = "',ch,'"')
else write(' ch = ''',ch,'''');
for i := 1 to 4 do if sp+i < stackmax then write(' ',
stack[sp+i]);
if strmode then writeln(' """"') else writeln; end;}
{procedure showbspace; var i,j: int; begin
for j := 1 to ymax do for i := 1 to xmax+1 do
if i < xmax+1 then write(bspace[i,j]) else writeln;
halt end;}

begin {bef93}

randomize; clearstack; clearbspace; i := 0; j := 1; sp := stackmax;

{ *) paramcount := 1; (* }
if paramcount = 0 then halt else assign(example,paramstr(1));

reset(example);
while not eof(example) do begin incr(i);
if eoln(example) then begin
readln(example); i := 0; incr(j); end
else read(example,bspace[i,j]);
end;

{ make sure we read the file in correctly}
{ this wraps and looks wrong on 80x25, redirect to file}
{ can't skimp, I need to show it all !!!}
{showbspace;}

x := -1; y := 0; delta(1,0); strmode := false;

while true do begin {main loop}

{wrap if necessary}
x := x + xdelta; y := y + ydelta;
if x > xmax-1 then x := 0; if y > ymax-1 then y := 0;
if x < 0 then x := xmax-1; if y < 0 then y := ymax-1;

ch := bspace[x+1,y+1];

{debug;}

{ this is slow yet shouldn't be needed}
{for i := sp downto 1 do stack[i] := 0;}

if strmode then if ch <> '"' then push(ord(ch));

if ch = '"' then strmode := not strmode;

if not strmode then
if ch in ['0'..'9'] then push(ord(ch)-ord('0')) else
if ch in ['+','-','*','/','%','!','`','^','v','<','>','|','_','?','#',
',','.','~','&','$',':','\','g','p','"','@',' '] then

case ch of

' ': nop;
'"': nop;

'.': begin pop(a); write(a:1,' '); end;
',': begin pop(a); if a=10 then writeln else write(chr(a)); end;

'^': delta(0,-1);
'v': delta(0,1);
'<': delta(-1,0);
'>': delta(1,0);
'#': begin case ydelta of -1: decr(y); 1: incr(y); 0: nop; end;
case xdelta of -1: decr(x); 1: incr(x); 0: nop; end; end;
'_': begin pop(a); if a <> 0 then delta(-1,0) else delta(1,0); end;
'|': begin pop(a); if a <> 0 then delta(0,-1) else delta(0,1); end;

'`': begin pop(b); pop(a); if a > b then push(1) else push(0); end;
'!': begin pop(a); if a = 0 then push(1) else push(0); end;
'\': begin pop(a); pop(b); push(a); push(b); end;
':': begin pop(a); push(a); push(a); end;
'$': pop(a);

'+': begin pop(b); pop(a); push(a + b); end;
'-': begin pop(b); pop(a); push(a - b); end;
'*': begin pop(b); pop(a); push(a * b); end;
'/': begin pop(b); pop(a); push(a div b); end;
'%': begin pop(b); pop(a); push(a mod b); end;

'~': begin read(input,chartemp); push(ord(chartemp)); end;
'&': begin read(input,a); push(a); end;

'g': begin pop(b); pop(a); c := ord(bspace[a+1,b+1]); push(c); end;
'p': begin pop(b); pop(a); pop(c); bspace[a+1,b+1] := chr(c); end;

'?': begin a := random(4)+1; case a of 0: nop; 1: delta(0,-1);
2: delta(0,1); 3: delta(-1,0); 4: delta(1,0); end end;
'@': halt;
{otherwise write(' ch = ''',ch,'''');}

end {case ch}
else nop; {write('*** unknown ch = ''',ch,''' ***');}
end; {while true do}

9999:
end. {bef93}
Rugxulo
2010-06-28 17:59:09 UTC
Permalink
Hi, back again, figured some minor improvements were worth reposting.
(Besides, not much traffic here otherwise.)
Hi, back by popular demand (not)!    ;-)
-------------------

{language=turbo}{ansic=1}{headername="p2c.h"}
{randomizename=srand(time(0));//}{randintname=rand()%6;//}

{"gpc -s -O --classic-pascal --transparent-file-names"}
{then at runtime: "--gpc-rts -n example:guesswho.bef"}

{sed -n -e "s/t,example)/t)/" -e "s/example: txt;//" \
-e "s/example/input/g" -e "s/reset([^)][^)]*);*//" \
-e "/^.sed/,/bef93\.pas/d" -e "w b-p5.pas" bef93.pas}

{ *) (*$M Thank you for using ISO 7185*) (* }

{ ====================================================================

Monday, June 28, 2010 12:20pm

Befunge-93 in standard Pascal -- public domain, nenies proprajxo

preferred: GPC 20070904 (DJGPP + GCC 3.4.4)
also fixed to work: FPC, TMT390, TP55, VP21, IP, ACK, IRIE, P2C
needs minor fixes: P5, ALICE, Vector, Canterbury, PTOC, PTC
test later: Prospero

rugxulo _AT_ gmail _DOT_ com

!! Christus Rex !!

BUGS:
= IP's 2005 demo limits to 200 lines (even comments!)
- just strip these useless lines and then it'll work
= TP, TMT, probably others only understand CR+LF .BEF files !!
- use the loadfixedbeffile routine (or else it hangs on *nix LF)
= TMT fails EDGETEST.BEF (but others don't ??)
- in fairness, even BEFI and "official" BEF do too!
- but "official" FBBI and CCBI handle it correctly, so ...
= requires ASCII charset
- would a xlat table fix this? (I don't have EBCDIC to test!)
= B93 always expects signed 32-bit stack
- use "longint" if necessary and available (but not on GPC !)
- "gp --uses=system -D__BP_TYPE_SIZES__" if not --classic
= NEGMOD.BEF success seems to depend on the compiler
- ISO error? nobody complains, but yeah, it's unreliable
= random via '?' is still not fully implemented (how???) :-/
- probably no ISO 7185 method w/o making user seed manually
- pipe time into stdin and act on that?? (separate version?)
- use implementation defined (e.g. ptr data uninitialized)??
- note that it is just ignored, it doesn't fail !!
- hence it should still work (except for broken scripts
(SALUTON4.BEF, oops) that assume it will eventually find its
way out, which is never guaranteed!)
= p2c 1.21a2 (1993) dislikes $ifdef directives (sigsegv)
- 1.20.1 accepts it fine, however
- BTW, don't forget to set P2C_HOME if needed
= TP55 dislikes incompatible compiler directives (error)
- others are smarter and ignore 'em
= ptoc only outputs C++ for "-turbo" due to varstrings
- still possible to use C but needs reset(example,'example')
or manually adjusting C src to use argv[1], etc.
- note that it does read mixed comments, unlike most
= ptc is tough to compile, esp. too hard for me in its
Pascal version, but it (mostly) works too after tweaks
- in particular, assumes "int rewind"; try the fseek patches
= newp2ada 2008 doesn't work yet, but I'm considering it
- at minimum, it needs "stubedit p2ada.exe minstack=8m" first

LINKS:
= http://catseye.tc/projects/bef.html
= http://www.esolangs.org/wiki/Befunge
= http://board.flatassembler.net/topic.php?t=10810
= #esoteric on irc.freenode.net

HISTORY:
= v1.0 : initial (pre)release
= v1.1 : minor cleanups (but still using "goto")
= v1.2 : mixed comment compatibility tricks, still needs cleanups
= v1.3 : more cleanups, put some stuff into procedures for clarity
= v1.4 : (very rough, pseudo-) LFN support for TP55 (default off)
= v1.5 : more tweaks, esp. re: *nix LFs for TP55 and TMT390
= v1.6 : fixed P5 sed hack, more compatibility notes
= v1.7 : removed "goto" (except in "halt" emulation)

==================================================================== }

program bef93(input,output,example);
{uses LFNhack;} (* TP 5.5 *)
{uses WinCRT;} (* VP 2.1, works in Win 3.1/Win32s if not UPX'd! *)
{ *) label 9999; (* }
const xmax = 80; ymax = 25; stackmax=1000;
type
{ *) longint = integer; (* } {ignored by non-ISO (TP-ish) compilers}
int = longint;
txt = text; {file of char;} {latter only for TP or TMT}
var
{ *) paramcount: int; (* }
example: txt; strmode: boolean; ch, chartemp: char;
x, y, i, j, a, b, c, sp, xdelta, ydelta: int;
stack: packed array [1..stackmax] of int;
bspace: packed array [1..xmax, 1..ymax] of char;

{ *) procedure inc(var k: int); begin k := k+1 end; (* }
{ *) procedure dec(var l: int); begin l := l-1 end; (* }
{ *) procedure randomize; begin end; (* }
{ *) function random(r: int):int; begin r:=r+1;random := -1;end; (* }
{ *) procedure assign(var e:txt; i:int);begin reset(e);i:=i end; (* }
{ *) procedure close(var e:txt);begin reset(e) end; (* }
{ *) function paramstr(n:int):int; begin n:=n; paramstr:=1; end; (* }
{ *) procedure halt; begin goto 9999 end; (* }

procedure nop; begin {a := 0} end;
procedure clearstack; var i: int; begin for i := 1 to stackmax do
stack[i] := 0 end;
procedure clearbspace; var i,j: int; begin for j := 1 to ymax do
for i := 1 to xmax do bspace[i,j] := ' ' end;
procedure push(m: int); begin stack[sp] := m;
if sp > 1 then dec(sp); end;
procedure pop(var m: int); begin
if sp < stackmax then begin inc(sp);
m := stack[sp]; end else m := 0; end;
procedure delta(xd, yd: int); begin
xdelta := xd; ydelta := yd; end;
procedure loadbeffile; begin while not eof(example) do begin inc(i);
if eoln(example) then begin readln(example); i := 0;
inc(j); end else read(example,bspace[i,j]); end; end;

{
procedure debug; var i: int; begin
write(' x,y = ',x:2,',',y:2); if ch <> '"' then
write(' ch = "',ch,'"') else write(' ch = ''',ch,'''');
for i := 1 to 4 do if sp+i < stackmax then write(' ',stack[sp+i]);
if strmode then writeln(' """"') else writeln; end;
procedure showbspace; var i,j: int; begin
for j := 1 to ymax do for i := 1 to xmax+1 do
if i < xmax+1 then write(bspace[i,j]) else writeln; halt end;
procedure clearusedstack; begin for i := sp downto 1 do
stack[i] := 0 end;
procedure loadfixedbeffile; begin
while not eof(example) do begin inc(i); read(example,ch);
if (ord(ch)=13) or (ord(ch)=10) then begin i := 0; if ord(ch)=10
then inc(j) end else bspace[i,j] := ch end end;
}

begin {bef93}

randomize; clearstack; clearbspace;

i := 0; j := 1; sp := stackmax;

{ *) paramcount := 1; (* }
if paramcount = 0 then halt else assign(example,paramstr(1));

reset(example); loadbeffile; close(example);

(* make sure we read the whole file in correctly
this wraps and looks wrong on 80x25, redirect to file
can't skimp, I need to show it all !!! *)
{showbspace;}

x := -1; y := 0; delta(1,0); strmode := false;

repeat {main loop}

(* wrap if necessary *)
x := x + xdelta; y := y + ydelta;
if x > xmax-1 then x := 0; if y > ymax-1 then y := 0;
if x < 0 then x := xmax-1; if y < 0 then y := ymax-1;

ch := bspace[x+1,y+1];

{debug;}

(* this is slow yet shouldn't be needed *)
{clearusedstack;}

if strmode then if ch <> '"' then push(ord(ch));

if ch = '"' then strmode := not strmode;

if not strmode then
if ch in ['0'..'9'] then push(ord(ch)-ord('0')) else
if ch in ['+','-','*','/','%','!','`','^','v','<','>','|','_','?','#',
',','.','~','&','$',':','\','g','p','"','@',' '] then

case ch of

' ': nop;
'"': nop;

'.': begin pop(a); write(a:1,' '); end;
',': begin pop(a); if a=10 then writeln else write(chr(a)); end;

'^': delta(0,-1);
'v': delta(0,1);
'<': delta(-1,0);
'>': delta(1,0);
'#': begin case ydelta of -1: dec(y); 1: inc(y); 0: nop; end;
case xdelta of -1: dec(x); 1: inc(x); 0: nop; end; end;
'_': begin pop(a); if a <> 0 then delta(-1,0) else delta(1,0); end;
'|': begin pop(a); if a <> 0 then delta(0,-1) else delta(0,1); end;

'`': begin pop(b); pop(a); if a > b then push(1) else push(0); end;
'!': begin pop(a); if a = 0 then push(1) else push(0); end;
'\': begin pop(a); pop(b); push(a); push(b); end;
':': begin pop(a); push(a); push(a); end;
'$': pop(a);

'+': begin pop(b); pop(a); push(a + b); end;
'-': begin pop(b); pop(a); push(a - b); end;
'*': begin pop(b); pop(a); push(a * b); end;
'/': begin pop(b); pop(a); push(a div b); end;
'%': begin pop(b); pop(a); push(a mod b); end;

'~': begin read(chartemp); push(ord(chartemp)); end;
'&': begin read(a); push(a); end;

'g': begin pop(b); pop(a); c := ord(bspace[a+1,b+1]); push(c); end;
'p': begin pop(b); pop(a); pop(c); bspace[a+1,b+1] := chr(c); end;

'?': begin a := random(4)+1; case a of 0: nop; 1: delta(0,-1);
2: delta(0,1); 3: delta(-1,0); 4: delta(1,0); end end;
'@': nop; {halt;}
{otherwise write(' ch = ''',ch,'''');}

end {case ch}
else nop; {write('*** unknown ch = ''',ch,''' ***');}
until (not strmode) and (ch = '@');

{ *) 9999: (* }
end. {bef93}
Rugxulo
2010-07-06 16:44:24 UTC
Permalink
Oops, made a silly mistake.
        -e "s/example/input/g" -e "s/reset([^)][^)]*);*//" \
"*)" accidentally ends the "{sed" comment (in ISO 7185 mode only),
which is not what you want. Workaround is putting '[' and ']' around
the ')' after the '*' :

-e "s/reset([^)][^)]*[)];*//" \

It's so trivial that I almost didn't think it was worth mentioning,
but better safe than sorry. ;-)

Loading...