88 |
%union |
%union |
89 |
{ |
{ |
90 |
symbol_t *symbol; |
symbol_t *symbol; |
91 |
|
symbol_list *list; |
92 |
int integer; |
int integer; |
93 |
char *string; |
char *string; |
94 |
associativity assoc; |
associativity assoc; |
145 |
%type <integer> INT |
%type <integer> INT |
146 |
%type <symbol> ID symbol string_as_id |
%type <symbol> ID symbol string_as_id |
147 |
%type <assoc> precedence_declarator |
%type <assoc> precedence_declarator |
148 |
|
%type <list> symbols.1 |
149 |
%% |
%% |
150 |
|
|
151 |
input: |
input: |
212 |
current_class = unknown_sym; |
current_class = unknown_sym; |
213 |
current_type = NULL; |
current_type = NULL; |
214 |
} |
} |
215 |
| "%type" TYPE {current_type = $2; } nterms_to_type.1 |
| "%type" TYPE symbols.1 |
216 |
{ |
{ |
217 |
current_type = NULL; |
symbol_list *list; |
218 |
|
for (list = $3; list; list = list->next) |
219 |
|
symbol_type_set (list->sym, list->location, $2); |
220 |
|
LIST_FREE (symbol_list, $3); |
221 |
} |
} |
222 |
; |
; |
223 |
|
|
224 |
precedence_declaration: |
precedence_declaration: |
225 |
precedence_declarator type.opt |
precedence_declarator type.opt symbols.1 |
226 |
{ current_assoc = $1; ++current_prec; } |
{ |
227 |
terms_to_prec.1 |
symbol_list *list; |
228 |
{ current_assoc = non_assoc; current_type = NULL; } |
++current_prec; |
229 |
|
for (list = $3; list; list = list->next) |
230 |
|
{ |
231 |
|
symbol_type_set (list->sym, list->location, current_type); |
232 |
|
symbol_precedence_set (list->sym, list->location, current_prec, $1); |
233 |
|
} |
234 |
|
LIST_FREE (symbol_list, $3); |
235 |
|
current_type = NULL; |
236 |
|
} |
237 |
; |
; |
238 |
|
|
239 |
precedence_declarator: |
precedence_declarator: |
248 |
; |
; |
249 |
|
|
250 |
/* One or more nonterminals to be %typed. */ |
/* One or more nonterminals to be %typed. */ |
|
nterms_to_type.1: |
|
|
ID { symbol_type_set ($1, current_type); } |
|
|
| nterms_to_type.1 ID { symbol_type_set ($2, current_type); } |
|
|
; |
|
251 |
|
|
252 |
/* One or more symbols to be given a precedence/associativity. */ |
symbols.1: |
253 |
terms_to_prec.1: |
symbol { $$ = symbol_list_new ($1, @1); } |
254 |
symbol |
| symbols.1 symbol { $$ = symbol_list_prepend ($1, $2, @2); } |
|
{ |
|
|
symbol_type_set ($1, current_type); |
|
|
symbol_precedence_set ($1, current_prec, current_assoc); |
|
|
} |
|
|
| terms_to_prec.1 symbol |
|
|
{ |
|
|
symbol_type_set ($2, current_type); |
|
|
symbol_precedence_set ($2, current_prec, current_assoc); |
|
|
} |
|
255 |
; |
; |
256 |
|
|
257 |
/* One token definition. */ |
/* One token definition. */ |
263 |
| ID |
| ID |
264 |
{ |
{ |
265 |
symbol_class_set ($1, current_class); |
symbol_class_set ($1, current_class); |
266 |
symbol_type_set ($1, current_type); |
symbol_type_set ($1, @1, current_type); |
267 |
} |
} |
268 |
| ID INT |
| ID INT |
269 |
{ |
{ |
270 |
symbol_class_set ($1, current_class); |
symbol_class_set ($1, current_class); |
271 |
symbol_type_set ($1, current_type); |
symbol_type_set ($1, @1, current_type); |
272 |
symbol_user_token_number_set ($1, $2); |
symbol_user_token_number_set ($1, $2); |
273 |
} |
} |
274 |
| ID string_as_id |
| ID string_as_id |
275 |
{ |
{ |
276 |
symbol_class_set ($1, current_class); |
symbol_class_set ($1, current_class); |
277 |
symbol_type_set ($1, current_type); |
symbol_type_set ($1, @1, current_type); |
278 |
symbol_make_alias ($1, $2); |
symbol_make_alias ($1, $2); |
279 |
} |
} |
280 |
| ID INT string_as_id |
| ID INT string_as_id |
281 |
{ |
{ |
282 |
symbol_class_set ($1, current_class); |
symbol_class_set ($1, current_class); |
283 |
symbol_type_set ($1, current_type); |
symbol_type_set ($1, @1, current_type); |
284 |
symbol_user_token_number_set ($1, $2); |
symbol_user_token_number_set ($1, $2); |
285 |
symbol_make_alias ($1, $3); |
symbol_make_alias ($1, $3); |
286 |
} |
} |