|
|
1.1 root 1:
2:
3:
4: RSG(1) Icon Program Library RSG(1)
5:
6:
7:
8: NNNNAAAAMMMMEEEE
9: rsg - generate random sentences
10:
11: SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
12: rrrrssssgggg [----llll _n] [----llll _n] [----tttt]
13:
14: DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
15: _R_s_g generates randomly selected sentences from a grammar
16: specified by the user.
17:
18: The following options may appear in any order:
19:
20: ----ssss _n Set the seed for random generation to _n. The default
21: seed is 0.
22:
23: ----llll _n Terminate generation if the number of symbols remaining
24: to be processed exceeds _n. There is no default limit.
25:
26: ----tttt Trace the generation of sentences. Trace output goes to
27: standard error output.
28:
29: _R_s_g works interactively, allowing the user to build, test,
30: modify, and save grammars. Input to _r_s_g consists of various
31: kinds of specifications, which can be intermixed:
32:
33: _P_r_o_d_u_c_t_i_o_n_s define nonterminal symbols in a syntax similar
34: to the rewriting rules of BNF with various alternatives con-
35: sisting of the concatenation of nonterminal and terminal
36: symbols.
37:
38: _G_e_n_e_r_a_t_i_o_n _s_p_e_c_i_f_i_c_a_t_i_o_n_s cause the generation of a speci-
39: fied number of sentences from the language defined by a
40: given nonterminal symbol.
41:
42: _G_r_a_m_m_a_r _o_u_t_p_u_t _s_p_e_c_i_f_i_c_a_t_i_o_n_s cause the definition of a
43: specified nonterminal or the entire current grammar to be
44: written to a given file.
45:
46: _S_o_u_r_c_e _s_p_e_c_i_f_i_c_a_t_i_o_n_s cause subsequent input to be read from
47: a specified file.
48:
49: In addition, any line beginning with #### is considered to be a
50: comment, while any line beginning with ==== causes the rest of
51: that line to be used as a prompt to the user whenever _r_s_g is
52: ready for input (there normally is no prompt). A line con-
53: sisting of a single ==== stops prompting.
54:
55: PPPPrrrroooodddduuuuccccttttiiiioooonnnnssss
56: Examples of productions are:
57:
58: <expr>::=<term>|<term>+<expr>
59: <term>::=<element>|<element>*<term>
60:
61:
62:
63: Version 5.9 The University of Arizona - 5/16/83 1
64:
65:
66:
67:
68:
69:
70: RSG(1) Icon Program Library RSG(1)
71:
72:
73:
74: <element>::=x|y|z|(<expr>)
75:
76: Productions may occur in any order. The definition for a
77: nonterminal symbol can be changed by specifying a new pro-
78: duction for it.
79:
80: There are a number of special devices to facilitate the
81: definition of grammars, including eight predefined, built-in
82: nonterminal symbols:
83:
84: symbol definition
85: <<<<llllbbbb>>>> <<<<
86: <<<<rrrrbbbb>>>> >>>>
87: <<<<vvvvbbbb>>>> ||||
88: <<<<nnnnllll>>>> newline
89: <<<<>>>> empty string
90: <<<<&&&&llllccccaaaasssseeee>>>> any single lowercase letter
91: <<<<&&&&uuuuccccaaaasssseeee>>>> any single uppercase letter
92: <<<<&&&&ddddiiiiggggiiiitttt>>>> any single digit
93:
94: In addition, if the string between a <<<< and >>>> begins and ends
95: with a single quotation mark, that construction stands for
96: any single character between the quotation marks. For exam-
97: ple,
98:
99: <'xyz'>
100:
101: is equivalent to
102:
103: x|y|z
104:
105: Finally, if the name of a nonterminal symbol between the <<<<
106: and >>>> begins with ????, the user is queried during generation
107: to supply a string for that nonterminal symbol. For example,
108: in
109:
110: <expr>::=<term>|<term>+<expr>|<?expr>
111:
112: if the third alternative is encountered during generation,
113: the user is asked to provide a string for <<<<eeeexxxxpppprrrr>>>>.
114:
115: GGGGeeeennnneeeerrrraaaattttiiiioooonnnn SSSSppppeeeecccciiiiffffiiiiccccaaaattttiiiioooonnnnssss
116: A generation specification consists of a nonterminal symbol
117: followed by a nonnegative integer. An example is
118:
119: <expr>10
120:
121: which specifies the generation of 10 <<<<eeeexxxxpppprrrr>>>>s. If the integer
122: is omitted, it is assumed to be 1. Generated sentences are
123: written to standard output.
124:
125:
126:
127:
128:
129: Version 5.9 The University of Arizona - 5/16/83 2
130:
131:
132:
133:
134:
135:
136: RSG(1) Icon Program Library RSG(1)
137:
138:
139:
140: GGGGrrrraaaammmmmmmmaaaarrrr OOOOuuuuttttppppuuuutttt SSSSppppeeeecccciiiiffffiiiiccccaaaattttiiiioooonnnnssss
141: A grammar output specification consists of a nonterminal
142: symbol, followed by ---->>>>, followed by a file name. Such a
143: specification causes the current definition of the nontermi-
144: nal symbol to be written to the given file. If the file is
145: omitted, standard output is assumed. If the nonterminal sym-
146: bol is omitted, the entire grammar is written out. Thus,
147:
148: ->
149:
150: causes the entire grammar to be written to standard output.
151:
152: SSSSoooouuuurrrrcccceeee SSSSppppeeeecccciiiiffffiiiiccccaaaattttiiiioooonnnnssss
153: A source specification consists of @@@@ followed by a file
154: name. Subsequent input is read from that file. When an end
155: of file is encountered, input reverts to the previous file.
156: Input files can be nested.
157:
158: DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
159: Syntactically erroneous input lines are noted, but ignored.
160:
161: Specifications for a file that cannot be opened are noted
162: and treated as erroneous.
163:
164: If an undefined nonterminal symbol is encountered during
165: generation, an error message that identifies the undefined
166: symbol is produced, followed by the partial sentence gen-
167: erated to that point. Exceeding the limit of symbols remain-
168: ing to be generated as specified by the ----llll option is handled
169: in similarly.
170:
171: CCCCAAAAVVVVEEEEAAAATTTTSSSS
172: Generation may fail to terminate because of a loop in the
173: rewriting rules or, more seriously, because of the progres-
174: sive accumulation of nonterminal symbols. The latter problem
175: can be identified by using the ----tttt option and controlled by
176: using the ----llll option. The problem often can be circumvented
177: by duplicating alternatives that lead to fewer rather than
178: more nonterminal symbols. For example, changing
179:
180: <expr>::=<term>|<term>+<expr>
181:
182: to
183:
184: <expr>::=<term>|<term>|<term>+<expr>
185:
186: increases the probability of selecting <<<<tttteeeerrrrmmmm>>>> from 1/2 to
187: 2/3. See the second reference listed below for a discussion
188: of the general problem.
189:
190: SSSSEEEEEEEE AAAALLLLSSSSOOOO
191: Griswold, Ralph E. and Madge T. Griswold. _T_h_e _I_c_o_n
192:
193:
194:
195: Version 5.9 The University of Arizona - 5/16/83 3
196:
197:
198:
199:
200:
201:
202: RSG(1) Icon Program Library RSG(1)
203:
204:
205:
206: _P_r_o_g_r_a_m_m_i_n_g _L_a_n_g_u_a_g_e, Prentice-Hall, Inc., Englewood Cliffs,
207: New Jersey, 1983. pp. 211-219, 301-302.
208:
209: Wetherell, C. S. ``Probabilistic Languages: A Review and
210: Some Open Questions'', _C_o_m_p_u_t_e_r _S_u_r_v_e_y_s, Vol. 12, No. 4
211: (1980), pp. 361-379.
212:
213: AAAAUUUUTTTTHHHHOOOORRRR
214: Ralph E. Griswold
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261: Version 5.9 The University of Arizona - 5/16/83 4
262:
263:
264:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.