Rugxulo
2010-01-13 06:12:00 UTC
Well, I'm new here, and I don't really know Pascal at all, but since
I've barely squeaked out something (and it's better than the spam, at
least), I'll post it here. Yes, I know, it's not really useful yet.
Feel free to improve / explain / suggest!
http://en.wikipedia.org/wiki/Befunge
http://board.flatassembler.net/topic.php?t=10810
=======================================
{$define DEBUG}
{$standard-pascal} (* well, striving to be ... *)
(*********************************************
buggy, VERY incomplete, depends on ASCII
I don't grok Pascal yet!!
"echo 98*.@ >example" -> 72 (or ',' -> 'H')
rugxulo _AT_ gmail _DOT_ com
*********************************************)
program Befunge(input,output,example);
label 9999; (* "sed -e '/9999/s//adios/' *.pas | less" *)
const
bsize = 2000; (* 80*25 for B93 *)
maxstack = 1000; (* reasonable??? *)
type
line = array [1..80] of char;
string = packed array [1..20] of char;
var
i: integer;
bspace: array [1..bsize] of char;
bstack: array [1..maxstack] of integer;
example: text;
procedure debugmsg(chr: string);
begin
{$ifdef DEBUG}
writeln; writeln(chr);
{$endif}
end;
begin
debugmsg('*** Begin ***');
reset(example);
for i := 1 to bsize do
begin
if not eof(example) then
begin
bspace[i] := example^;
get(example);
end;
end;
for i := 1 to 5 do
begin
if bspace[i] in ['0'..'9'] then
bstack[i] := ord(bspace[i])-ord('0')
else
begin
case bspace[i] of
'+': bstack[5] := bstack[i-2] + bstack[i-1];
'-': bstack[5] := bstack[i-2] - bstack[i-1];
'*': bstack[5] := bstack[i-2] * bstack[i-1];
'/': bstack[5] := bstack[i-2] div bstack[i-1];
'%': bstack[5] := bstack[i-2] mod bstack[i-1];
'.': write(bstack[5]:1);
',': write(chr(bstack[5]));
'@': goto 9999; (* empty statement also accepted *)
end;
end;
end;
9999:
debugmsg('*** End ***');
end.
I've barely squeaked out something (and it's better than the spam, at
least), I'll post it here. Yes, I know, it's not really useful yet.
Feel free to improve / explain / suggest!
http://en.wikipedia.org/wiki/Befunge
http://board.flatassembler.net/topic.php?t=10810
=======================================
{$define DEBUG}
{$standard-pascal} (* well, striving to be ... *)
(*********************************************
buggy, VERY incomplete, depends on ASCII
I don't grok Pascal yet!!
"echo 98*.@ >example" -> 72 (or ',' -> 'H')
rugxulo _AT_ gmail _DOT_ com
*********************************************)
program Befunge(input,output,example);
label 9999; (* "sed -e '/9999/s//adios/' *.pas | less" *)
const
bsize = 2000; (* 80*25 for B93 *)
maxstack = 1000; (* reasonable??? *)
type
line = array [1..80] of char;
string = packed array [1..20] of char;
var
i: integer;
bspace: array [1..bsize] of char;
bstack: array [1..maxstack] of integer;
example: text;
procedure debugmsg(chr: string);
begin
{$ifdef DEBUG}
writeln; writeln(chr);
{$endif}
end;
begin
debugmsg('*** Begin ***');
reset(example);
for i := 1 to bsize do
begin
if not eof(example) then
begin
bspace[i] := example^;
get(example);
end;
end;
for i := 1 to 5 do
begin
if bspace[i] in ['0'..'9'] then
bstack[i] := ord(bspace[i])-ord('0')
else
begin
case bspace[i] of
'+': bstack[5] := bstack[i-2] + bstack[i-1];
'-': bstack[5] := bstack[i-2] - bstack[i-1];
'*': bstack[5] := bstack[i-2] * bstack[i-1];
'/': bstack[5] := bstack[i-2] div bstack[i-1];
'%': bstack[5] := bstack[i-2] mod bstack[i-1];
'.': write(bstack[5]:1);
',': write(chr(bstack[5]));
'@': goto 9999; (* empty statement also accepted *)
end;
end;
end;
9999:
debugmsg('*** End ***');
end.