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
79
80
81
82
83
84
85
|
############################################################################
#
# File: lsysmap.icn
#
# Subject: Program to map L-system symbols
#
# Author: Ralph E. Griswold
#
# Date: June 18, 1998
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# This program maps the symbols in L-Systems.
#
# The following options are supported:
#
# -i s input symbols for mapping; default &ucase
# -o s output symbols for mapping; default &ucase
# -a put symbols for axiom production in alphabetical
# order (ignores -i and -o)
#
# symbol strings are given on the command line, as in
#
# lsysmap -i ABCD -o DCBA <exam.lys
#
# There is little error checking. It's possible to produce an invalid
# L-system by creating duplicate nonterminals or changing metacharacters.
#
# The program handles two-level grammars using the first axiom symbol.
#
############################################################################
#
# Links: options, strings
#
############################################################################
link options
link strings
procedure main(args)
local isyms, osyms, line, defs, axiom, i, opts, symbols, done
opts := options(args, "i:s:a")
if /opts["a"] then {
isyms := \opts["i"] | &ucase
osyms := \opts["o"] | &ucase
if *isyms ~= *osyms then
stop("*** input and output strings not of equal length")
}
defs := []
symbols := ''
while line := read() do {
put(defs, line)
line ? {
if ="axiom:" then {
if not(/axiom := move(1)) then # not first axiom
done := 1 # turn off gathering nontrminals
}
else if =\axiom & ="->" & /isyms then isyms := tab(0)
if /done & find("->") then symbols ++:= move(1)
}
}
isyms := deletec(isyms, &cset -- symbols)
isyms := ochars(isyms)
osyms := csort(isyms)
every i := 1 to *defs do {
defs[i] ?:= {
(="axiom:" || map(move(1), isyms, osyms)) |
(find("->") & map(tab(0), isyms, osyms)) |
tab(0)
}
}
every write(!defs)
end
|