Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/agcore/cra.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 * cra.cpp - Chain Reduction Analysis | |
7 */ | |
8 | |
9 #include <string.h> | |
10 #include "port.h" | |
11 | |
12 #include "arrays.h" | |
13 #include "assert.h" | |
14 #include "cra.h" | |
15 #include "data.h" | |
16 #include "q1glbl.h" | |
17 #include "q5.h" | |
18 #include "rule.h" | |
19 #include "token.h" | |
20 #include "tsd.h" | |
21 | |
22 //#define INCLUDE_LOGGING | |
23 #include "log.h" | |
24 | |
25 | |
26 static int *complete_form; | |
27 | |
28 | |
29 static int crax(Token completingToken, Rule rule) { | |
30 LOGSECTION("crax"); | |
31 LOGV(completingToken) LCV(rule); | |
32 RuleDescriptor &ruleDescriptor(rule); | |
33 | |
34 /* | |
35 if (rule.isNotNull() && rule->proc_name == 0 | |
36 && rule->not_unique_reduction == 0) { | |
37 if (rule->length() == 1) { | |
38 Token primaryToken = rule->prim_tkn; | |
39 */ | |
40 if (rule.isNotNull() && ruleDescriptor.proc_name == 0 | |
41 && ruleDescriptor.not_unique_reduction == 0) { | |
42 if (ruleDescriptor.length() == 1) { | |
43 Token primaryToken = ruleDescriptor.prim_tkn; | |
44 if (!primaryToken->subgrammar) { | |
45 if (tut[primaryToken]) { | |
46 at(lgt, (int)completingToken, complete_form[primaryToken]); | |
47 LOGS("appendTuple to lgt") LV(completingToken) | |
48 LCV(complete_form[primaryToken]); | |
49 return 1; | |
50 } | |
51 LOGV(primaryToken) LCV(complete_form[primaryToken]); | |
52 if (complete_form[primaryToken] != -1) { | |
53 return crax(completingToken, complete_form[primaryToken]); | |
54 } | |
55 } | |
56 } | |
57 } | |
58 at(lcftp, (int) completingToken, (int) rule); | |
59 return 0; | |
60 } | |
61 | |
62 void cra(void) { | |
63 LOGSECTION("cra"); | |
64 int *p, *q; | |
65 int i, k, n; | |
66 int s, t, f; | |
67 state_number_map *msn; | |
68 | |
69 if (lcft->nt == 0) { | |
70 return; | |
71 } | |
72 msn = &map_state_number[kits]; | |
73 LOGV(kits); | |
74 k = 0; | |
75 //complete_form = token_list; | |
76 complete_form = local_array(ntkns+1, int); | |
77 memset(complete_form, -1, sizeof(*complete_form)*(ntkns+1)); | |
78 memset(tut, 0, sizeof(*tut) * (ntkns+1)); | |
79 q = lcft->sb; | |
80 n = lcft->nt; | |
81 for (i = 0; i< n; i++) { | |
82 t = *q++; | |
83 f = *q++; | |
84 LOGV(t) LCV(f) LCV(tut[t]); | |
85 assert(complete_form[t] == -1); | |
86 complete_form[t] = f; | |
87 } | |
88 q = lgt->sb; | |
89 n = lgt->nt; | |
90 for (i = 0; i < n; i++) { | |
91 t = *q++; | |
92 s = *q++; | |
93 tut[t] = 1; | |
94 LOGV(t) LCV(s) LCV(tut[t]); | |
95 assert(complete_form[t] == -1); | |
96 complete_form[t] = s; | |
97 } | |
98 p = lcft->sb; | |
99 n = lcft->nt; | |
100 reset_tsd(lcftp); | |
101 for (i = 0; i < n; i++) { | |
102 t = *p++; | |
103 f = *p++; | |
104 k += crax(t, f); | |
105 } | |
106 if (lcftp->nt) { | |
107 chain_completions_list = (unsigned *) | |
108 size_prop(chain_completions_list, lcftp->nt); | |
109 msn->chain_completions_index = store_tuples(lcftp, chain_completions_list); | |
110 msn->n_chain_completions = lcftp->nt; | |
111 } | |
112 if (k) { | |
113 chain_gotos_list = (unsigned *) size_prop(chain_gotos_list, lgt->nt); | |
114 msn->chain_gotos_index = store_tuples(lgt, chain_gotos_list); | |
115 msn->n_chain_gotos = lgt->nt; | |
116 //check_counter_overflow(msn->n_chain_gotos == lgt->nt, "Chain gotos"); | |
117 } | |
118 LOGV(lcft->nt) LCV(lcftp->nt) LCV(msn->n_gotos) LCV(msn->n_chain_gotos); | |
119 assert(lcftp->nt + k == lcft->nt); | |
120 } | |
121 | |
122 |