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