]> git.saurik.com Git - bison.git/blob - src/parse-gram.y
lalr1.cc: syntax_error as exceptions.
[bison.git] / src / parse-gram.y
1 %{/* Bison Grammar Parser -*- C -*-
2
3 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software
4 Foundation, Inc.
5
6 This file is part of Bison, the GNU Compiler Compiler.
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 #include <config.h>
22 #include "system.h"
23
24 #include "complain.h"
25 #include "conflicts.h"
26 #include "files.h"
27 #include "getargs.h"
28 #include "gram.h"
29 #include "muscle-tab.h"
30 #include "named-ref.h"
31 #include "quotearg.h"
32 #include "reader.h"
33 #include "symlist.h"
34 #include "scan-gram.h"
35 #include "scan-code.h"
36
37 #define YYLLOC_DEFAULT(Current, Rhs, N) (Current) = lloc_default (Rhs, N)
38 static YYLTYPE lloc_default (YYLTYPE const *, int);
39
40 #define YY_LOCATION_PRINT(File, Loc) \
41 location_print (File, Loc)
42
43 static void version_check (location const *loc, char const *version);
44
45 /* Request detailed syntax error messages, and pass them to GRAM_ERROR.
46 FIXME: depends on the undocumented availability of YYLLOC. */
47 #undef yyerror
48 #define yyerror(Msg) \
49 gram_error (&yylloc, Msg)
50 static void gram_error (location const *, char const *);
51
52 static char const *char_name (char);
53 %}
54
55 %code
56 {
57 static int current_prec = 0;
58 static location current_lhs_location;
59 static named_ref *current_lhs_named_ref;
60 static symbol *current_lhs;
61 static symbol_class current_class = unknown_sym;
62 static uniqstr current_type = NULL;
63
64 #define YYTYPE_INT16 int_fast16_t
65 #define YYTYPE_INT8 int_fast8_t
66 #define YYTYPE_UINT16 uint_fast16_t
67 #define YYTYPE_UINT8 uint_fast8_t
68 }
69
70 %debug
71 %verbose
72 %defines
73 %locations
74 %pure-parser
75 %define parse.error "verbose"
76 %name-prefix="gram_"
77 %expect 0
78
79 %initial-action
80 {
81 /* Bison's grammar can initial empty locations, hence a default
82 location is needed. */
83 boundary_set (&@$.start, current_file, 1, 1);
84 boundary_set (&@$.end, current_file, 1, 1);
85 }
86
87 %union
88 {
89 assoc assoc;
90 char *code;
91 char const *chars;
92 int integer;
93 named_ref *named_ref;
94 symbol *symbol;
95 symbol_list *list;
96 uniqstr uniqstr;
97 unsigned char character;
98 };
99
100 /* Define the tokens together with their human representation. */
101 %token GRAM_EOF 0 "end of file"
102 %token STRING "string"
103 %token INT "integer"
104
105 %token PERCENT_TOKEN "%token"
106 %token PERCENT_NTERM "%nterm"
107
108 %token PERCENT_TYPE "%type"
109 %token PERCENT_DESTRUCTOR "%destructor"
110 %token PERCENT_PRINTER "%printer"
111
112 %token PERCENT_LEFT "%left"
113 %token PERCENT_RIGHT "%right"
114 %token PERCENT_NONASSOC "%nonassoc"
115 %token PERCENT_PRECEDENCE "%precedence"
116
117 %token PERCENT_PREC "%prec"
118 %token PERCENT_DPREC "%dprec"
119 %token PERCENT_MERGE "%merge"
120
121
122 /*----------------------.
123 | Global Declarations. |
124 `----------------------*/
125
126 %token
127 PERCENT_CODE "%code"
128 PERCENT_DEFAULT_PREC "%default-prec"
129 PERCENT_DEFINE "%define"
130 PERCENT_DEFINES "%defines"
131 PERCENT_ERROR_VERBOSE "%error-verbose"
132 PERCENT_EXPECT "%expect"
133 PERCENT_EXPECT_RR "%expect-rr"
134 PERCENT_FLAG "%<flag>"
135 PERCENT_FILE_PREFIX "%file-prefix"
136 PERCENT_GLR_PARSER "%glr-parser"
137 PERCENT_INITIAL_ACTION "%initial-action"
138 PERCENT_LANGUAGE "%language"
139 PERCENT_NAME_PREFIX "%name-prefix"
140 PERCENT_NO_DEFAULT_PREC "%no-default-prec"
141 PERCENT_NO_LINES "%no-lines"
142 PERCENT_NONDETERMINISTIC_PARSER
143 "%nondeterministic-parser"
144 PERCENT_OUTPUT "%output"
145 PERCENT_REQUIRE "%require"
146 PERCENT_SKELETON "%skeleton"
147 PERCENT_START "%start"
148 PERCENT_TOKEN_TABLE "%token-table"
149 PERCENT_VERBOSE "%verbose"
150 PERCENT_YACC "%yacc"
151 ;
152
153 %token BRACED_CODE "{...}"
154 %token CHAR "char"
155 %token EPILOGUE "epilogue"
156 %token EQUAL "="
157 %token ID "identifier"
158 %token ID_COLON "identifier:"
159 %token PERCENT_PERCENT "%%"
160 %token PIPE "|"
161 %token PROLOGUE "%{...%}"
162 %token SEMICOLON ";"
163 %token TAG "<tag>"
164 %token TAG_ANY "<*>"
165 %token TAG_NONE "<>"
166 %token BRACKETED_ID "[identifier]"
167
168 %type <character> CHAR
169 %printer { fputs (char_name ($$), stderr); } CHAR
170
171 /* braceless is not to be used for rule or symbol actions, as it
172 calls code_props_plain_init. */
173 %type <chars> STRING "%{...%}" EPILOGUE braceless content.opt
174 %type <code> "{...}"
175 %printer { fputs (quotearg_style (c_quoting_style, $$), stderr); }
176 STRING
177 %printer { fprintf (stderr, "{\n%s\n}", $$); }
178 braceless content.opt "{...}" "%{...%}" EPILOGUE
179
180 %type <uniqstr> TAG ID ID_COLON BRACKETED_ID PERCENT_FLAG variable
181 %type <named_ref> named_ref.opt
182 %printer { fputs ($$, stderr); } ID variable
183 %printer { fprintf (stderr, "%s:", $$); } ID_COLON
184 %printer { fprintf (stderr, "%%%s", $$); } PERCENT_FLAG
185 %printer { fprintf (stderr, "<%s>", $$); } TAG
186
187 %type <integer> INT
188 %printer { fprintf (stderr, "%d", $$); } INT
189
190 %type <symbol> id id_colon symbol symbol.prec string_as_id
191 %printer { fprintf (stderr, "%s", $$->tag); } id symbol string_as_id
192 %printer { fprintf (stderr, "%s:", $$->tag); } id_colon
193
194 %type <assoc> precedence_declarator
195 %type <list> symbols.1 symbols.prec generic_symlist generic_symlist_item
196
197 /*---------.
198 | %param. |
199 `---------*/
200 %code requires
201 {
202 # ifndef PARAM_TYPE
203 # define PARAM_TYPE
204 typedef enum
205 {
206 param_none = 0,
207 param_lex = 1 << 0,
208 param_parse = 1 << 1,
209 param_both = param_lex | param_parse
210 } param_type;
211 # endif
212 };
213 %code
214 {
215 /** Add a lex-param and/or a parse-param.
216 *
217 * \param type where to push this formal argument.
218 * \param decl the formal argument. Destroyed.
219 * \param loc the location in the source.
220 */
221 static void add_param (param_type type, char *decl, location loc);
222 static param_type current_param = param_none;
223 };
224 %union
225 {
226 param_type param;
227 }
228 %token <param> PERCENT_PARAM "%param";
229 %printer
230 {
231 switch ($$)
232 {
233 #define CASE(In, Out) \
234 case param_ ## In: fputs ("%" #Out, stderr); break
235 CASE(lex, lex-param);
236 CASE(parse, parse-param);
237 CASE(both, param);
238 #undef CASE
239 }
240 } <param>;
241
242
243 /*==========\
244 | Grammar. |
245 \==========*/
246 %%
247
248 input:
249 prologue_declarations "%%" grammar epilogue.opt
250 ;
251
252
253 /*------------------------------------.
254 | Declarations: before the first %%. |
255 `------------------------------------*/
256
257 prologue_declarations:
258 /* Nothing */
259 | prologue_declarations prologue_declaration
260 ;
261
262 prologue_declaration:
263 grammar_declaration
264 | "%{...%}"
265 {
266 code_props plain_code;
267 code_props_plain_init (&plain_code, $1, @1);
268 code_props_translate_code (&plain_code);
269 gram_scanner_last_string_free ();
270 muscle_code_grow (union_seen ? "post_prologue" : "pre_prologue",
271 plain_code.code, @1);
272 code_scanner_last_string_free ();
273 }
274 | "%<flag>"
275 {
276 muscle_percent_define_ensure ($1, @1, true);
277 }
278 | "%define" variable content.opt
279 {
280 muscle_percent_define_insert ($2, @2, $3,
281 MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
282 }
283 | "%defines" { defines_flag = true; }
284 | "%defines" STRING
285 {
286 defines_flag = true;
287 spec_defines_file = xstrdup ($2);
288 }
289 | "%error-verbose"
290 {
291 muscle_percent_define_insert ("parse.error", @1, "verbose",
292 MUSCLE_PERCENT_DEFINE_GRAMMAR_FILE);
293 }
294 | "%expect" INT { expected_sr_conflicts = $2; }
295 | "%expect-rr" INT { expected_rr_conflicts = $2; }
296 | "%file-prefix" STRING { spec_file_prefix = $2; }
297 | "%file-prefix" "=" STRING { spec_file_prefix = $3; } /* deprecated */
298 | "%glr-parser"
299 {
300 nondeterministic_parser = true;
301 glr_parser = true;
302 }
303 | "%initial-action" "{...}"
304 {
305 code_props action;
306 code_props_symbol_action_init (&action, $2, @2);
307 code_props_translate_code (&action);
308 gram_scanner_last_string_free ();
309 muscle_code_grow ("initial_action", action.code, @2);
310 code_scanner_last_string_free ();
311 }
312 | "%language" STRING { language_argmatch ($2, grammar_prio, @1); }
313 | "%name-prefix" STRING { spec_name_prefix = $2; }
314 | "%name-prefix" "=" STRING { spec_name_prefix = $3; } /* deprecated */
315 | "%no-lines" { no_lines_flag = true; }
316 | "%nondeterministic-parser" { nondeterministic_parser = true; }
317 | "%output" STRING { spec_outfile = $2; }
318 | "%output" "=" STRING { spec_outfile = $3; } /* deprecated */
319 | "%param" { current_param = $1; } params { current_param = param_none; }
320 | "%require" STRING { version_check (&@2, $2); }
321 | "%skeleton" STRING
322 {
323 char const *skeleton_user = $2;
324 if (strchr (skeleton_user, '/'))
325 {
326 size_t dir_length = strlen (current_file);
327 char *skeleton_build;
328 while (dir_length && current_file[dir_length - 1] != '/')
329 --dir_length;
330 while (dir_length && current_file[dir_length - 1] == '/')
331 --dir_length;
332 skeleton_build =
333 xmalloc (dir_length + 1 + strlen (skeleton_user) + 1);
334 if (dir_length > 0)
335 {
336 strncpy (skeleton_build, current_file, dir_length);
337 skeleton_build[dir_length++] = '/';
338 }
339 strcpy (skeleton_build + dir_length, skeleton_user);
340 skeleton_user = uniqstr_new (skeleton_build);
341 free (skeleton_build);
342 }
343 skeleton_arg (skeleton_user, grammar_prio, @1);
344 }
345 | "%token-table" { token_table_flag = true; }
346 | "%verbose" { report_flag |= report_states; }
347 | "%yacc" { yacc_flag = true; }
348 | /*FIXME: Err? What is this horror doing here? */ ";"
349 ;
350
351 params:
352 params "{...}" { add_param (current_param, $2, @2); }
353 | "{...}" { add_param (current_param, $1, @1); }
354 ;
355
356
357 /*----------------------.
358 | grammar_declaration. |
359 `----------------------*/
360
361 grammar_declaration:
362 precedence_declaration
363 | symbol_declaration
364 | "%start" symbol
365 {
366 grammar_start_symbol_set ($2, @2);
367 }
368 | "%destructor" "{...}" generic_symlist
369 {
370 symbol_list *list;
371 for (list = $3; list; list = list->next)
372 symbol_list_destructor_set (list, $2, @2);
373 symbol_list_free ($3);
374 }
375 | "%printer" "{...}" generic_symlist
376 {
377 symbol_list *list;
378 for (list = $3; list; list = list->next)
379 symbol_list_printer_set (list, $2, @2);
380 symbol_list_free ($3);
381 }
382 | "%default-prec"
383 {
384 default_prec = true;
385 }
386 | "%no-default-prec"
387 {
388 default_prec = false;
389 }
390 | "%code" braceless
391 {
392 /* Do not invoke muscle_percent_code_grow here since it invokes
393 muscle_user_name_list_grow. */
394 muscle_code_grow ("percent_code()", $2, @2);
395 code_scanner_last_string_free ();
396 }
397 | "%code" ID braceless
398 {
399 muscle_percent_code_grow ($2, @2, $3, @3);
400 code_scanner_last_string_free ();
401 }
402 ;
403
404
405 /*---------.
406 | %union. |
407 `---------*/
408
409 %token PERCENT_UNION "%union";
410
411 union_name:
412 /* Nothing. */ {}
413 | ID { muscle_code_grow ("union_name", $1, @1); }
414 ;
415
416 grammar_declaration:
417 "%union" union_name braceless
418 {
419 union_seen = true;
420 muscle_code_grow ("stype", $3, @3);
421 code_scanner_last_string_free ();
422 }
423 ;
424
425
426
427
428 symbol_declaration:
429 "%nterm" { current_class = nterm_sym; } symbol_defs.1
430 {
431 current_class = unknown_sym;
432 current_type = NULL;
433 }
434 | "%token" { current_class = token_sym; } symbol_defs.1
435 {
436 current_class = unknown_sym;
437 current_type = NULL;
438 }
439 | "%type" TAG symbols.1
440 {
441 symbol_list *list;
442 tag_seen = true;
443 for (list = $3; list; list = list->next)
444 symbol_type_set (list->content.sym, $2, @2);
445 symbol_list_free ($3);
446 }
447 ;
448
449 precedence_declaration:
450 precedence_declarator tag.opt symbols.prec
451 {
452 symbol_list *list;
453 ++current_prec;
454 for (list = $3; list; list = list->next)
455 {
456 symbol_type_set (list->content.sym, current_type, @2);
457 symbol_precedence_set (list->content.sym, current_prec, $1, @1);
458 }
459 symbol_list_free ($3);
460 current_type = NULL;
461 }
462 ;
463
464 precedence_declarator:
465 "%left" { $$ = left_assoc; }
466 | "%right" { $$ = right_assoc; }
467 | "%nonassoc" { $$ = non_assoc; }
468 | "%precedence" { $$ = precedence_assoc; }
469 ;
470
471 tag.opt:
472 /* Nothing. */ { current_type = NULL; }
473 | TAG { current_type = $1; tag_seen = true; }
474 ;
475
476 /* Just like symbols.1 but accept INT for the sake of POSIX. */
477 symbols.prec:
478 symbol.prec
479 { $$ = symbol_list_sym_new ($1, @1); }
480 | symbols.prec symbol.prec
481 { $$ = symbol_list_prepend ($1, symbol_list_sym_new ($2, @2)); }
482 ;
483
484 symbol.prec:
485 symbol { $$ = $1; }
486 | symbol INT { $$ = $1; symbol_user_token_number_set ($1, $2, @2); }
487 ;
488
489 /* One or more symbols to be %typed. */
490 symbols.1:
491 symbol
492 { $$ = symbol_list_sym_new ($1, @1); }
493 | symbols.1 symbol
494 { $$ = symbol_list_prepend ($1, symbol_list_sym_new ($2, @2)); }
495 ;
496
497 generic_symlist:
498 generic_symlist_item { $$ = $1; }
499 | generic_symlist generic_symlist_item { $$ = symbol_list_prepend ($1, $2); }
500 ;
501
502 generic_symlist_item:
503 symbol { $$ = symbol_list_sym_new ($1, @1); }
504 | TAG { $$ = symbol_list_type_new ($1, @1); }
505 | "<*>" { $$ = symbol_list_default_tagged_new (@1); }
506 | "<>" { $$ = symbol_list_default_tagless_new (@1); }
507 ;
508
509 /* One token definition. */
510 symbol_def:
511 TAG
512 {
513 current_type = $1;
514 tag_seen = true;
515 }
516 | id
517 {
518 symbol_class_set ($1, current_class, @1, true);
519 symbol_type_set ($1, current_type, @1);
520 }
521 | id INT
522 {
523 symbol_class_set ($1, current_class, @1, true);
524 symbol_type_set ($1, current_type, @1);
525 symbol_user_token_number_set ($1, $2, @2);
526 }
527 | id string_as_id
528 {
529 symbol_class_set ($1, current_class, @1, true);
530 symbol_type_set ($1, current_type, @1);
531 symbol_make_alias ($1, $2, @$);
532 }
533 | id INT string_as_id
534 {
535 symbol_class_set ($1, current_class, @1, true);
536 symbol_type_set ($1, current_type, @1);
537 symbol_user_token_number_set ($1, $2, @2);
538 symbol_make_alias ($1, $3, @$);
539 }
540 ;
541
542 /* One or more symbol definitions. */
543 symbol_defs.1:
544 symbol_def
545 | symbol_defs.1 symbol_def
546 ;
547
548
549 /*------------------------------------------.
550 | The grammar section: between the two %%. |
551 `------------------------------------------*/
552
553 grammar:
554 rules_or_grammar_declaration
555 | grammar rules_or_grammar_declaration
556 ;
557
558 /* As a Bison extension, one can use the grammar declarations in the
559 body of the grammar. */
560 rules_or_grammar_declaration:
561 rules
562 | grammar_declaration ";"
563 | error ";"
564 {
565 yyerrok;
566 }
567 ;
568
569 rules:
570 id_colon named_ref.opt { current_lhs = $1; current_lhs_location = @1;
571 current_lhs_named_ref = $2; } rhses.1
572 ;
573
574 rhses.1:
575 rhs { grammar_current_rule_end (@1); }
576 | rhses.1 "|" rhs { grammar_current_rule_end (@3); }
577 | rhses.1 ";"
578 ;
579
580 rhs:
581 /* Nothing. */
582 { grammar_current_rule_begin (current_lhs, current_lhs_location,
583 current_lhs_named_ref); }
584 | rhs symbol named_ref.opt
585 { grammar_current_rule_symbol_append ($2, @2, $3); }
586 | rhs "{...}" named_ref.opt
587 { grammar_current_rule_action_append ($2, @2, $3); }
588 | rhs "%prec" symbol
589 { grammar_current_rule_prec_set ($3, @3); }
590 | rhs "%dprec" INT
591 { grammar_current_rule_dprec_set ($3, @3); }
592 | rhs "%merge" TAG
593 { grammar_current_rule_merge_set ($3, @3); }
594 ;
595
596 named_ref.opt:
597 /* Nothing. */ { $$ = 0; }
598 |
599 BRACKETED_ID { $$ = named_ref_new($1, @1); }
600 ;
601
602
603 /*---------------------------.
604 | variable and content.opt. |
605 `---------------------------*/
606
607 /* The STRING form of variable is deprecated and is not M4-friendly.
608 For example, M4 fails for `%define "[" "value"'. */
609 variable:
610 ID
611 | STRING { $$ = uniqstr_new ($1); }
612 ;
613
614 /* Some content or empty by default. */
615 content.opt:
616 /* Nothing. */ { $$ = ""; }
617 | ID { $$ = $1; }
618 | STRING
619 ;
620
621
622 /*------------.
623 | braceless. |
624 `------------*/
625
626 braceless:
627 "{...}"
628 {
629 code_props plain_code;
630 $1[strlen ($1) - 1] = '\n';
631 code_props_plain_init (&plain_code, $1+1, @1);
632 code_props_translate_code (&plain_code);
633 gram_scanner_last_string_free ();
634 $$ = plain_code.code;
635 }
636 ;
637
638
639 /*--------------.
640 | Identifiers. |
641 `--------------*/
642
643 /* Identifiers are returned as uniqstr values by the scanner.
644 Depending on their use, we may need to make them genuine symbols. */
645
646 id:
647 ID
648 { $$ = symbol_from_uniqstr ($1, @1); }
649 | CHAR
650 {
651 $$ = symbol_get (char_name ($1), @1);
652 symbol_class_set ($$, token_sym, @1, false);
653 symbol_user_token_number_set ($$, $1, @1);
654 }
655 ;
656
657 id_colon:
658 ID_COLON { $$ = symbol_from_uniqstr ($1, @1); }
659 ;
660
661
662 symbol:
663 id
664 | string_as_id
665 ;
666
667 /* A string used as an ID: quote it. */
668 string_as_id:
669 STRING
670 {
671 $$ = symbol_get (quotearg_style (c_quoting_style, $1), @1);
672 symbol_class_set ($$, token_sym, @1, false);
673 }
674 ;
675
676 epilogue.opt:
677 /* Nothing. */
678 | "%%" EPILOGUE
679 {
680 code_props plain_code;
681 code_props_plain_init (&plain_code, $2, @2);
682 code_props_translate_code (&plain_code);
683 gram_scanner_last_string_free ();
684 muscle_code_grow ("epilogue", plain_code.code, @2);
685 code_scanner_last_string_free ();
686 }
687 ;
688
689 %%
690
691
692 /* Return the location of the left-hand side of a rule whose
693 right-hand side is RHS[1] ... RHS[N]. Ignore empty nonterminals in
694 the right-hand side, and return an empty location equal to the end
695 boundary of RHS[0] if the right-hand side is empty. */
696
697 static YYLTYPE
698 lloc_default (YYLTYPE const *rhs, int n)
699 {
700 int i;
701 YYLTYPE loc;
702
703 /* SGI MIPSpro 7.4.1m miscompiles "loc.start = loc.end = rhs[n].end;".
704 The bug is fixed in 7.4.2m, but play it safe for now. */
705 loc.start = rhs[n].end;
706 loc.end = rhs[n].end;
707
708 /* Ignore empty nonterminals the start of the the right-hand side.
709 Do not bother to ignore them at the end of the right-hand side,
710 since empty nonterminals have the same end as their predecessors. */
711 for (i = 1; i <= n; i++)
712 if (! equal_boundaries (rhs[i].start, rhs[i].end))
713 {
714 loc.start = rhs[i].start;
715 break;
716 }
717
718 return loc;
719 }
720
721
722 static void
723 add_param (param_type type, char *decl, location loc)
724 {
725 static char const alphanum[26 + 26 + 1 + 10] =
726 "abcdefghijklmnopqrstuvwxyz"
727 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
728 "_"
729 "0123456789";
730
731 char const *name_start = NULL;
732 {
733 char *p;
734 /* Stop on last actual character. */
735 for (p = decl; p[1]; p++)
736 if ((p == decl
737 || ! memchr (alphanum, p[-1], sizeof alphanum))
738 && memchr (alphanum, p[0], sizeof alphanum - 10))
739 name_start = p;
740
741 /* Strip the surrounding '{' and '}', and any blanks just inside
742 the braces. */
743 while (*--p == ' ' || *p == '\t')
744 continue;
745 p[1] = '\0';
746 while (*++decl == ' ' || *decl == '\t')
747 continue;
748 }
749
750 if (! name_start)
751 complain_at (loc, _("missing identifier in parameter declaration"));
752 else
753 {
754 char *name;
755 size_t name_len;
756
757 for (name_len = 1;
758 memchr (alphanum, name_start[name_len], sizeof alphanum);
759 name_len++)
760 continue;
761
762 name = xmalloc (name_len + 1);
763 memcpy (name, name_start, name_len);
764 name[name_len] = '\0';
765 if (type & param_lex)
766 muscle_pair_list_grow ("lex_param", decl, name);
767 if (type & param_parse)
768 muscle_pair_list_grow ("parse_param", decl, name);
769 free (name);
770 }
771
772 gram_scanner_last_string_free ();
773 }
774
775
776 static void
777 version_check (location const *loc, char const *version)
778 {
779 if (strverscmp (version, PACKAGE_VERSION) > 0)
780 {
781 complain_at (*loc, "require bison %s, but have %s",
782 version, PACKAGE_VERSION);
783 exit (63);
784 }
785 }
786
787 static void
788 gram_error (location const *loc, char const *msg)
789 {
790 complain_at (*loc, "%s", msg);
791 }
792
793 char const *
794 token_name (int type)
795 {
796 return yytname[YYTRANSLATE (type)];
797 }
798
799 static char const *
800 char_name (char c)
801 {
802 if (c == '\'')
803 return "'\\''";
804 else
805 {
806 char buf[4];
807 buf[0] = '\''; buf[1] = c; buf[2] = '\''; buf[3] = '\0';
808 return quotearg_style (escape_quoting_style, buf);
809 }
810 }