95 |
/* Be ready to map a state_number_t to an int. */ |
/* Be ready to map a state_number_t to an int. */ |
96 |
# define state_number_as_int(Tok) ((int) (Tok)) |
# define state_number_as_int(Tok) ((int) (Tok)) |
97 |
|
|
98 |
|
|
99 |
|
typedef struct state_s state_t; |
100 |
|
|
101 |
/*--------------. |
/*--------------. |
102 |
| Transitions. | |
| Transitions. | |
103 |
`--------------*/ |
`--------------*/ |
105 |
typedef struct transtion_s |
typedef struct transtion_s |
106 |
{ |
{ |
107 |
short num; |
short num; |
108 |
state_number_t states[1]; |
state_t *states[1]; |
109 |
} transitions_t; |
} transitions_t; |
110 |
|
|
111 |
|
|
114 |
token), or non terminals in case of gotos. */ |
token), or non terminals in case of gotos. */ |
115 |
|
|
116 |
#define TRANSITION_SYMBOL(Transitions, Num) \ |
#define TRANSITION_SYMBOL(Transitions, Num) \ |
117 |
(states[Transitions->states[Num]]->accessing_symbol) |
(Transitions->states[Num]->accessing_symbol) |
118 |
|
|
119 |
/* Is the TRANSITIONS->states[Num] a shift? (as opposed to gotos). */ |
/* Is the TRANSITIONS->states[Num] a shift? (as opposed to gotos). */ |
120 |
|
|
135 |
disabled. */ |
disabled. */ |
136 |
|
|
137 |
#define TRANSITION_DISABLE(Transitions, Num) \ |
#define TRANSITION_DISABLE(Transitions, Num) \ |
138 |
(Transitions->states[Num] = 0) |
(Transitions->states[Num] = NULL) |
139 |
|
|
140 |
#define TRANSITION_IS_DISABLED(Transitions, Num) \ |
#define TRANSITION_IS_DISABLED(Transitions, Num) \ |
141 |
(Transitions->states[Num] == 0) |
(Transitions->states[Num] == NULL) |
142 |
|
|
143 |
|
|
144 |
|
/* Iterate over each transition over a token (shifts). */ |
145 |
|
#define FOR_EACH_SHIFT(Transitions, Iter) \ |
146 |
|
for (Iter = 0; \ |
147 |
|
Iter < Transitions->num \ |
148 |
|
&& (TRANSITION_IS_DISABLED (Transitions, Iter) \ |
149 |
|
|| TRANSITION_IS_SHIFT (Transitions, Iter)); \ |
150 |
|
++Iter) \ |
151 |
|
if (!TRANSITION_IS_DISABLED (Transitions, Iter)) |
152 |
|
|
153 |
|
|
154 |
/* Return the state such these TRANSITIONS contain a shift/goto to it on |
/* Return the state such these TRANSITIONS contain a shift/goto to it on |
155 |
SYMBOL. Aborts if none found. */ |
SYMBOL. Aborts if none found. */ |
165 |
typedef struct errs_s |
typedef struct errs_s |
166 |
{ |
{ |
167 |
short num; |
short num; |
168 |
symbol_number_t symbols[1]; |
symbol_t *symbols[1]; |
169 |
} errs_t; |
} errs_t; |
170 |
|
|
171 |
errs_t *errs_new PARAMS ((int num, symbol_number_t *tokens)); |
errs_t *errs_new PARAMS ((int num, symbol_t **tokens)); |
172 |
|
|
173 |
|
|
174 |
/*-------------. |
/*-------------. |
178 |
typedef struct reductions_s |
typedef struct reductions_s |
179 |
{ |
{ |
180 |
short num; |
short num; |
181 |
rule_number_t rules[1]; |
rule_t *rules[1]; |
182 |
} reductions_t; |
} reductions_t; |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
/*----------. |
/*---------. |
187 |
| State_t. | |
| States. | |
188 |
`----------*/ |
`---------*/ |
189 |
|
|
190 |
typedef struct state_s |
struct state_s |
191 |
{ |
{ |
192 |
state_number_t number; |
state_number_t number; |
193 |
symbol_number_t accessing_symbol; |
symbol_number_t accessing_symbol; |
217 |
*/ |
*/ |
218 |
unsigned short nitems; |
unsigned short nitems; |
219 |
item_number_t items[1]; |
item_number_t items[1]; |
220 |
} state_t; |
}; |
221 |
|
|
222 |
extern state_number_t nstates; |
extern state_number_t nstates; |
223 |
extern state_t *final_state; |
extern state_t *final_state; |
228 |
|
|
229 |
/* Set the transitions of STATE. */ |
/* Set the transitions of STATE. */ |
230 |
void state_transitions_set PARAMS ((state_t *state, |
void state_transitions_set PARAMS ((state_t *state, |
231 |
int num, state_number_t *transitions)); |
int num, state_t **transitions)); |
232 |
|
|
233 |
/* Set the reductions of STATE. */ |
/* Set the reductions of STATE. */ |
234 |
void state_reductions_set PARAMS ((state_t *state, |
void state_reductions_set PARAMS ((state_t *state, |
235 |
int num, rule_number_t *reductions)); |
int num, rule_t **reductions)); |
236 |
|
|
237 |
/* Set the errs of STATE. */ |
/* Set the errs of STATE. */ |
238 |
void state_errs_set PARAMS ((state_t *state, |
void state_errs_set PARAMS ((state_t *state, |
239 |
int num, symbol_number_t *errs)); |
int num, symbol_t **errs)); |
240 |
|
|
241 |
/* Print on OUT all the lookaheads such that this STATE wants to |
/* Print on OUT all the lookaheads such that this STATE wants to |
242 |
reduce this RULE. */ |
reduce this RULE. */ |