Annotation of 43BSD/contrib/icon/src/cmd/csgen.icn, revision 1.1.1.1

1.1       root        1: #      CSGEN(1)
                      2: #
                      3: #      Generate instances of sentences defined by context-sensitive
                      4: #      grammars
                      5: #
                      6: #      Ralph E. Griswold
                      7: #
                      8: #      Last modified 4/27/83
                      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 xpairs(line) then next
                     17:       else {
                     18:          line ? (goal := move(1),move(1),count := (0 < integer(tab(0))))
                     19:          break
                     20:          }
                     21:    every 1 to count do {               #  generate sentences
                     22:       s := goal
                     23:       while upto(&ucase,s) do {                #  test for nonterminal
                     24:          if x[1] == "-t" then write(&errout,s)
                     25:                                        #  quit on deadlock
                     26:          if not(s ? replace(!xlist)) then break next
                     27:          until s ?:= replace(?xlist)   #  make replacement
                     28:          }
                     29:       write(s)
                     30:       }
                     31: end
                     32: 
                     33: #  replace left hand side by right hand side
                     34: #
                     35: procedure replace(a)
                     36:    suspend tab(find(a[1])) || (move(*a[1]),a[2]) || tab(0)
                     37: end
                     38: 
                     39: #  enter rewriting rule
                     40: #
                     41: procedure xpairs(s)
                     42:    local i, a
                     43:    initial xlist := []
                     44:    if s ? {
                     45:                                #  handle optional replication factor
                     46:       i := 1(0 < integer(tab(upto(':'))),move(1)) | 1 &
                     47:       a := [tab(find("->")),(move(2),tab(0))]
                     48:       }
                     49:    then {
                     50:       every 1 to i do put(xlist,a)
                     51:       return
                     52:       }
                     53: end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.