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