|
|
1.1 root 1: # CSGEN
2: #
3: # Generate instances of sentences defined by context-sensitive
4: # grammars
5: #
6: # Ralph E. Griswold
7: #
8: # Last modified 8/7/85
9: #
10:
11: global xlist
12:
13: procedure main(x)
14: local line, goal, count, s
15: while line := read() do # read in grammar
16: if line[1] == "#" then next
17: else if xpairs(line) then next
18: else {
19: line ? (goal := move(1),move(1),count := (0 < integer(tab(0))))
20: break
21: }
22: if /count then stop("no goal specification")
23: every 1 to count do { # generate sentences
24: s := goal
25: while upto(&ucase,s) do { # test for nonterminal
26: if x[1] == "-t" then write(&errout,s)
27: # quit on deadlock
28: if not(s ? replace(!xlist)) then break next
29: until s ?:= replace(?xlist) # make replacement
30: }
31: write(s)
32: }
33: end
34:
35: # replace left hand side by right hand side
36: #
37: procedure replace(a)
38: suspend tab(find(a[1])) || (move(*a[1]),a[2]) || tab(0)
39: end
40:
41: # enter rewriting rule
42: #
43: procedure xpairs(s)
44: local i, a
45: initial xlist := []
46: if s ? {
47: # handle optional replication factor
48: i := 1(0 < integer(tab(upto(':'))),move(1)) | 1 &
49: a := [tab(find("->")),(move(2),tab(0))]
50: }
51: then {
52: every 1 to i do put(xlist,a)
53: return
54: }
55: end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.