1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
############################################################################
#
# File: makelsys.icn
#
# Subject: Procedures to convert L-Systems to records
#
# Author: Ralph E. Griswold
#
# Date: January 23, 1999
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# These procedures coverts a list corresponding to an L-System into an
# L-System record.
#
# See lindsys.icn for documentation about format.
#
# See linden.dat for an example of input data.
#
# See also linden.icn for a graphics version.
#
############################################################################
record Lsys(name, axiom, gener, angle, comment, productions)
procedure makelsys(lst) #: make L-system from list
local line, i, s, c, symbol, rewrite
local allchars, rhs, value, spec, result
result := Lsys()
rewrite := table()
allchars := '' # cset of all rhs characters
while line := get(lst) do {
line ? {
if symbol := move(1) & ="->" then {
rhs := tab(0)
rewrite[symbol] := rhs
allchars ++:= rhs # keep track of all characters
}
else if spec := tab(upto(':')) then {
move(1)
value := tab(0)
if spec == "axiom" then allchars ++:= value
else if spec == "end" then break
/result[spec] := value
}
}
}
# At this point, we have the table to map characters, but it may lack
# mappings for characters that "go into themselves" by default. For
# efficiency in rewriting, these mappings are added.
every c := !allchars do
/rewrite[c] := c
result.productions := rewrite
return result
end
procedure readlsys(input) #: make L-system from a file
local result
result := []
while put(result, read(input))
return makelsys(result)
end
|