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