20 |
|
|
21 |
|
|
22 |
#include "system.h" |
#include "system.h" |
23 |
|
#include "complain.h" |
24 |
#include "gram.h" |
#include "gram.h" |
25 |
#include "state.h" |
#include "state.h" |
26 |
|
|
27 |
|
|
28 |
|
/*-------------------. |
29 |
|
| Shifts and Gotos. | |
30 |
|
`-------------------*/ |
31 |
|
|
32 |
|
|
33 |
/*---------------------------------. |
/*---------------------------------. |
34 |
| Create a new array of N shitfs. | |
| Create a new array of N shitfs. | |
35 |
`---------------------------------*/ |
`---------------------------------*/ |
47 |
} |
} |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
/*--------------------. |
53 |
|
| Error transitions. | |
54 |
|
`--------------------*/ |
55 |
|
|
56 |
|
|
57 |
/*-------------------------------. |
/*-------------------------------. |
58 |
| Create a new array of N errs. | |
| Create a new array of N errs. | |
59 |
`-------------------------------*/ |
`-------------------------------*/ |
80 |
return res; |
return res; |
81 |
} |
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
/*-------------. |
87 |
|
| Reductions. | |
88 |
|
`-------------*/ |
89 |
|
|
90 |
|
|
91 |
/*-------------------------------------. |
/*-------------------------------------. |
92 |
| Create a new array of N reductions. | |
| Create a new array of N reductions. | |
93 |
`-------------------------------------*/ |
`-------------------------------------*/ |
104 |
return res; |
return res; |
105 |
} |
} |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
/*---------. |
110 |
|
| States. | |
111 |
|
`---------*/ |
112 |
|
|
113 |
|
|
114 |
|
state_number_t nstates = 0; |
115 |
|
/* FINAL_STATE is properly set by new_state when it recognizes its |
116 |
|
accessing symbol: EOF. */ |
117 |
|
state_t *final_state = NULL; |
118 |
|
|
119 |
|
/*------------------------------------------------------------. |
120 |
|
| Create a new state with ACCESSING_SYMBOL, for those items. | |
121 |
|
`------------------------------------------------------------*/ |
122 |
|
|
123 |
|
state_t * |
124 |
|
state_new (symbol_number_t accessing_symbol, |
125 |
|
size_t core_size, item_number_t *core) |
126 |
|
{ |
127 |
|
state_t *res; |
128 |
|
|
129 |
|
if (nstates >= STATE_NUMBER_MAX) |
130 |
|
fatal (_("too many states (max %d)"), STATE_NUMBER_MAX); |
131 |
|
|
132 |
|
#define STATE_ALLOC(Nitems) \ |
133 |
|
(state_t *) xcalloc ((unsigned) (sizeof (state_t) \ |
134 |
|
+ (Nitems - 1) * sizeof (item_number_t)), 1) |
135 |
|
|
136 |
|
res = STATE_ALLOC (core_size); |
137 |
|
res->accessing_symbol = accessing_symbol; |
138 |
|
res->number = nstates; |
139 |
|
++nstates; |
140 |
|
res->solved_conflicts = NULL; |
141 |
|
|
142 |
|
res->nitems = core_size; |
143 |
|
memcpy (res->items, core, core_size * sizeof (core[0])); |
144 |
|
|
145 |
|
return res; |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
/*--------------------------------------------------------------. |
/*--------------------------------------------------------------. |
150 |
| Print on OUT all the lookaheads such that this STATE wants to | |
| Print on OUT all the lookaheads such that this STATE wants to | |