Debian Codegraph @

demo/animal.rexx

raw
1 #!/usr/bin/env regina
2 /* Written by Stig Hemmer <[email protected]> */
3
4 parse arg infile .
5 if infile\='' then
6 do while lines(infile)>0
7 interpret linein(infile) ;
8 end
9 else
10 node = 'an elephant'
11
12 do until left(answer,1) = 'N'
13 where = 'NODE'
14 finished = 0
15 do while finished = 0
16 if symbol(where'.Y')='VAR' then do
17 say value(where)
18 pull answer
19 if left(space(answer),1) = 'N' then
20 where = where'.N'
21 else
22 where = where'.Y'
23 end; else do
24 finished = 1;
25 say 'Did you think of 'value(where)'?'
26 pull answer
27 if left(answer,1) = 'Y' then
28 say 'Good!'
29 else do
30 say 'Hmmm, what did you think of?'
31 parse pull newanimal
32 say 'Give me a question that separates between 'newanimal' from',
33 value(where)':'
34 parse pull quest
35 say 'And what is the answer for 'newanimal'?'
36 pull answer
37 answer = space(answer)
38 if left(answer,1) = 'Y' then do
39 interpret where'.N =' where
40 interpret where'.Y = newanimal'
41 interpret where '= quest'
42 end; else do
43 interpret where'.Y =' where
44 interpret where'.N = newanimal'
45 interpret where '= quest'
46 end
47 end
48 end
49 end
50 say 'Another play?'
51 pull answer
52 answer = space(answer)
53 end
54
55 say 'File to save in (leave empty if you don''t want to save)?'
56 parse pull filename
57 if filename\='' then do
58 call lineout filename,, 1
59 signal on notready
60 call dump 'NODE'
61 end
62
63 exit 0
64
65 dump: procedure expose filename node node.
66 parse arg arg
67 if symbol(arg)='VAR' then do
68 call lineout filename, arg'="'insulate(value(arg))'"'
69 call dump arg'.Y'
70 call dump arg'.N'
71 end
72 return ;
73
74 insulate:
75 parse arg string
76 pos = -1
77 do until pos=0
78 pos = pos('"', string, pos+2)
79 if (pos>0) then
80 string = left(string,pos-1) || '""' || substr(string,pos+1)
81 end
82 return string
83
84 notready:
85 say 'error while dumping to file; dumping terminated'
86 exit 1
87