comparison anagram/guisupport/ftpardc.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 * ftpardc.cpp
7 */
8
9 #include "arrays.h"
10 #include "bpe3.h"
11 #include "conflicttrc.h"
12 #include "data.h"
13 #include "dc.h"
14 #include "dict.h"
15 #include "items.h"
16 #include "ftpardc.h"
17 #include "q1a.h"
18 #include "stexpdc.h"
19 #include "tracedc.h"
20 #include "ws.h"
21
22 //#define INCLUDE_LOGGING
23 #include "log.h"
24
25
26 dc::MenuOption *FtParserDc::auxTable[] = {
27 &dc::auxiliaryTraceOptionInstance,
28 &dc::expansionRulesOptionInstance,
29 &dc::keywordsOptionInstance,
30 &dc::previousStatesOptionInstance,
31 &dc::productionsOptionInstance,
32 &dc::setElementsOptionInstance,
33 &dc::stateDefinitionOptionInstance,
34 &dc::stateExpansionOptionInstance,
35 &dc::tokenUsageOptionInstance,
36 NULL
37 };
38
39 dc::MenuOption *FtParserReductionDc::auxTable[] = {
40 &dc::expansionRulesOptionInstance,
41 &dc::productionsOptionInstance,
42 &dc::setElementsOptionInstance,
43 &dc::tokenUsageOptionInstance,
44 NULL
45 };
46
47 int FtParserReductionDc::reduction_menu_tabs[] = { 0 };
48
49 dc::MenuOption *TokenMenuDc::auxTable[] = {
50 &dc::expansionRulesOptionInstance,
51 &dc::productionsOptionInstance,
52 &dc::setElementsOptionInstance,
53 &dc::tokenUsageOptionInstance,
54 NULL
55 };
56
57 static int tokenMenuTabs[] = {6,15,0};
58 TokenMenuDc::TokenMenuDc(FtParser &p, unsigned ln)
59 : parser(p)
60 {
61 LOGSECTION("TokenMenuDc::TokenMenuDc");
62 LOGV(ln);
63 unsigned stackDepth = parser.stateStack.size();
64 FtParser::State state;
65 if (ln >= stackDepth) {
66 state = parser.state;
67 }
68 else {
69 state = parser.stateStack[ln];
70 }
71 int length = map_state_number[state.number].n_actions;
72 state_number = state.number;
73 LOGV(state.number);
74 LOGV(length);
75 tab_stops = tokenMenuTabs;
76 des->d_size.y = length;
77
78 des->c_loc_doc.y = positionCursor(state.number, state.token);
79 }
80
81 void TokenMenuDc::reset(unsigned sn) {
82 LOGSECTION("TokenMenuDc::reset");
83 state_number = sn;
84 LOGV(state_number);
85 int length = map_state_number[sn].n_actions;
86 des->d_size.y = length;
87 }
88
89 int TokenMenuDc::positionCursor(unsigned sn, unsigned tn) {
90 LOGSECTION("TokenMenuDc::positionCursor");
91 LOGV(sn);
92 LOGV(tn);
93 LOGV(state_number);
94 int length = map_state_number[sn].n_actions;
95 unsigned *t_act = lstptr(map_state_number[sn], t_actions);
96 int ln = 0;
97 int defaultLine = 0;
98 while (ln < length) {
99 unsigned t = *t_act++;
100 if (t == tn) {
101 break;
102 }
103 if (t == 0) {
104 defaultLine = ln;
105 }
106 ln++;
107 }
108 if (ln == length) {
109 ln = defaultLine;
110 }
111 LOGV(tn) LCV(ln) LCV(defaultLine);
112 return ln;
113 }
114
115 void TokenMenuDc::getLine(unsigned ln) const {
116 LOGSECTION("TokenMenuDc::getLine");
117 LOGV(ln);
118
119 LOGV(parser.state.number);
120 LOGV(state_number);
121 state_number_map *sp = &map_state_number[state_number];
122 int an, tn, pn;
123 const char *as = NULL;
124
125 an = lstptr(*sp, a_actions)[ln];
126 tn = lstptr(*sp, t_actions)[ln];
127 pn = lstptr(*sp, p_actions)[ln];
128
129 LOGV(an);
130 LOGV(tn);
131 LOGV(pn);
132 if (tn == 0) {
133 if (an == pe_syn_error) {
134 sss("No Default");
135 }
136 else {
137 if ((ln == 0 && pn == 0)
138 /*|| (ln == 1 && map_state_number[t->sn].actions[1] == noise_token)*/
139 ) {
140 sss("Accept\t\t");
141 }
142 else if (an == pe_reduce_form || an == pe_simple_reduce) {
143 ssprintf("****\t<< R%03d\tNone of the above--Default", pn);
144 }
145 else {
146 sss("****\t\tNone of the above--Default");
147 }
148 }
149 }
150 else {
151 ssprintf("T%03d\t", tn);
152 switch (an) {
153 case pe_go_to:
154 as = ">> S%03d\t";
155 break;
156 case pe_reduce_form:
157 case pe_simple_reduce:
158 case pe_accept:
159 as = "<< R%03d\t";
160 break;
161 case pe_shift_accept:
162 as = "Accept\t";
163 break;
164 case pe_shift_reduce:
165 case pe_shift_simple_reduce:
166 case pe_syn_error:
167 case pe_null_go_to:
168 case pe_skip:
169 case pe_skip_reduce:
170 as = "\t";
171 }
172 apprintf(as, pn);
173 atkn(tn);
174 }
175 }
176
177 unsigned TokenMenuDc::token(unsigned ln){
178 LOGSECTION("TokenMenuDc::token");
179 LOGV(ln);
180 LOGV(parser.state.number);
181 LOGV(state_number);
182 return lstptr(map_state_number[state_number], t_actions)[ln];
183 }
184
185 int TokenMenuDc::expansion_rules_ok(unsigned ln) {
186 LOGSECTION("TokenMenuDc::expansion_rules_ok");
187 LOGV(ln);
188 return build_item_list_ok(token(ln));
189 }
190
191 dc_ref TokenMenuDc::expansion_rules(unsigned ln) {
192 return build_item_list(token(ln));
193 }
194
195 int TokenMenuDc::productions_ok(unsigned ln) {
196 LOGSECTION("TokenMenuDc::productions_ok");
197 return productions_window_ok(token(ln));
198 }
199
200 dc_ref TokenMenuDc::productions(unsigned ln) {
201 return productions_window(token(ln));
202 }
203
204 int TokenMenuDc::set_elements_ok(unsigned ln) {
205 LOGSECTION("TokenMenuDc::set_elements_ok");
206 return token_set_window_ok(token(ln));
207 }
208
209 dc_ref TokenMenuDc::set_elements(unsigned ln) {
210 LOGSECTION("TokenMenuDc::set_elements_ok");
211 return token_set_window(token(ln));
212 }
213
214 int TokenMenuDc::usage_ok(unsigned ln) {
215 LOGSECTION("TokenMenuDc::usage_ok");
216 return token_usage_window_ok(token(ln));
217 }
218
219 dc_ref TokenMenuDc::usage(unsigned ln) {
220 return token_usage_window(token(ln));
221 }
222
223
224 static int ftr_stack_tabs[] = {3,10,16,0};
225 //static int ftr_stack_tabs[] = {3,10,24,0};
226
227 FtParserDc::FtParserDc(FtParser &p)
228 : parser(p)
229 {
230 LOGSECTION("FtParserDc::FtParserDc");
231 LOGV(parser.stateStack.size());
232 int stackDepth = parser.stateStack.size();
233 des->d_size = cint(token_name_length+ftr_stack_tabs[2],stackDepth + 1);
234 //des->c_size = cursor_bar_size;
235 tab_stops = ftr_stack_tabs;
236 connect(this, &FtParserDc::updateSize, parser.stackChanged);
237 }
238
239 void FtParserDc::updateSize(const FtParser::StackChanged &msg) {
240 LOGSECTION("FtParserDc::updateSize");
241 LOGV(msg.newSize) LCV(des->d_size.y);
242 des->d_size.y = msg.newSize;
243 }
244
245 void FtParserDc::getLine(unsigned ln) const {
246 LOGSECTION("FtParserDc::getLine");
247 LOGV(ln);
248 FtParser::State *state;
249 LOGV(parser.processState);
250 LOGV(parser.reductionIndex);
251 LOGV(parser.stateStack.size());
252 unsigned token = 0;
253 if (ln >= parser.stateStack.size()) {
254 if (parser.processState == parser.selectionRequired &&
255 ln == parser.reductionIndex)
256 {
257 state = &parser.reductionState;
258 token = state->token;
259 }
260 else {
261 state = &parser.state;
262 //token = parser.inputToken;
263 token = parser.state.token;
264 }
265 }
266 else {
267 state = &parser.stateStack[ln];
268 token = state->token;
269 }
270 ssprintf("%2d\tS%03d:\t", ln, state->number);
271 LOGV(token);
272 if (token) {
273 apprintf("T%03d\t",token);
274 atkn(token);
275 }
276 LOGV(string_base);
277 }
278
279 dc_ref FtParserDc::tokenMenu(int ln) {
280 LOGSECTION("FtParserDc::tokenMenu");
281 LOGV(ln);
282 return new TokenMenuDc(parser, ln);
283 }
284
285 unsigned FtParserDc::state(unsigned ln) {
286 int sn = parser.state.number;
287
288 if (ln < parser.stateStack.size()) {
289 sn = parser.stateStack[ln].number;
290 }
291 return sn;
292 }
293
294 unsigned FtParserDc::token(unsigned ln) {
295 LOGSECTION("FtParserDc::token");
296 unsigned tn = parser.state.token;
297 LOGV(ln);
298 LOGV(parser.stateStack.size());
299 if (ln < parser.stateStack.size()) {
300 tn = parser.stateStack[ln].token;
301 }
302 LOGV(tn);
303 return tn;
304 }
305
306 unsigned FtParserReductionDc::token(unsigned ln) {
307 unsigned tn = ibnfs[ibnfb[rule_number] + ln];
308
309 return tn;
310 }
311
312 dc_ref FtParserDc::aux_trace(unsigned) {
313 LOGSECTION("FtParserDc::aux_trace(unsigned)");
314 tsd *ts = init_tsd(2);
315 int k = 0;
316 dc_ref window;
317 int ssx = parser.stateStack.size();
318
319 while (k < ssx) {
320 int sn = parser.stateStack[k].number;
321 int tn = parser.stateStack[k++].token;
322 at(ts, sn, tn);
323 }
324 if (parser.processState == FtParser::selectionRequired) {
325 at(ts, parser.reductionState.number, (int) parser.reductionState.token);
326 }
327 /*
328 else if (parser.processState == FtParser::syntaxError) {
329 at(ts, parser.reductionState.number, 0);
330 }
331 else {
332 at(ts, parser.state.number, parser.state.token);
333 }
334 */
335 else {
336 at(ts, parser.state.number, 0);
337 }
338 window = new trace_window_dc("Auxiliary Trace", ts);
339 delete_tsd(ts);
340 return window;
341 }
342
343 dc_ref FtParserDc::expansion_rules(unsigned ln) {
344 return build_item_list(token(ln));
345 }
346
347 int FtParserDc::expansion_rules_ok(unsigned ln) {
348 LOGSECTION("FtParserDc::expansion_rules_ok");
349 return build_item_list_ok(token(ln));
350 }
351
352 dc_ref FtParserReductionDc::expansion_rules(unsigned ln) {
353 return build_item_list(token(ln));
354 }
355
356 int FtParserReductionDc::expansion_rules_ok(unsigned ln) {
357 return build_item_list_ok(token(ln));
358 }
359
360 int FtParserDc::keywords_ok(unsigned ln) {
361 LOGSECTION("FtParserDc::keywords_ok");
362 return keywords_window_ok(state(ln));
363 }
364
365 dc_ref FtParserDc::keywords(unsigned ln) {
366 return keywords_window(state(ln));
367 }
368
369 dc_ref FtParserDc::previous_states(unsigned ln) {
370 LOGSECTION("FtParserDc::previous_states");
371 return previous_states_window(state(ln));
372 }
373
374 int FtParserDc::productions_ok(unsigned ln) {
375 LOGSECTION("FtParserDc::productions_ok");
376 return productions_window_ok(token(ln));
377 }
378
379 int FtParserDc::previous_states_ok(unsigned ln) {
380 LOGSECTION("FtParserDc::previous_states_ok");
381 return ln != 0;
382 }
383
384 dc_ref FtParserDc::productions(unsigned ln) {
385 return productions_window(token(ln));
386 }
387
388 int FtParserReductionDc::productions_ok(unsigned ln) {
389 return productions_window_ok(token(ln));
390 }
391
392 dc_ref FtParserReductionDc::productions(unsigned ln) {
393 return productions_window(token(ln));
394 }
395
396 /*
397 dc_ref FtParserDc::rule_stack(unsigned ln) {
398 LOGSECTION("FtParserDc::rule_stack");
399 LOGV(ln);
400
401 parser.itemStack = parser.x1x_new();
402 return dc_ref(new rule_stack_dc(parser.itemStack,ln, head_title));
403 }
404 */
405
406 int FtParserDc::set_elements_ok(unsigned ln) {
407 return token_set_window_ok(token(ln));
408 }
409
410 dc_ref FtParserDc::set_elements(unsigned ln) {
411 return token_set_window(token(ln));
412 }
413
414 int FtParserReductionDc::set_elements_ok(unsigned ln) {
415 return token_set_window_ok(token(ln));
416 }
417
418 dc_ref FtParserReductionDc::set_elements(unsigned ln) {
419 return token_set_window(token(ln));
420 }
421
422 dc_ref FtParserDc::state_definition(unsigned ln) {
423 return conflict_state_window(state(ln));
424 }
425
426 dc_ref FtParserDc::state_expansion(unsigned ln) {
427 return state_expansion_window(state(ln));
428 }
429
430 int FtParserDc::usage_ok(unsigned ln) {
431 return token_usage_window_ok(token(ln));
432 }
433
434 dc_ref FtParserDc::usage(unsigned ln) {
435 return token_usage_window(token(ln));
436 }
437
438 int FtParserReductionDc::usage_ok(unsigned ln) {
439 return token_usage_window_ok(token(ln));
440 }
441
442 dc_ref FtParserReductionDc::usage(unsigned ln) {
443 return token_usage_window(token(ln));
444 }
445
446 #ifdef __IBMCPP__
447
448 #pragma define(DcRef<FtParserDc>)
449 #pragma define(DcRef<FtParserReductionDc>)
450 #pragma define(DcRef<rule_stack_dc>)
451 #pragma define(DcRef<TokenMenuDc>)
452
453 #endif
454