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