diff anagram/guisupport/ruletabdc.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/ruletabdc.cpp	Sat Dec 22 17:52:45 2007 -0500
@@ -0,0 +1,116 @@
+/*
+ * AnaGram, A System for Syntax Directed Programming
+ * Copyright 1993-2002 Parsifal Software. All Rights Reserved.
+ * See the file COPYING for license and usage terms.
+ *
+ * ruletabdc.cpp
+ */
+
+#include "dc.h"
+#include "items.h"
+#include "q1a.h"
+#include "q1glbl.h"
+#include "ruletabdc.h"
+#include "stacks.h"
+#include "token.h"
+#include "ut.h"
+#include "wm1.h"
+#include "ws.h"
+
+//#define INCLUDE_LOGGING
+#include "log.h"
+
+
+rule_table_dc::localize::localize(unsigned ln) {
+  LOGSECTION("rule_table_dc::localize::localize");
+  int rn = 1;
+  unsigned nc = ibnfn[1] + 1;
+  int lc = 0;
+
+  while (nc <= ln) {
+    lc = nc;
+    nc += ibnfn[++rn] + 1;
+  }
+  rule = rn;
+  index = ln-lc;
+  LOGV(ln) LCV(rule) LCV(index) LCV(lc) LCV(nc);
+}
+
+int rule_table_dc::expansion_rules_ok(unsigned ln) {
+  localize x(ln);
+  return build_item_list_ok(x.token());
+}
+
+dc_ref rule_table_dc::expansion_rules(unsigned ln) {
+  localize x(ln);
+  return build_item_list(x.token());
+}
+
+
+int rule_table_dc::productions_ok(unsigned ln) {
+  localize x(ln);
+  return productions_window_ok(x.token());
+}
+
+dc_ref rule_table_dc::productions(unsigned ln) {
+  localize x(ln);
+  return productions_window(x.token());
+}
+
+int rule_table_dc::usage_ok(unsigned ln) {
+  localize x(ln);
+  return token_usage_window_ok(x.token());
+}
+
+dc_ref rule_table_dc::usage(unsigned ln) {
+  localize x(ln);
+  return token_usage_window(x.token());
+}
+
+dc_ref rule_table_dc::rule_context(unsigned ln) {
+  localize x(ln);
+  return rule_context_window(x.rule);
+}
+
+
+static int rule_table_tabs[] = {7,0};
+
+void rule_table_dc::getLine(unsigned ln) const {
+  LOGSECTION("rule_table_dc::getLine");
+  localize x(ln);
+  unsigned nt = ibnfn[x.rule];
+  LOGV(ln) LCV(nt);
+  if (x.index < nt) {
+    int tn = ibnfs[ibnfb[x.rule] + x.index];
+    ssprintf("T%03d:\t", tn);
+    atkn(tn);
+    return;
+  }
+  sss("\t   -> ");
+  append_item(x.rule, -1);
+}
+
+void rule_table_dc::synchCursor(unsigned ln) const {
+  LOGSECTION("rule_table_dc::synchCursor");
+  LOGV(ln);
+  localize x(ln);
+  if (x.rule) {
+    set_rule_line(x.rule);
+  }
+}
+
+rule_table_dc::rule_table_dc(void)
+  : dc("Rule Table")
+{
+  int lc = 0;
+  unsigned fn = 0;
+
+  tab_stops = rule_table_tabs;
+  columnHeadTitle = "Token\tProduction";
+  while (fn++ < nforms) {
+    lc += ibnfn[fn] + 1;
+  }
+  des->d_size.y = lc;
+  des->d_size.x = rule_table_tabs[1] + item_length;
+}
+