Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/guisupport/items.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-1999 Parsifal Software. All Rights Reserved. | |
4 * See the file COPYING for license and usage terms. | |
5 * | |
6 * items.cpp | |
7 */ | |
8 | |
9 #include "dc.h" | |
10 #include "dict.h" | |
11 #include "items.h" | |
12 #include "myalloc.h" | |
13 #include "q1glbl.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 //#define INCLUDE_LOGGING | |
23 #include "log.h" | |
24 | |
25 | |
26 state_table_dc::item::item(unsigned ln) { | |
27 // LOGSECTION("state_table_dc::item::item"); | |
28 int k = 0; | |
29 unsigned lc = 0; | |
30 unsigned *ndx = isht_dict->ndx; | |
31 int *text = isht_dict->text; | |
32 int *p; | |
33 // LOGV(ln); | |
34 // LOGV((int) text); | |
35 // LOGV((int) ndx); | |
36 while (lc <= ln) { | |
37 lc += (text[ndx[k++]]-1)/2; | |
38 } | |
39 // LOGV(lc); | |
40 // LOGV((int) p); | |
41 p = &text[ndx[--k]]; | |
42 lc -= (*p++ -1)/2; | |
43 p += 2*(first_flag = ln-lc); | |
44 state = k; | |
45 // LOGV((int) p); | |
46 rule = *p++; | |
47 index= *p; | |
48 // LOGV(rule); | |
49 // LOGV(index); | |
50 } | |
51 | |
52 unsigned state_table_dc::item::token(void) { | |
53 unsigned length; | |
54 Rule r(rule); | |
55 | |
56 length = r->length(); | |
57 if (index >= length) { | |
58 return 0; | |
59 } | |
60 //return lstptr(map_form_number[rule],tokens)[index]; | |
61 return r.token(index); | |
62 } | |
63 | |
64 int build_item_list_ok(int tn) { | |
65 LOGSECTION("build_item_list_ok"); | |
66 LOGV(tn); | |
67 LOGV(ntkns); | |
68 return tn && map_token_number[tn].non_terminal_flag; | |
69 } | |
70 | |
71 dc_ref build_item_list(int tn) { | |
72 //dc_ref window; | |
73 if (tn == 0 || !map_token_number[tn].non_terminal_flag) { | |
74 return dc_ref(); | |
75 } | |
76 | |
77 AgString head("Expansion Rules"); | |
78 AgString foot = AgString::format("T%03d: ", tn).concat(token_string(tn)); | |
79 return dc_ref(new expansion_rules_dc(tn, foot)); | |
80 } | |
81 | |
82 expansion_rules_dc::expansion_rules_dc(unsigned tn, const AgString foot) | |
83 : dc("Expansion Rules", foot), token_number(tn) | |
84 { | |
85 des->d_size.y = Token(tn)->expansionRuleList.size(); | |
86 } | |
87 | |
88 unsigned expansion_rules_dc::rule(unsigned ln) const { | |
89 return Token(token_number).expansionRule(ln); | |
90 } | |
91 | |
92 unsigned expansion_rules_dc::token(unsigned ln) const { | |
93 int rn = rule(ln); | |
94 if (map_form_number[rn].length() == 0) { | |
95 return 0; | |
96 } | |
97 return Rule(rn).token(0); | |
98 } | |
99 | |
100 void expansion_rules_dc::synchCursor(unsigned ln) const { | |
101 unsigned rn = rule(ln); | |
102 if (rn) { | |
103 set_rule_line(rn); | |
104 } | |
105 } | |
106 | |
107 void expansion_rules_dc::getLine(unsigned ln) const{ | |
108 ics(); | |
109 append_item(rule(ln), 0); | |
110 } | |
111 | |
112 int expansion_rules_dc::expansion_rules_ok(unsigned ln) { | |
113 return build_item_list_ok(token(ln)); | |
114 } | |
115 | |
116 dc_ref expansion_rules_dc::expansion_rules(unsigned ln) { | |
117 unsigned tn = token(ln); | |
118 if (tn) { | |
119 return build_item_list(token(ln)); | |
120 } | |
121 return NULL; | |
122 } | |
123 | |
124 int expansion_rules_dc::productions_ok(unsigned ln) { | |
125 return productions_window_ok(token(ln)); | |
126 } | |
127 | |
128 dc_ref expansion_rules_dc::productions(unsigned ln) { | |
129 unsigned tn = token(ln); | |
130 if (tn) { | |
131 return productions_window(token(ln)); | |
132 } | |
133 return NULL; | |
134 } | |
135 | |
136 | |
137 dc_ref expansion_rules_dc::rule_context(unsigned ln) { | |
138 unsigned rn = rule(ln); | |
139 if (rn) { | |
140 return rule_context_window(rn); | |
141 } | |
142 return NULL; | |
143 } | |
144 | |
145 int expansion_rules_dc::set_elements_ok(unsigned ln) { | |
146 unsigned tn = token(ln); | |
147 if (tn) { | |
148 return token_set_window_ok(token(ln)); | |
149 } | |
150 return 0; | |
151 } | |
152 | |
153 dc_ref expansion_rules_dc::set_elements(unsigned ln) { | |
154 unsigned tn = token(ln); | |
155 if (tn) { | |
156 return token_set_window(token(ln)); | |
157 } | |
158 return NULL; | |
159 } | |
160 | |
161 int expansion_rules_dc::usage_ok(unsigned ln) { | |
162 unsigned tn = token(ln); | |
163 return token_usage_window_ok(tn); | |
164 } | |
165 | |
166 dc_ref expansion_rules_dc::usage(unsigned ln) { | |
167 unsigned tn = token(ln); | |
168 return token_usage_window(tn); | |
169 } | |
170 | |
171 dc_ref expand_specific_item(dc_ref , int fn, int fx){ | |
172 int tn; | |
173 Rule rule(fn); | |
174 | |
175 if (fx < 0 || fx >= rule->length()) { | |
176 return dc_ref(); | |
177 } | |
178 tn = rule.token(fx); | |
179 return build_item_list(tn); | |
180 } | |
181 | |
182 static int state_table_tabs[] = {7,0}; | |
183 | |
184 void state_table_dc::getLine(unsigned ln) const { | |
185 item x(ln); | |
186 ics(); | |
187 if (x.first_flag == 0) { | |
188 apprintf("S%03d:", x.state); | |
189 } | |
190 acs('\t'); | |
191 append_item(x.rule, x.index); | |
192 } | |
193 | |
194 void state_table_dc::synchCursor(unsigned ln) const { | |
195 set_rule_line(item(ln).rule); | |
196 } | |
197 | |
198 state_table_dc::state_table_dc(void) | |
199 : dc("State Definition Table") | |
200 { | |
201 int dp = 0,k = isht_dict->nsx; | |
202 const int *ndx = (int*)isht_dict->ndx, *text = (int*)isht_dict->text; | |
203 | |
204 | |
205 tab_stops = state_table_tabs; | |
206 columnHeadTitle = "State\tCharacteristic Rules"; | |
207 while (k--) dp += (text[*ndx++]-1); | |
208 dp /=2; | |
209 ok_ptr(des); | |
210 des->d_size.y = dp; | |
211 } | |
212 | |
213 dc_ref state_table_dc::aux_trace(unsigned ln) { | |
214 return aux_trace_window(item(ln).state); | |
215 } | |
216 | |
217 int state_table_dc::expansion_rules_ok(unsigned ln){ | |
218 item x(ln); | |
219 unsigned tn = x.token(); | |
220 return build_item_list_ok(tn); | |
221 } | |
222 | |
223 dc_ref state_table_dc::expansion_rules(unsigned ln){ | |
224 item x(ln); | |
225 unsigned tn = x.token(); | |
226 if (tn == 0) { | |
227 return NULL; | |
228 } | |
229 return build_item_list(tn); | |
230 } | |
231 | |
232 int state_table_dc::keywords_ok(unsigned ln) { | |
233 return keywords_window_ok(item(ln).state); | |
234 } | |
235 | |
236 dc_ref state_table_dc::keywords(unsigned ln) { | |
237 return keywords_window(item(ln).state); | |
238 } | |
239 | |
240 int state_table_dc::previous_states_ok(unsigned ln) { | |
241 return previous_states_window_ok(item(ln).state); | |
242 } | |
243 | |
244 dc_ref state_table_dc::previous_states(unsigned ln) { | |
245 return previous_states_window(item(ln).state); | |
246 } | |
247 | |
248 int state_table_dc::productions_ok(unsigned ln) { | |
249 return productions_window_ok(item(ln).token()); | |
250 } | |
251 | |
252 dc_ref state_table_dc::productions(unsigned ln) { | |
253 return productions_window(item(ln).token()); | |
254 } | |
255 | |
256 int state_table_dc::reduction_states_ok(unsigned ln) { | |
257 item x(ln); | |
258 return reduction_states_window_ok(x.rule,x.index); | |
259 } | |
260 | |
261 dc_ref state_table_dc::reduction_states(unsigned ln) { | |
262 item x(ln); | |
263 return reduction_states_window(x.state,x.rule,x.index); | |
264 } | |
265 | |
266 dc_ref state_table_dc::rule_context(unsigned ln){ | |
267 item x(ln); | |
268 return rule_context_window(x.rule); | |
269 } | |
270 | |
271 int state_table_dc::set_elements_ok(unsigned ln) { | |
272 return token_set_window_ok(item(ln).token()); | |
273 } | |
274 | |
275 dc_ref state_table_dc::set_elements(unsigned ln) { | |
276 return token_set_window(item(ln).token()); | |
277 } | |
278 | |
279 dc_ref state_table_dc::state_expansion(unsigned ln) { | |
280 return state_expansion_window(item(ln).state); | |
281 } | |
282 | |
283 int state_table_dc::usage_ok(unsigned ln) { | |
284 return token_usage_window_ok(item(ln).token()); | |
285 } | |
286 | |
287 dc_ref state_table_dc::usage(unsigned ln) { | |
288 return token_usage_window(item(ln).token()); | |
289 } |