1 define
2 {
3 NUMSYM = 256
4 }
5 type pos
6 {
7 byte state
8 byte afunc
9 byte retstate
10 }
11 /*type r
12 {
13 arr of str
14 }*/
15 global
16 {
17 arr res[0,$NUMSYM] of pos
18 uint cres = 0
19 uint pres = 0
20 uint mres = 0
21 arr arbeg of str
22 hash names
23 uint main
24 // arr ar of arr of str
25 }
26
27 operator pos = ( pos l, r )
28 {
29 l.state = r.state
30 l.afunc = r.afunc
31 l.retstate = r.retstate
32 return l
33 }
34
35 method pos.getpos( str s )
36 {
37 uint i
38 arr ar of str
39 s.split( ar, '/', /*$SPLIT_EMPTY |*/ $SPLIT_NOSYS )
40 if *ar
41 {
42 if (ar[0])[0] =='_'
43 {
44 this.state = names[ar[0]]
45 }
46 else
47 {
48 this.state = str2int( ar[0] )
49 if this.state != 255 && this.state
50 {
51 this.state += pres
52 }
53 }
54 this.afunc = 0
55 this.retstate = 0
56 if *ar > 1
57 {
58 this.afunc = str2int( ar[1] )
59 if *ar > 2
60 {
61 this.retstate = str2int( ar[2] )
62 if this.retstate != 255 && this.retstate
63 {
64 this.retstate += pres
65 }
66 }
67 }
68 }
69 }
70
71 func proc( str s, uint beg )
72 {
73 uint i, j
74 arr ar of str
75 pos p,pd
76
77 s.split( ar, ',', $SPLIT_EMPTY | $SPLIT_NOSYS /*| $SPLIT_QUOTE*/ )
78 if beg
79 {
80 i=0
81 res.expand( $NUMSYM )
82 pd.getpos( ar[1] )
83 /*i=0
84 print( ?(i,",","") + ar[i] )
85 i=1
86 print( ?(i,",","") + ar[i] )*/
87 fornum j=0, $NUMSYM
88 {
89 res[cres,j] = pd
90 }
91 p.state = cres+1
92 //res[cres,0] = p
93 fornum i=2, *ar
94 {
95 p = pd
96 p.getpos(ar[i])
97 //print( ?(i,",","") + ar[i] )
98 fornum j=0, *arbeg[i]
99 {
100 res[cres, uint((arbeg[i])[j])] = p
101 }
102 }
103 cres++
104
105 }
106 else
107 {
108 arbeg.cut( 0 )
109 arbeg.expand( *ar )
110 if ar[0] == "_main" {
111 main = 1
112 mres = cres
113 //cres = 0
114 }
115
116 names[ar[0]] = cres+1
117
118 i=0
119 print( ?(i,",","") + ar[i] )
120 i=1
121 print( ?(i,",","") + ar[i] )
122 fornum i=2, *ar
123 {
124 print( ?(i,",","") + ar[i] )
125 arbeg[i].setlen(0)
126 if (ar[i])[0] == 0x27
127 {
128 arbeg[i].appendch((ar[i])[1])
129 }
130 elif (ar[i])[0] == 'q'
131 {
132 arbeg[i].appendch( 0x27 )
133 }
134 elif (ar[i])[0] == 's'
135 {
136 arbeg[i].appendch(0x20)
137 arbeg[i].appendch(0x09)
138 arbeg[i].appendch(0x0D)
139 arbeg[i].appendch(0x0A)
140 }
141 }
142 print( "\n" )
143 }
144 }
145
146
147 func tblget<main>
148 {
149 str s, curs
150 uint i, j, beg = 0
151 uint state = 0
152
153 s.read( "sp.txt" )
154 while i < *s
155 {
156 switch state
157 {
158 case 0
159 {
160 if s[i]=='(': state = 1
161 elif s[i]=='-': state = 2
162 else
163 {
164 i--
165 state = 3
166 }
167 }
168 case 1
169 {
170 if s[i]==')': state = 2
171 }
172 case 2
173 {
174 if s[i]==0x0A
175 {
176 state = 0
177 beg = 0
178 pres = cres
179 }
180 }
181 case 3
182 {
183 if s[i] == 0x0A
184 {
185 state = 0
186 proc( curs, beg )
187 beg = 1
188 curs.clear()
189 }
190 else
191 {
192 curs.appendch( s[i])
193 }
194 }
195 }
196 i++
197 }
198 str a
199 print( "\( cres ) \( mres )\n" )
200 fornum i=0, cres
201 {
202 fornum j=0, $NUMSYM
203 {
204 if res[i,j].state && res[i,j].state !=255
205 {
206 if res[i,j].state > mres
207 {
208 res[i,j].state -= mres
209 }
210 else
211 {
212 res[i,j].state += cres-mres
213 }
214 }
215 if res[i,j].retstate && res[i,j].retstate !=255
216 {
217 if res[i,j].retstate > mres
218 {
219 res[i,j].retstate -= mres
220 }
221 else
222 {
223 res[i,j].retstate += cres-mres
224 }
225 }
226 }
227 }
228 res.insert( 0, (cres-mres)*$NUMSYM )
229 //mres+1
230 fornum i = 0, cres-mres
231 {
232 fornum j= 0, $NUMSYM
233 {
234 res[i,j]=res[i + cres,j]
235 }
236 }
237 res.del( cres*$NUMSYM, (2*cres-mres)*$NUMSYM )
238 /*
239 fornum i=0, *res/$NUMSYM
240 {
241 fornum j=0, 10
242 {
243 a.clear()
244 int2str( a, "%x ", res[i,j].state )
245 print( a )
246 }
247 print( "\n" )
248 }
249 */
250 res.abuf.write("sp.tbl")
251 a.clear()
252 fornum j=0, 255
253 {
254 a@" "
255 if j >= 0x20 : a.appendch( j )
256 else : a@" "
257 }
258 a@"\n"
259 fornum i=0, *res/$NUMSYM
260 {
261 fornum j=0, 255
262 {
263 //a.clear()
264 int2str( a, "%2x", res[i,j].state )
265 //print( a )
266 }
267 a@"\n"
268 }
269 a.write( "spt.txt")
270 getch()
271 }