Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/guisupport/stexpdc.cpp @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 * AnaGram, A System for Syntax Directed Programming | |
3 * Copyright 1993-2002 Parsifal Software. All Rights Reserved. | |
4 * See the file COPYING for license and usage terms. | |
5 * | |
6 * stexpdc.cpp | |
7 */ | |
8 | |
9 #include "dc.h" | |
10 #include "dict.h" | |
11 #include "items.h" | |
12 #include "q1glbl.h" | |
13 #include "q5.h" | |
14 #include "rule.h" | |
15 #include "stexpdc.h" | |
16 #include "stacks.h" | |
17 #include "token.h" | |
18 #include "ut.h" | |
19 #include "wm1.h" | |
20 #include "ws.h" | |
21 | |
22 | |
23 static int chain_element(int t, int f) { | |
24 //unsigned *fp; | |
25 int n; | |
26 Token token = t; | |
27 //if (x4(t,f) == 0) return 0; | |
28 if (!token.isExpansionRule(f)) return 0; | |
29 //fp = lstptr(map_token_number[t], forms); | |
30 //n = map_token_number[t].n_forms; | |
31 //n = token->n_forms; | |
32 n = token->ruleList.size(); | |
33 //while (n--) { | |
34 for (int i = 0; i < n; i++) { | |
35 //Rule fn = *fp++; | |
36 Rule fn = token.rule(i); | |
37 int tn; | |
38 if ((int) fn == f) return 1; | |
39 if (fn->length() == 0) continue; | |
40 if (xws(fn)) continue; | |
41 //tn = lstptr(map_form_number[fn], tokens)[0]; | |
42 tn = Rule(fn).token(0); | |
43 if (chain_element(tn, f)) { | |
44 return 1; | |
45 } | |
46 fws(); | |
47 } | |
48 return 0; | |
49 } | |
50 | |
51 static tsd *expand_chain(int sn, int f) { | |
52 int *list = dict_str(isht_dict, sn); | |
53 int n = (*list++ - 1)/2; | |
54 int fn, fx, k = n; | |
55 tsd *sx = init_tsd(2); | |
56 iws(); | |
57 while (k--) { | |
58 int tn; | |
59 | |
60 fn = *list++; | |
61 fx = *list++; | |
62 | |
63 if (fx >= map_form_number[fn].length()) { | |
64 continue; | |
65 } | |
66 //tn = lstptr(map_form_number[fn], tokens)[fx]; | |
67 tn = Rule(fn).token(fx); | |
68 if (chain_element(tn, f) == 0) { | |
69 continue; | |
70 } | |
71 at(sx, fn, fx); | |
72 xws(f); | |
73 k = tis(); | |
74 list = list_base; | |
75 while (k--) { | |
76 at(sx, *list++, 0); | |
77 } | |
78 rws(); | |
79 break; | |
80 } | |
81 return sx; | |
82 } | |
83 | |
84 dc_ref expansion_chain_window(int sn, int fn, int fx) { | |
85 dc_ref window; | |
86 | |
87 if (fx || fn == 0) { | |
88 return dc_ref(); | |
89 } | |
90 | |
91 const AgString foot = AgString::format("S%03d:R%03d", sn, fn); | |
92 //window = find_on_screen("Expansion Chain", foot); | |
93 //if (window) return window; | |
94 return dc_ref(new expansion_chain_dc(sn, fn, foot)); | |
95 } | |
96 | |
97 expansion_chain_dc::expansion_chain_dc(unsigned sn, unsigned rn, AgString foot) | |
98 : state_expansion_dc(sn, "Expansion Chain", foot) | |
99 { | |
100 state_number = sn; | |
101 rule_number = rn; | |
102 delete_tsd(expansion); | |
103 expansion = expand_chain(sn, rn); | |
104 //des->c_size = cursor_bar_size; | |
105 des->d_size.y = expansion->nt; | |
106 | |
107 //getWidth(); | |
108 //resize_window(); | |
109 } | |
110 | |
111 dc_ref state_expansion_window(int sn) { | |
112 //dc_ref window; | |
113 | |
114 //if (sn == 0) return dc_ref(); | |
115 const AgString foot = AgString::format("S%03d", sn); | |
116 //window = find_on_screen("State Expansion", foot); | |
117 //if (window.exists()) return window; | |
118 return dc_ref(new state_expansion_dc(sn, "State Expansion", foot)); | |
119 } | |
120 | |
121 dc_ref state_expansion_dc::aux_trace(unsigned) { | |
122 return aux_trace_window(state_number); | |
123 } | |
124 | |
125 int state_expansion_dc::expansion_chain_ok(unsigned ln) { | |
126 int fn, fx; | |
127 xtx(expansion, ln, &fn, &fx); | |
128 return fn && fx == 0; | |
129 } | |
130 | |
131 dc_ref state_expansion_dc::expansion_chain(unsigned ln) { | |
132 int fn, fx; | |
133 xtx(expansion, ln, &fn, &fx); | |
134 return expansion_chain_window(state_number, fn, fx); | |
135 } | |
136 | |
137 int state_expansion_dc::expansion_rules_ok(unsigned ln) { | |
138 return build_item_list_ok(token(ln)); | |
139 } | |
140 | |
141 dc_ref state_expansion_dc::expansion_rules(unsigned ln) { | |
142 return build_item_list(token(ln)); | |
143 } | |
144 | |
145 void state_expansion_dc::getLine(unsigned ln) const { | |
146 int rn, rx; | |
147 xtx(expansion, ln, &rn, &rx); | |
148 ics(); | |
149 append_item(rn, rx); | |
150 } | |
151 | |
152 void state_expansion_dc::synchCursor(unsigned ln) const { | |
153 int rn, rx; | |
154 xtx(expansion, ln, &rn, &rx); | |
155 if (rn) { | |
156 set_rule_line(rn); | |
157 } | |
158 } | |
159 | |
160 int state_expansion_dc::previous_states_ok(unsigned) { | |
161 return previous_states_window_ok(state_number); | |
162 } | |
163 | |
164 dc_ref state_expansion_dc::previous_states(unsigned) { | |
165 return previous_states_window(state_number); | |
166 } | |
167 | |
168 int state_expansion_dc::productions_ok(unsigned ln) { | |
169 return productions_window_ok(token(ln)); | |
170 } | |
171 | |
172 dc_ref state_expansion_dc::productions(unsigned ln) { | |
173 return productions_window(token(ln)); | |
174 } | |
175 | |
176 int state_expansion_dc::reduction_states_ok(unsigned ln) { | |
177 int fn, fx; | |
178 xtx(expansion, ln, &fn, &fx); | |
179 return reduction_states_window_ok(fn, fx); | |
180 } | |
181 | |
182 dc_ref state_expansion_dc::reduction_states(unsigned ln) { | |
183 int fn, fx; | |
184 xtx(expansion, ln, &fn, &fx); | |
185 return reduction_states_window(state_number, fn, fx); | |
186 } | |
187 | |
188 dc_ref state_expansion_dc::rule_context(unsigned ln) { | |
189 int rn, rx; | |
190 xtx(expansion, ln, &rn, &rx); | |
191 return rule_context_window(rn); | |
192 } | |
193 | |
194 int state_expansion_dc::set_elements_ok(unsigned ln) { | |
195 return token_set_window_ok(token(ln)); | |
196 } | |
197 | |
198 dc_ref state_expansion_dc::set_elements(unsigned ln) { | |
199 return token_set_window(token(ln)); | |
200 } | |
201 | |
202 state_expansion_dc::state_expansion_dc(unsigned sn, | |
203 const AgString head, | |
204 const AgString foot) | |
205 : dc(head, foot) | |
206 , expansion(expand_state(sn)) | |
207 { | |
208 state_number = sn; | |
209 //des->c_size = cursor_bar_size; | |
210 des->d_size.y = expansion->nt; | |
211 | |
212 //getWidth(); | |
213 //resize_window(); | |
214 } | |
215 | |
216 state_expansion_dc::~state_expansion_dc(void) { | |
217 //if (!clone() && (expansion != NULL)) delete_tsd(expansion); | |
218 if (expansion != NULL) { | |
219 delete_tsd(expansion); | |
220 } | |
221 } | |
222 | |
223 unsigned state_expansion_dc::token(unsigned ln) { | |
224 int fn, fx; | |
225 xtx(expansion, ln, &fn, &fx); | |
226 if (fx >= map_form_number[fn].length()) { | |
227 return 0; | |
228 } | |
229 //return lstptr(map_form_number[fn], tokens)[fx]; | |
230 return Rule(fn).token(fx); | |
231 } | |
232 | |
233 int state_expansion_dc::usage_ok(unsigned ln) { | |
234 return token_usage_window_ok(token(ln)); | |
235 } | |
236 | |
237 dc_ref state_expansion_dc::usage(unsigned ln) { | |
238 return token_usage_window(token(ln)); | |
239 } | |
240 | |
241 | |
242 | |
243 |