-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlane_tracing.h
306 lines (244 loc) · 8.07 KB
/
lane_tracing.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
This file is part of Hyacc, a LR(0)/LALR(1)/LR(1)/LR(k) parser generator.
Copyright (C) 2008, 2009 Xin Chen. [email protected]
Hyacc is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Hyacc is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Hyacc; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _LANE_TRACING_H_
#define _LANE_TRACING_H_
#include "y.h"
/*
* lane_tracing.h
*
* Used by lane_tracing.c and lrk.c only.
*
* @Author: Xin Chen
* @Created on: 7/26/2008
* @Last modified: 3/24/2009
*/
#define DEBUG_EdgePushing 0
/*
* A macro to determine if a config is the goal production
* of state 0. Used for getting the "$end" context
* before testA() in lane-tracing.
* Single it out and put here, so it's easier to understand.
*/
#define IS_GOAL(o) (o->owner->state_no == 0 && o->ruleID == 0)
/** Data structure for the state-combination in phase 2 table. START */
typedef struct _llist_int llist_int; /* linked list of states */
struct _llist_int {
int n;
llist_int * next;
};
/*
* Similar to llist_int, but has two int fields.
* Used by LT_cluster only.
*/
typedef struct _llist_int2 llist_int2; /* linked list of states */
struct _llist_int2 {
int n1;
int n2;
llist_int2 * next;
};
typedef struct _llist_context_set llist_context_set;
struct _llist_context_set {
Configuration * config; // in INC order of config->ruleID.
SymbolList ctxt; // in INC order of symbol.
llist_context_set * next;
};
/*
* to get a State pointer from the state_no, use
* states_new_array->state_list[state_no].
*/
typedef struct _LT_tbl_entry LT_tbl_entry;
struct _LT_tbl_entry {
BOOL processed; // whether this entry was processed during regeration.
int from_state;
llist_context_set * ctxt_set; // in INC order of config->ruleID.
llist_int * to_states; // in INC order of state_no.
LT_tbl_entry * next;
};
/*
* For state combining purpose.
*/
typedef struct _LT_cluster LT_cluster;
struct _LT_cluster {
BOOL pairwise_disjoint;
llist_int2 * states; // in INC order of state_no.
llist_context_set * ctxt_set; // in INC order of config->ruleID.
LT_cluster * next;
};
extern LT_cluster * all_clusters;
/* Functions */
extern LT_tbl_entry * LT_tbl_entry_find(State * from);
extern LT_cluster * find_actual_containing_cluster(int state_no);
extern void cluster_dump(LT_cluster * c);
extern llist_int * llist_int_add_inc(llist_int * list, int n);
extern int cluster_contain_state(LT_cluster * c, int state_no);
extern llist_int2 * llist_int2_find_n2(llist_int2 * list, int n2);
extern void llist_int_dump(llist_int * list);
/*
* Data structures in lrk.c
*/
/*
* For conflicting lanes' head states and associated conflicting contexts.
*/
typedef struct laneHeadState laneHead;
struct laneHeadState {
State * s; // conflicting lane head state.
SymbolList contexts; // list of conflicting contexts.
laneHead * next;
};
/*
* For (conflict_config, lane_end_config) pairs.
*/
typedef struct _ConfigPairNode ConfigPairNode;
struct _ConfigPairNode {
Configuration * end; // conflict_config
Configuration * start; // lane_start_config
ConfigPairNode * next;
};
typedef ConfigPairNode * ConfigPairList;
extern ConfigPairList lane_head_tail_pairs;
/*
* For parsing table extention on LR(k).
*/
typedef struct _LRk_contextListNode LRk_contextListNode;
struct _LRk_contextListNode {
int k; // level of k in LR(k).
SymbolList context; // context symbols.
int context_count; // basically this is useless but keep it here.
LRk_contextListNode * next; // to next context list of higher k in LR(k)
};
typedef struct _LRk_configListNode LRk_configListNode;
struct _LRk_configListNode {
Configuration * config;
LRk_contextListNode * ctxt_list;
LRk_configListNode * next;
};
typedef struct _LRk_PT_entry LRk_PT_entry;
struct _LRk_PT_entry {
int state;
SymbolTblNode * token;
LRk_configListNode * cfg_list;
int conflict_count; // 0 if no conflict. can be > 1, but counted as 1
// when report in statistics.
LRk_PT_entry * next;
};
LRk_PT_entry * LRk_PT; // extension parsing table for LR(k).
/*
* Functions in lane_tracing.c
*/
extern laneHead * trace_back(
Configuration * c0, Configuration * c, laneHead * lh_list);
extern void trace_back_lrk(
Configuration * c0, Configuration * c);
extern void trace_back_lrk_clear(
Configuration * c0, Configuration * c);
/*
* Functions in lrk.c
*/
extern void lane_tracing_LR_k();
/*
* Functions in lrk_util.c
*/
extern ConfigPairList ConfigPairList_combine(
ConfigPairList t, ConfigPairList s);
extern ConfigPairList ConfigPairList_insert(ConfigPairList list,
Configuration * conflict_config, Configuration * lane_start_config);
extern void ConfigPairList_dump(ConfigPairList list);
extern ConfigPairNode * ConfigPairList_find(
ConfigPairList list, Configuration * conflict_config);
extern void ConfigPairList_destroy(ConfigPairList list);
// Set - a linked list of objects.
typedef struct _Object_item Object_item;
struct _Object_item {
void * object;
Object_item * next;
};
typedef Object_item Set;
extern Set * Set_insert(Set * set, void * object);
extern Object_item * Set_find(Set * set, void * object);
extern Set * Set_delete(Set * set, void * object);
extern void Set_dump(Set * set, void (* set_item_dump)(void *));
// List - a single linked list.
typedef struct {
int count;
Object_item * head;
Object_item * tail;
} List;
extern List * List_create();
extern void List_insert_tail(List * t, void * object);
extern void List_destroy(List * t);
extern void List_dump(List * t, void (* list_item_dump)(void *));
extern void print_symbolList(void * object);
//
// LRk_P_T - LR(k) parsing table.
//
#define CONST_CONFLICT_SYMBOL -10000010
typedef struct _LRk_P_T_row LRk_P_T_row;
struct _LRk_P_T_row {
int state;
SymbolNode * token;
ConfigPairNode ** row;
LRk_P_T_row * next;
};
#define LRk_P_T_INIT_SIZE 10
#define LRk_P_T_INC 10
// LR(k) parsing table.
typedef struct {
int k; // k in LR(k).
int row_count; // number of rows.
LRk_P_T_row * rows;
} LRk_P_T;
extern LRk_P_T * LRk_P_T_create(int k);
extern void LRk_P_T_dump(LRk_P_T * t);
extern LRk_P_T_row * LRk_P_T_find(LRk_P_T * t,
int state, SymbolTblNode * token, int * found);
extern ConfigPairNode * LRk_P_T_getEntry(LRk_P_T * t, int state,
SymbolTblNode * token, SymbolTblNode * col_token, int * exist);
extern BOOL LRk_P_T_addReduction(LRk_P_T * t,
int state, SymbolTblNode * token,
SymbolTblNode * s, Configuration * c, Configuration * c_tail);
//
// LR(k) parsing table array.
//
typedef struct {
LRk_P_T ** array;
int max_k; // number of entries in array is max_k - 1.
int size; // 0 <= max_k - 2 <= size - 1
} LRk_P_T_Array;
extern LRk_P_T_Array * lrk_pt_array; // defined in lrk.c
extern LRk_P_T_Array * LRk_P_T_Array_create();
extern void LRk_P_T_Array_add(LRk_P_T_Array * a, LRk_P_T * t);
extern LRk_P_T * LRk_P_T_Array_get(LRk_P_T_Array * a, int k);
extern void LRk_P_T_Array_dump(LRk_P_T_Array * a);
extern void LRk_P_T_Array_dump_FILE(LRk_P_T_Array * a);
//
// for (configuration, conflict context) pair
//
typedef struct {
Configuration * c;
SymbolList ctxt; // conflict context symbols
Configuration * tail;
} cfg_ctxt;
extern cfg_ctxt * cfg_ctxt_create(
Configuration * c, SymbolList s, Configuration * tail);
extern void cfg_ctxt_destroy(cfg_ctxt * cc);
extern void cfg_ctxt_dump(cfg_ctxt * cc);
// for LR(k) theads.
extern List * lrk_theads(SymbolList alpha, int k);
// in the lane_tracing of edge_pushing.
extern BOOL IN_EDGE_PUSHING_LANE_TRACING;
extern Configuration * cur_red_config;
extern SymbolList EDGE_PUSHING_CONTEXT_GENERATED;
#endif