30 |
|
|
31 |
%{ |
%{ |
32 |
#include "system.h" |
#include "system.h" |
33 |
|
|
34 |
#include "complain.h" |
#include "complain.h" |
35 |
#include "muscle_tab.h" |
#include "conflicts.h" |
36 |
#include "files.h" |
#include "files.h" |
37 |
#include "getargs.h" |
#include "getargs.h" |
|
#include "output.h" |
|
|
#include "symlist.h" |
|
38 |
#include "gram.h" |
#include "gram.h" |
39 |
|
#include "muscle_tab.h" |
40 |
|
#include "output.h" |
41 |
#include "reader.h" |
#include "reader.h" |
42 |
#include "conflicts.h" |
#include "symlist.h" |
43 |
|
|
44 |
/* Produce verbose syntax errors. */ |
/* Produce verbose syntax errors. */ |
45 |
#define YYERROR_VERBOSE 1 |
#define YYERROR_VERBOSE 1 |
52 |
#undef yyerror |
#undef yyerror |
53 |
#define yyerror(Msg) \ |
#define yyerror(Msg) \ |
54 |
gram_error (&yylloc, Msg) |
gram_error (&yylloc, Msg) |
55 |
static void gram_error (location_t const *, char const *); |
static void gram_error (location const *, char const *); |
56 |
|
|
57 |
#define YYPRINT(File, Type, Value) \ |
#define YYPRINT(File, Type, Value) \ |
58 |
print_token_value (File, Type, &Value) |
print_token_value (File, Type, &Value) |
59 |
static void print_token_value (FILE *, int, YYSTYPE const *); |
static void print_token_value (FILE *, int, YYSTYPE const *); |
60 |
|
|
61 |
static void add_param (char const *, char const *, location_t); |
static void add_param (char const *, char const *, location); |
62 |
|
|
63 |
symbol_class current_class = unknown_sym; |
symbol_class current_class = unknown_sym; |
64 |
struniq_t current_type = 0; |
uniqstr current_type = 0; |
65 |
symbol_t *current_lhs; |
symbol *current_lhs; |
66 |
location_t current_lhs_location; |
location current_lhs_location; |
67 |
assoc_t current_assoc; |
assoc current_assoc; |
68 |
int current_prec = 0; |
int current_prec = 0; |
69 |
braced_code_t current_braced_code = action_braced_code; |
braced_code current_braced_code = action_braced_code; |
70 |
%} |
%} |
71 |
|
|
72 |
|
|
73 |
/* Only NUMBERS have a value. */ |
/* Only NUMBERS have a value. */ |
74 |
%union |
%union |
75 |
{ |
{ |
76 |
symbol_t *symbol; |
symbol *symbol; |
77 |
symbol_list_t *list; |
symbol_list *list; |
78 |
int integer; |
int integer; |
79 |
char *string; |
char *chars; |
80 |
assoc_t assoc; |
assoc assoc; |
81 |
struniq_t struniq; |
uniqstr uniqstr; |
82 |
}; |
}; |
83 |
|
|
84 |
/* Define the tokens together with their human representation. */ |
/* Define the tokens together with their human representation. */ |
142 |
%token BRACED_CODE "{...}" |
%token BRACED_CODE "{...}" |
143 |
|
|
144 |
|
|
145 |
%type <string> STRING string_content |
%type <chars> STRING string_content |
146 |
BRACED_CODE code_content action |
BRACED_CODE code_content action |
147 |
PROLOGUE EPILOGUE |
PROLOGUE EPILOGUE |
148 |
%type <struniq> TYPE |
%type <uniqstr> TYPE |
149 |
%type <integer> INT |
%type <integer> INT |
150 |
%type <symbol> ID ID_COLON symbol string_as_id |
%type <symbol> ID ID_COLON symbol string_as_id |
151 |
%type <assoc> precedence_declarator |
%type <assoc> precedence_declarator |
207 |
{ current_braced_code = destructor_braced_code; } |
{ current_braced_code = destructor_braced_code; } |
208 |
BRACED_CODE symbols.1 |
BRACED_CODE symbols.1 |
209 |
{ |
{ |
210 |
symbol_list_t *list; |
symbol_list *list; |
211 |
for (list = $4; list; list = list->next) |
for (list = $4; list; list = list->next) |
212 |
symbol_destructor_set (list->sym, $3, @3); |
symbol_destructor_set (list->sym, $3, @3); |
213 |
symbol_list_free ($4); |
symbol_list_free ($4); |
217 |
{ current_braced_code = printer_braced_code; } |
{ current_braced_code = printer_braced_code; } |
218 |
BRACED_CODE symbols.1 |
BRACED_CODE symbols.1 |
219 |
{ |
{ |
220 |
symbol_list_t *list; |
symbol_list *list; |
221 |
for (list = $4; list; list = list->next) |
for (list = $4; list; list = list->next) |
222 |
symbol_printer_set (list->sym, $3, list->location); |
symbol_printer_set (list->sym, $3, list->location); |
223 |
symbol_list_free ($4); |
symbol_list_free ($4); |
238 |
} |
} |
239 |
| "%type" TYPE symbols.1 |
| "%type" TYPE symbols.1 |
240 |
{ |
{ |
241 |
symbol_list_t *list; |
symbol_list *list; |
242 |
for (list = $3; list; list = list->next) |
for (list = $3; list; list = list->next) |
243 |
symbol_type_set (list->sym, $2, @2); |
symbol_type_set (list->sym, $2, @2); |
244 |
symbol_list_free ($3); |
symbol_list_free ($3); |
248 |
precedence_declaration: |
precedence_declaration: |
249 |
precedence_declarator type.opt symbols.1 |
precedence_declarator type.opt symbols.1 |
250 |
{ |
{ |
251 |
symbol_list_t *list; |
symbol_list *list; |
252 |
++current_prec; |
++current_prec; |
253 |
for (list = $3; list; list = list->next) |
for (list = $3; list; list = list->next) |
254 |
{ |
{ |
449 |
declaration DECL and location LOC. */ |
declaration DECL and location LOC. */ |
450 |
|
|
451 |
static void |
static void |
452 |
add_param (char const *type, char const *decl, location_t loc) |
add_param (char const *type, char const *decl, location loc) |
453 |
{ |
{ |
454 |
static char const alphanum[] = |
static char const alphanum[] = |
455 |
"0123456789" |
"0123456789" |
505 |
break; |
break; |
506 |
|
|
507 |
case STRING: |
case STRING: |
508 |
fprintf (file, " = \"%s\"", value->string); |
fprintf (file, " = \"%s\"", value->chars); |
509 |
break; |
break; |
510 |
|
|
511 |
case TYPE: |
case TYPE: |
512 |
fprintf (file, " = <%s>", value->struniq); |
fprintf (file, " = <%s>", value->uniqstr); |
513 |
break; |
break; |
514 |
|
|
515 |
case BRACED_CODE: |
case BRACED_CODE: |
516 |
case PROLOGUE: |
case PROLOGUE: |
517 |
case EPILOGUE: |
case EPILOGUE: |
518 |
fprintf (file, " = {{ %s }}", value->string); |
fprintf (file, " = {{ %s }}", value->chars); |
519 |
break; |
break; |
520 |
|
|
521 |
default: |
default: |
525 |
} |
} |
526 |
|
|
527 |
static void |
static void |
528 |
gram_error (location_t const *loc, char const *msg) |
gram_error (location const *loc, char const *msg) |
529 |
{ |
{ |
530 |
complain_at (*loc, "%s", msg); |
complain_at (*loc, "%s", msg); |
531 |
} |
} |