Category talk:ALGOL 68-l-system
Appearance
Source code
# BEGIN lsystem.incl.a68: modes and operators related to L-System evaluation #
MODE LRULE = STRUCT( CHAR symbol, STRING replacement );
MODE LSYSTEM = STRUCT( STRING axiom, FLEX[ 1 : 0 ]LRULE rules );
PRIO -> = 9; # constructs an LRULE from symbol and replacement #
OP -> = ( CHAR symbol, STRING replacement )LRULE: ( symbol, replacement );
OP -> = ( CHAR symbol, CHAR replacement )LRULE: ( symbol, replacement );
PRIO EVAL = 9; # executes the rewriting rules of l n times #
OP EVAL = ( LSYSTEM l, INT n )STRING:
BEGIN
STRING result := axiom OF l;
TO n DO
STRING next := "";
FOR s pos FROM LWB result TO UPB result DO
CHAR symbol = result[ s pos ];
BOOL found := FALSE;
FOR r pos FROM LWB rules OF l TO UPB rules OF l WHILE NOT found DO
LRULE rule = ( rules OF l )[ r pos ];
IF found := symbol = symbol OF rule THEN
next +:= replacement OF rule
FI
OD;
IF NOT found THEN next +:= symbol FI
OD;
result := next
OD;
result
END # EVAL # ;
PRIO INTERPRET = 9; # interprets the results of EVALuating an L-System #
OP INTERPRET = ( STRING results, PROC(CHAR)VOID exec )VOID:
FOR c pos FROM LWB results TO UPB results DO exec( results[ c pos ] ) OD;
# END lsystem.incl.a68 #