Mercurial > ~dholland > hg > ag > index.cgi
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/anagram/guisupport/ftpardc.cpp Sat Dec 22 17:52:45 2007 -0500 @@ -0,0 +1,454 @@ +/* + * AnaGram, A System for Syntax Directed Programming + * Copyright 1993-2002 Parsifal Software. All Rights Reserved. + * See the file COPYING for license and usage terms. + * + * ftpardc.cpp + */ + +#include "arrays.h" +#include "bpe3.h" +#include "conflicttrc.h" +#include "data.h" +#include "dc.h" +#include "dict.h" +#include "items.h" +#include "ftpardc.h" +#include "q1a.h" +#include "stexpdc.h" +#include "tracedc.h" +#include "ws.h" + +//#define INCLUDE_LOGGING +#include "log.h" + + +dc::MenuOption *FtParserDc::auxTable[] = { + &dc::auxiliaryTraceOptionInstance, + &dc::expansionRulesOptionInstance, + &dc::keywordsOptionInstance, + &dc::previousStatesOptionInstance, + &dc::productionsOptionInstance, + &dc::setElementsOptionInstance, + &dc::stateDefinitionOptionInstance, + &dc::stateExpansionOptionInstance, + &dc::tokenUsageOptionInstance, + NULL +}; + +dc::MenuOption *FtParserReductionDc::auxTable[] = { + &dc::expansionRulesOptionInstance, + &dc::productionsOptionInstance, + &dc::setElementsOptionInstance, + &dc::tokenUsageOptionInstance, + NULL +}; + +int FtParserReductionDc::reduction_menu_tabs[] = { 0 }; + +dc::MenuOption *TokenMenuDc::auxTable[] = { + &dc::expansionRulesOptionInstance, + &dc::productionsOptionInstance, + &dc::setElementsOptionInstance, + &dc::tokenUsageOptionInstance, + NULL +}; + +static int tokenMenuTabs[] = {6,15,0}; +TokenMenuDc::TokenMenuDc(FtParser &p, unsigned ln) + : parser(p) +{ + LOGSECTION("TokenMenuDc::TokenMenuDc"); + LOGV(ln); + unsigned stackDepth = parser.stateStack.size(); + FtParser::State state; + if (ln >= stackDepth) { + state = parser.state; + } + else { + state = parser.stateStack[ln]; + } + int length = map_state_number[state.number].n_actions; + state_number = state.number; + LOGV(state.number); + LOGV(length); + tab_stops = tokenMenuTabs; + des->d_size.y = length; + + des->c_loc_doc.y = positionCursor(state.number, state.token); +} + +void TokenMenuDc::reset(unsigned sn) { + LOGSECTION("TokenMenuDc::reset"); + state_number = sn; + LOGV(state_number); + int length = map_state_number[sn].n_actions; + des->d_size.y = length; +} + +int TokenMenuDc::positionCursor(unsigned sn, unsigned tn) { + LOGSECTION("TokenMenuDc::positionCursor"); + LOGV(sn); + LOGV(tn); + LOGV(state_number); + int length = map_state_number[sn].n_actions; + unsigned *t_act = lstptr(map_state_number[sn], t_actions); + int ln = 0; + int defaultLine = 0; + while (ln < length) { + unsigned t = *t_act++; + if (t == tn) { + break; + } + if (t == 0) { + defaultLine = ln; + } + ln++; + } + if (ln == length) { + ln = defaultLine; + } + LOGV(tn) LCV(ln) LCV(defaultLine); + return ln; +} + +void TokenMenuDc::getLine(unsigned ln) const { + LOGSECTION("TokenMenuDc::getLine"); + LOGV(ln); + + LOGV(parser.state.number); + LOGV(state_number); + state_number_map *sp = &map_state_number[state_number]; + int an, tn, pn; + const char *as = NULL; + + an = lstptr(*sp, a_actions)[ln]; + tn = lstptr(*sp, t_actions)[ln]; + pn = lstptr(*sp, p_actions)[ln]; + + LOGV(an); + LOGV(tn); + LOGV(pn); + if (tn == 0) { + if (an == pe_syn_error) { + sss("No Default"); + } + else { + if ((ln == 0 && pn == 0) + /*|| (ln == 1 && map_state_number[t->sn].actions[1] == noise_token)*/ + ) { + sss("Accept\t\t"); + } + else if (an == pe_reduce_form || an == pe_simple_reduce) { + ssprintf("****\t<< R%03d\tNone of the above--Default", pn); + } + else { + sss("****\t\tNone of the above--Default"); + } + } + } + else { + ssprintf("T%03d\t", tn); + switch (an) { + case pe_go_to: + as = ">> S%03d\t"; + break; + case pe_reduce_form: + case pe_simple_reduce: + case pe_accept: + as = "<< R%03d\t"; + break; + case pe_shift_accept: + as = "Accept\t"; + break; + case pe_shift_reduce: + case pe_shift_simple_reduce: + case pe_syn_error: + case pe_null_go_to: + case pe_skip: + case pe_skip_reduce: + as = "\t"; + } + apprintf(as, pn); + atkn(tn); + } +} + +unsigned TokenMenuDc::token(unsigned ln){ + LOGSECTION("TokenMenuDc::token"); + LOGV(ln); + LOGV(parser.state.number); + LOGV(state_number); + return lstptr(map_state_number[state_number], t_actions)[ln]; +} + +int TokenMenuDc::expansion_rules_ok(unsigned ln) { + LOGSECTION("TokenMenuDc::expansion_rules_ok"); + LOGV(ln); + return build_item_list_ok(token(ln)); +} + +dc_ref TokenMenuDc::expansion_rules(unsigned ln) { + return build_item_list(token(ln)); +} + +int TokenMenuDc::productions_ok(unsigned ln) { + LOGSECTION("TokenMenuDc::productions_ok"); + return productions_window_ok(token(ln)); +} + +dc_ref TokenMenuDc::productions(unsigned ln) { + return productions_window(token(ln)); +} + +int TokenMenuDc::set_elements_ok(unsigned ln) { + LOGSECTION("TokenMenuDc::set_elements_ok"); + return token_set_window_ok(token(ln)); +} + +dc_ref TokenMenuDc::set_elements(unsigned ln) { + LOGSECTION("TokenMenuDc::set_elements_ok"); + return token_set_window(token(ln)); +} + +int TokenMenuDc::usage_ok(unsigned ln) { + LOGSECTION("TokenMenuDc::usage_ok"); + return token_usage_window_ok(token(ln)); +} + +dc_ref TokenMenuDc::usage(unsigned ln) { + return token_usage_window(token(ln)); +} + + +static int ftr_stack_tabs[] = {3,10,16,0}; +//static int ftr_stack_tabs[] = {3,10,24,0}; + +FtParserDc::FtParserDc(FtParser &p) + : parser(p) +{ + LOGSECTION("FtParserDc::FtParserDc"); + LOGV(parser.stateStack.size()); + int stackDepth = parser.stateStack.size(); + des->d_size = cint(token_name_length+ftr_stack_tabs[2],stackDepth + 1); + //des->c_size = cursor_bar_size; + tab_stops = ftr_stack_tabs; + connect(this, &FtParserDc::updateSize, parser.stackChanged); +} + +void FtParserDc::updateSize(const FtParser::StackChanged &msg) { + LOGSECTION("FtParserDc::updateSize"); + LOGV(msg.newSize) LCV(des->d_size.y); + des->d_size.y = msg.newSize; +} + +void FtParserDc::getLine(unsigned ln) const { + LOGSECTION("FtParserDc::getLine"); + LOGV(ln); + FtParser::State *state; + LOGV(parser.processState); + LOGV(parser.reductionIndex); + LOGV(parser.stateStack.size()); + unsigned token = 0; + if (ln >= parser.stateStack.size()) { + if (parser.processState == parser.selectionRequired && + ln == parser.reductionIndex) + { + state = &parser.reductionState; + token = state->token; + } + else { + state = &parser.state; + //token = parser.inputToken; + token = parser.state.token; + } + } + else { + state = &parser.stateStack[ln]; + token = state->token; + } + ssprintf("%2d\tS%03d:\t", ln, state->number); + LOGV(token); + if (token) { + apprintf("T%03d\t",token); + atkn(token); + } + LOGV(string_base); +} + +dc_ref FtParserDc::tokenMenu(int ln) { + LOGSECTION("FtParserDc::tokenMenu"); + LOGV(ln); + return new TokenMenuDc(parser, ln); +} + +unsigned FtParserDc::state(unsigned ln) { + int sn = parser.state.number; + + if (ln < parser.stateStack.size()) { + sn = parser.stateStack[ln].number; + } + return sn; +} + +unsigned FtParserDc::token(unsigned ln) { + LOGSECTION("FtParserDc::token"); + unsigned tn = parser.state.token; + LOGV(ln); + LOGV(parser.stateStack.size()); + if (ln < parser.stateStack.size()) { + tn = parser.stateStack[ln].token; + } + LOGV(tn); + return tn; +} + +unsigned FtParserReductionDc::token(unsigned ln) { + unsigned tn = ibnfs[ibnfb[rule_number] + ln]; + + return tn; +} + +dc_ref FtParserDc::aux_trace(unsigned) { + LOGSECTION("FtParserDc::aux_trace(unsigned)"); + tsd *ts = init_tsd(2); + int k = 0; + dc_ref window; + int ssx = parser.stateStack.size(); + + while (k < ssx) { + int sn = parser.stateStack[k].number; + int tn = parser.stateStack[k++].token; + at(ts, sn, tn); + } + if (parser.processState == FtParser::selectionRequired) { + at(ts, parser.reductionState.number, (int) parser.reductionState.token); + } +/* + else if (parser.processState == FtParser::syntaxError) { + at(ts, parser.reductionState.number, 0); + } + else { + at(ts, parser.state.number, parser.state.token); + } +*/ + else { + at(ts, parser.state.number, 0); + } + window = new trace_window_dc("Auxiliary Trace", ts); + delete_tsd(ts); + return window; +} + +dc_ref FtParserDc::expansion_rules(unsigned ln) { + return build_item_list(token(ln)); +} + +int FtParserDc::expansion_rules_ok(unsigned ln) { + LOGSECTION("FtParserDc::expansion_rules_ok"); + return build_item_list_ok(token(ln)); +} + +dc_ref FtParserReductionDc::expansion_rules(unsigned ln) { + return build_item_list(token(ln)); +} + +int FtParserReductionDc::expansion_rules_ok(unsigned ln) { + return build_item_list_ok(token(ln)); +} + +int FtParserDc::keywords_ok(unsigned ln) { + LOGSECTION("FtParserDc::keywords_ok"); + return keywords_window_ok(state(ln)); +} + +dc_ref FtParserDc::keywords(unsigned ln) { + return keywords_window(state(ln)); +} + +dc_ref FtParserDc::previous_states(unsigned ln) { + LOGSECTION("FtParserDc::previous_states"); + return previous_states_window(state(ln)); +} + +int FtParserDc::productions_ok(unsigned ln) { + LOGSECTION("FtParserDc::productions_ok"); + return productions_window_ok(token(ln)); +} + +int FtParserDc::previous_states_ok(unsigned ln) { + LOGSECTION("FtParserDc::previous_states_ok"); + return ln != 0; +} + +dc_ref FtParserDc::productions(unsigned ln) { + return productions_window(token(ln)); +} + +int FtParserReductionDc::productions_ok(unsigned ln) { + return productions_window_ok(token(ln)); +} + +dc_ref FtParserReductionDc::productions(unsigned ln) { + return productions_window(token(ln)); +} + +/* +dc_ref FtParserDc::rule_stack(unsigned ln) { + LOGSECTION("FtParserDc::rule_stack"); + LOGV(ln); + + parser.itemStack = parser.x1x_new(); + return dc_ref(new rule_stack_dc(parser.itemStack,ln, head_title)); +} +*/ + +int FtParserDc::set_elements_ok(unsigned ln) { + return token_set_window_ok(token(ln)); +} + +dc_ref FtParserDc::set_elements(unsigned ln) { + return token_set_window(token(ln)); +} + +int FtParserReductionDc::set_elements_ok(unsigned ln) { + return token_set_window_ok(token(ln)); +} + +dc_ref FtParserReductionDc::set_elements(unsigned ln) { + return token_set_window(token(ln)); +} + +dc_ref FtParserDc::state_definition(unsigned ln) { + return conflict_state_window(state(ln)); +} + +dc_ref FtParserDc::state_expansion(unsigned ln) { + return state_expansion_window(state(ln)); +} + +int FtParserDc::usage_ok(unsigned ln) { + return token_usage_window_ok(token(ln)); +} + +dc_ref FtParserDc::usage(unsigned ln) { + return token_usage_window(token(ln)); +} + +int FtParserReductionDc::usage_ok(unsigned ln) { + return token_usage_window_ok(token(ln)); +} + +dc_ref FtParserReductionDc::usage(unsigned ln) { + return token_usage_window(token(ln)); +} + +#ifdef __IBMCPP__ + +#pragma define(DcRef<FtParserDc>) +#pragma define(DcRef<FtParserReductionDc>) +#pragma define(DcRef<rule_stack_dc>) +#pragma define(DcRef<TokenMenuDc>) + +#endif +