comparison anagram/agcore/data.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 * data.cpp - Data Module
7 */
8
9 #include <time.h>
10 #include "port.h"
11
12 #include "agarray.h"
13 #include "arrays.h"
14 #include "assert.h"
15 #include "config.h"
16 #include "data.h"
17 #include "dict.h"
18 #include "error.h"
19 #include "lexeme.h"
20 #include "myalloc.h"
21 #include "nckwtr.h"
22 #include "p.h"
23 #include "q1a.h"
24 #include "q1glbl.h"
25 #include "q5.h"
26 #include "rpz.h"
27 #include "tsd.h"
28
29 //#define INCLUDE_LOGGING
30 #include "log.h"
31
32
33 tuple_dict *frss_dict;
34
35 tsd *unres_con;
36 tsd *res_con;
37 int precedence_level = 0;
38 int enum_base = 0;
39
40 tsd *prr;
41 tsd *key_mess;
42 tsd *rename_macro_list;
43
44 int void_token_type = 1;
45 int int_token_type;
46 int long_token_type;
47 unsigned nprods = 0;
48
49 syntax_states syntax_state = syntax_error;
50
51 const char *syntaxStateString[] = {
52 "Ready",
53 "Loaded",
54 "Error",
55 "Parsed",
56 "Analyzed",
57 "Built"
58 };
59
60 char_set_map *map_char_set = NULL;
61 unsigned *part_list = NULL;
62 unsigned *chars_list = NULL;
63
64 static int ints[2];
65
66 list_dict *char_set_dict = NULL;
67 list_dict *key_list_dict = NULL;
68 list_dict *part_dict = NULL;
69 list_dict *prod_dict = NULL;
70 list_dict *vp_prod_dict = NULL;
71
72 vp_prod_number_map *map_vp_prod_number = NULL;
73
74 unsigned *previous_states_list = NULL;
75 unsigned *completed_forms_list = NULL;
76 unsigned *gotos_list = NULL;
77 unsigned *reductions_list = NULL;
78 unsigned *a_actions_list = NULL;
79 unsigned *t_actions_list = NULL;
80 unsigned *p_actions_list = NULL;
81 unsigned *completions_list = NULL;
82 unsigned *chain_completions_list = NULL;
83 unsigned *chain_gotos_list = NULL;
84 unsigned *reduction_states_list = NULL;
85 unsigned nstates;
86
87 part_number_map *map_part_number = NULL;
88
89 char_number_map *map_char_number = NULL;
90 int max_char_number = -1;
91 int min_char_number = 0;
92 unsigned n_chars = 0;
93
94
95 /* flags */
96
97
98 FILE *h_file = NULL;
99 FILE *pe_file = NULL;
100
101 char *key_ends = NULL;
102 tsd *key_table = NULL;
103 unsigned n_key_ends = 0;
104 int max_key_length = 0;
105
106 int character_seen;
107
108 AgStack<int> distinguishSets;
109
110 static void reset_summary_lists(void) {
111 part_list = reset_list(part_list, 260);
112 chars_list = reset_list(chars_list, 260);
113 }
114
115 static void reset_result_lists(void) {
116 previous_states_list = reset_list(previous_states_list, 0);
117 completed_forms_list = reset_list(completed_forms_list, 0);
118 gotos_list = reset_list(gotos_list, 0);
119 reductions_list = reset_list(reductions_list, 0);
120 a_actions_list = reset_list(a_actions_list, 0);
121 t_actions_list = reset_list(t_actions_list, 0);
122 p_actions_list = reset_list(p_actions_list, 0);
123 completions_list = reset_list(completions_list, 0);
124 chain_completions_list = reset_list(chain_completions_list, 0);
125 chain_gotos_list = reset_list(chain_gotos_list, 0);
126 reduction_states_list = reset_list(reduction_states_list, 0);
127 }
128
129 #define reset_map(name, n) \
130 map_##name = (name##_map *) \
131 reset_array_size(map_##name, n, sizeof(name##_map))
132
133 static void reset_summary_arrays(void) {
134 reset_map(char_number, 260);
135 reset_map(char_set, 50);
136 reset_map(part_number, 50);
137 reset_map(vp_prod_number, 50);
138 }
139
140 void init_data(void) {
141 LOGSECTION("init_data");
142
143 reset_summary_lists();
144 LOGS("summary lists reset");
145
146 reset_result_lists();
147 LOGS("result_lists reset");
148
149 reset_summary_arrays();
150 LOGS("summary_arrays reset");
151
152 max_key_length = 0;
153 map_state_number = (state_number_map *)
154 init_array(0, sizeof(state_number_map));
155 nstates = 0;
156 semantic_productions = 0;
157
158 isht_dict = null_list_dict();
159 frss_dict = null_tuple_dict(3);
160
161 completed_form_dict = null_tuple_dict(2);
162 MAP(completed_form, 20);
163
164 unres_con = spec_tsd(0, 4);
165 res_con = spec_tsd(0, 4);
166 prr = spec_tsd(0, 4);
167 key_mess = spec_tsd(0, 4);
168 sgt = spec_tsd(100, 3);
169 srt = spec_tsd(100, 2);
170
171 rename_macro_list = spec_tsd(0, 2);
172
173 disregard_token = disregard_cont_rule = disregard_skip_rule = 0;
174 disregardList.reset();
175
176 distinguishSets.reset();
177
178 char_set_dict = null_list_dict();
179 part_dict = null_list_dict();
180
181 vp_prod_dict = null_list_dict();
182 add_list_dict(ints, 0, char_set_dict);
183 add_list_dict(ints, 0, part_dict);
184 add_list_dict(ints, 0, vp_prod_dict);
185 error_token = eof_token = 0;
186 n_chars = min_char_number = 0;
187 max_char_number = -1;
188
189 ibnfb = ibnfs = NULL;
190 ibnfn = NULL;
191 token_perm = NULL;
192 precedence_level = 0;
193 nprods = 0;
194 n_conflicts = 0;
195 enum_base = 0;
196 reset_errors();
197
198 token_perm = NULL;
199 }
200
201 void reset_summary_data(void) {
202 LOGSECTION("reset_summary_data");
203 reset_summary_lists();
204 reset_summary_arrays();
205
206 delete_tsd(bnf_table);
207 bnf_table = spec_tsd(200,2);
208
209 if (key_table != NULL) {
210 key_table = delete_tsd(key_table);
211 }
212
213 if (key_list_dict != NULL) {
214 key_list_dict = delete_list_dict(key_list_dict);
215 }
216
217 if (key_ends != NULL) {
218 DEALLOCATE(key_ends);
219 key_ends = NULL;
220 }
221
222 n_key_ends = 0;
223 max_key_length = 0;
224 disregardList.reset();
225 disregard_token = disregard_cont_rule = disregard_skip_rule = 0;
226 distinguishSets.reset();
227 ibnf_table = delete_tsd(ibnf_table);
228
229 reset_list_dict(char_set_dict);
230 reset_list_dict(part_dict);
231 reset_list_dict(vp_prod_dict);
232
233 add_list_dict(ints, 0, char_set_dict);
234 add_list_dict(ints, 0, part_dict);
235 add_list_dict(ints, 0, vp_prod_dict);
236 n_chars = min_char_number = 0;
237 max_char_number = -1;
238 nforms = ntkns = 0;
239 character_seen = 0;
240
241 if (token_perm != NULL) {
242 DEALLOCATE(token_perm);
243 token_perm = NULL;
244 }
245
246 if (ibnfn != NULL) {
247 DEALLOCATE(ibnfn);
248 ibnfn = NULL;
249 }
250
251 if (ibnfb != NULL) {
252 DEALLOCATE(ibnfb);
253 ibnfb = NULL;
254 }
255
256 if (ibnfs != NULL) {
257 DEALLOCATE(ibnfs);
258 ibnfs = NULL;
259 }
260
261 //partition_required = 0;
262 syntax_error_flag = 0;
263 parse_abort_flag = 0;
264 precedence_level = 0;
265 enum_base = 0;
266 nprods = 0;
267 semantic_productions = 0;
268 reset_errors();
269 }
270
271 static void reset_result_tuples(void) {
272 reset_list_dict(isht_dict);
273 reset_tuple_dict(frss_dict);
274 reset_tuple_dict(completed_form_dict);
275 reset_array(map_completed_form);
276 reset_tsd(sgt);
277 reset_tsd(srt);
278 reset_tsd(unres_con);
279 reset_tsd(res_con);
280 reset_tsd(prr);
281 reset_tsd(key_mess);
282 reset_tsd(rename_macro_list);
283 }
284
285 void reset_result_data(void) {
286 LOGSECTION("reset_result_data");
287 reset_result_lists();
288 reset_result_tuples();
289 reset_array(map_state_number);
290 nstates = kits = nits = 0;
291 n_conflicts = 0;
292 clear_conflict_expansion();
293 if (key_table != NULL) key_table = delete_tsd(key_table);
294 if (key_ends != NULL) {DEALLOCATE(key_ends); key_ends = NULL;}
295 n_key_ends = 0;
296 }
297