Mercurial > ~dholland > hg > ag > index.cgi
diff anagram/guisupport/symtabdc.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/symtabdc.cpp Sat Dec 22 17:52:45 2007 -0500 @@ -0,0 +1,114 @@ +/* + * AnaGram, A System for Syntax Directed Programming + * Copyright 1993-2002 Parsifal Software. All Rights Reserved. + * See the file COPYING for license and usage terms. + * + * symtabdc.cpp + */ + +#include "csexp.h" +#include "dc.h" +#include "items.h" +#include "stacks.h" +#include "symbol.h" +#include "symtabdc.h" +#include "token.h" +#include "tree.h" +#include "ut.h" +#include "ws.h" + +//#define INCLUDE_LOGGING +#include "log.h" + + +static int symbol_table_tabs[] = {6,0}; + +symbol_table_dc::symbol_table_dc(void) + : dc("Symbol Table") +{ + LOGSECTION("symbol_table_dc::symbol_table_dc"); + des->d_size.y = Symbol::count() - 1; + LOGV(Symbol::count()); + + tab_stops = symbol_table_tabs; + columnHeadTitle = "Token\tSymbol"; +} + +void symbol_table_dc::getLine(unsigned n) const { + LOGSECTION("symbol_table_dc::getLine"); + LOGV(n) LCV(Symbol::count()); + int vptn; + + Symbol symbol = Symbol::sorted(n + 1); + LOGV(symbol) LCV(symbol->string.pointer()); + ics(); + Token token = symbol->token_number; + LOGV(token); + if (token.isNotNull()) { + apprintf("T%03d", (int) token); + } + acs('\t'); + ass(symbol->string.pointer()); + ParseTree parseTree = symbol->parse_tree; + LOGV(parseTree); + if (parseTree.isNotNull()) { + ass( " = "); + ass(parseTree->expression->asString().pointer()); + return; + } + LOGV(token->vp_prod_number); + if (token.isNotNull() && (vptn = token->vp_prod_number) != 0) { + ass( " = "); + avptkn(vptn); + return; + } +} + +unsigned symbol_table_dc::token(unsigned ln) { + Symbol symbol = Symbol::sorted(ln + 1); + return symbol->token_number; +} + +int symbol_table_dc::expansion_rules_ok(unsigned ln) { + return build_item_list_ok(token(ln)); +} + +dc_ref symbol_table_dc::expansion_rules(unsigned ln) { + return build_item_list(token(ln)); +} + +int symbol_table_dc::productions_ok(unsigned ln) { + return productions_window_ok(token(ln)); +} + +dc_ref symbol_table_dc::productions(unsigned ln) { + return productions_window(token(ln)); +} + +int symbol_table_dc::set_elements_ok(unsigned ln) { + Symbol symbol = Symbol::sorted(ln + 1); + int pt = symbol->parse_tree; + + if (pt) { + return char_set_window_ok(map_parse_tree[pt].char_set); + } + return token_set_window_ok(symbol->token_number); +} + +dc_ref symbol_table_dc::set_elements(unsigned ln) { + Symbol symbol = Symbol::sorted(ln + 1); + int pt = symbol->parse_tree; + + if (pt) { + return char_set_window(map_parse_tree[pt].char_set); + } + return token_set_window(symbol->token_number); +} + +int symbol_table_dc::usage_ok(unsigned ln) { + return token_usage_window_ok(token(ln)); +} + +dc_ref symbol_table_dc::usage(unsigned ln) { + return token_usage_window(token(ln)); +}