]> git.saurik.com Git - bison.git/blame - src/parse-gram.y
Add comparison operators for C++ location classes. Discussed at
[bison.git] / src / parse-gram.y
CommitLineData
12ffdd28 1%{/* Bison Grammar Parser -*- C -*-
a737b216 2
073f9288 3 Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
e9955c83
AD
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 2 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, write to the Free Software
0fb669f9
PE
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA
e9955c83
AD
21*/
22
2cec9080 23#include <config.h>
e9955c83 24#include "system.h"
3d2cbc26 25
b275314e 26#include "complain.h"
3d2cbc26 27#include "conflicts.h"
e9955c83
AD
28#include "files.h"
29#include "getargs.h"
e9955c83 30#include "gram.h"
3d2cbc26 31#include "muscle_tab.h"
ca407bdf 32#include "quotearg.h"
e9955c83 33#include "reader.h"
3d2cbc26 34#include "symlist.h"
e9071366
AD
35#include "scan-gram.h"
36#include "scan-code.h"
b50d2359 37#include "strverscmp.h"
e9955c83 38
b7295522
PE
39#define YYLLOC_DEFAULT(Current, Rhs, N) (Current) = lloc_default (Rhs, N)
40static YYLTYPE lloc_default (YYLTYPE const *, int);
4cdb01db 41
b233d555 42#define YY_LOCATION_PRINT(File, Loc) \
f0064700 43 location_print (File, Loc)
b233d555 44
b50d2359
AD
45static void version_check (location const *loc, char const *version);
46
6e649e65 47/* Request detailed syntax error messages, and pass them to GRAM_ERROR.
ad8a3efc 48 FIXME: depends on the undocumented availability of YYLLOC. */
e9955c83
AD
49#undef yyerror
50#define yyerror(Msg) \
f0064700 51 gram_error (&yylloc, Msg)
3d2cbc26 52static void gram_error (location const *, char const *);
e9955c83 53
33ad1a9c
PE
54static char const *char_name (char);
55
e9ce5688 56static void add_param (char const *, char *, location);
1773ceee 57
04098407
PE
58static symbol_class current_class = unknown_sym;
59static uniqstr current_type = 0;
877519f8
PE
60static symbol *current_lhs;
61static location current_lhs_location;
04098407 62static int current_prec = 0;
d42cf844
PE
63
64#ifdef UINT_FAST8_MAX
65# define YYTYPE_UINT8 uint_fast8_t
66#endif
67#ifdef INT_FAST8_MAX
68# define YYTYPE_INT8 int_fast8_t
69#endif
70#ifdef UINT_FAST16_MAX
71# define YYTYPE_UINT16 uint_fast16_t
72#endif
73#ifdef INT_FAST16_MAX
74# define YYTYPE_INT16 int_fast16_t
75#endif
e9955c83
AD
76%}
77
12ffdd28 78%debug
82b248ad 79%verbose
12ffdd28
PE
80%defines
81%locations
82%pure-parser
83%error-verbose
84%defines
85%name-prefix="gram_"
86
cd3684cf
AD
87%initial-action
88{
89 /* Bison's grammar can initial empty locations, hence a default
90 location is needed. */
e9071366
AD
91 boundary_set (&@$.start, current_file, 1, 0);
92 boundary_set (&@$.end, current_file, 1, 0);
cd3684cf 93}
e9955c83
AD
94
95/* Only NUMBERS have a value. */
96%union
97{
3d2cbc26
PE
98 symbol *symbol;
99 symbol_list *list;
e9955c83 100 int integer;
3d2cbc26
PE
101 char *chars;
102 assoc assoc;
103 uniqstr uniqstr;
58d7a1a1 104 unsigned char character;
e9955c83
AD
105};
106
f9a85a15 107/* Define the tokens together with their human representation. */
3d38c03a
AD
108%token GRAM_EOF 0 "end of file"
109%token STRING "string"
3d38c03a 110%token INT "integer"
e9955c83 111
9280d3ef
AD
112%token PERCENT_TOKEN "%token"
113%token PERCENT_NTERM "%nterm"
366eea36 114
9280d3ef 115%token PERCENT_TYPE "%type"
e9071366
AD
116%token PERCENT_DESTRUCTOR "%destructor"
117%token PERCENT_PRINTER "%printer"
366eea36 118
9280d3ef
AD
119%token PERCENT_LEFT "%left"
120%token PERCENT_RIGHT "%right"
121%token PERCENT_NONASSOC "%nonassoc"
04e60654 122
3d38c03a
AD
123%token PERCENT_PREC "%prec"
124%token PERCENT_DPREC "%dprec"
125%token PERCENT_MERGE "%merge"
e9955c83 126
e9955c83 127
ae7453f2
AD
128/*----------------------.
129| Global Declarations. |
130`----------------------*/
131
132%token
9bc0dd67
JD
133 PERCENT_AFTER_DEFINITIONS
134 "%after-definitions"
135 PERCENT_BEFORE_DEFINITIONS
136 "%before-definitions"
cd3684cf 137 PERCENT_DEBUG "%debug"
39a06c25 138 PERCENT_DEFAULT_PREC "%default-prec"
cd3684cf
AD
139 PERCENT_DEFINE "%define"
140 PERCENT_DEFINES "%defines"
141 PERCENT_ERROR_VERBOSE "%error-verbose"
142 PERCENT_EXPECT "%expect"
d6328241 143 PERCENT_EXPECT_RR "%expect-rr"
cd3684cf
AD
144 PERCENT_FILE_PREFIX "%file-prefix"
145 PERCENT_GLR_PARSER "%glr-parser"
e9071366
AD
146 PERCENT_INITIAL_ACTION "%initial-action"
147 PERCENT_LEX_PARAM "%lex-param"
cd3684cf
AD
148 PERCENT_LOCATIONS "%locations"
149 PERCENT_NAME_PREFIX "%name-prefix"
22fccf95 150 PERCENT_NO_DEFAULT_PREC "%no-default-prec"
cd3684cf
AD
151 PERCENT_NO_LINES "%no-lines"
152 PERCENT_NONDETERMINISTIC_PARSER
f0064700 153 "%nondeterministic-parser"
cd3684cf 154 PERCENT_OUTPUT "%output"
e9071366 155 PERCENT_PARSE_PARAM "%parse-param"
cd3684cf 156 PERCENT_PURE_PARSER "%pure-parser"
f0064700 157 PERCENT_REQUIRE "%require"
cd3684cf
AD
158 PERCENT_SKELETON "%skeleton"
159 PERCENT_START "%start"
160 PERCENT_TOKEN_TABLE "%token-table"
161 PERCENT_VERBOSE "%verbose"
162 PERCENT_YACC "%yacc"
ae7453f2 163;
e9955c83 164
58d7a1a1
AD
165%token BRACED_CODE "{...}"
166%token CHAR "char"
167%token EPILOGUE "epilogue"
3d38c03a 168%token EQUAL "="
3d38c03a 169%token ID "identifier"
b7295522 170%token ID_COLON "identifier:"
e9955c83 171%token PERCENT_PERCENT "%%"
58d7a1a1 172%token PIPE "|"
3d38c03a 173%token PROLOGUE "%{...%}"
58d7a1a1
AD
174%token SEMICOLON ";"
175%token TYPE "type"
176
177%type <character> CHAR
33ad1a9c 178%printer { fputs (char_name ($$), stderr); } CHAR
3d38c03a 179
58d7a1a1 180%type <chars> STRING string_content "{...}" PROLOGUE EPILOGUE
33ad1a9c
PE
181%printer { fputs (quotearg_style (c_quoting_style, $$), stderr); }
182 STRING string_content
58d7a1a1
AD
183%printer { fprintf (stderr, "{\n%s\n}", $$); } "{...}" PROLOGUE EPILOGUE
184
185%type <uniqstr> TYPE ID ID_COLON
82b248ad 186%printer { fprintf (stderr, "<%s>", $$); } TYPE
33ad1a9c 187%printer { fputs ($$, stderr); } ID
58d7a1a1
AD
188%printer { fprintf (stderr, "%s:", $$); } ID_COLON
189
e9955c83 190%type <integer> INT
82b248ad 191%printer { fprintf (stderr, "%d", $$); } INT
58d7a1a1
AD
192
193%type <symbol> id id_colon symbol string_as_id
194%printer { fprintf (stderr, "%s", $$->tag); } id symbol string_as_id
195%printer { fprintf (stderr, "%s:", $$->tag); } id_colon
196
2c569025 197%type <assoc> precedence_declarator
1e0bab92 198%type <list> symbols.1
e9955c83 199%%
2c569025 200
8efe435c 201input:
2c569025 202 declarations "%%" grammar epilogue.opt
e9955c83
AD
203;
204
2c569025
AD
205
206 /*------------------------------------.
207 | Declarations: before the first %%. |
208 `------------------------------------*/
209
210declarations:
e9955c83 211 /* Nothing */
b7295522 212| declarations declaration
e9955c83
AD
213;
214
2c569025
AD
215declaration:
216 grammar_declaration
e9071366
AD
217| PROLOGUE { prologue_augment (translate_code ($1, @1),
218 @1); }
9bc0dd67
JD
219| "%after-definitions" "{...}"
220 {
221 after_definitions = true;
222 /* Remove the '{', and replace the '}' with '\n'. */
223 $2[strlen ($2) - 1] = '\n';
224 muscle_code_grow ("after_definitions", $2+1, @2);
225 }
226| "%before-definitions" "{...}"
227 {
228 before_definitions = true;
229 /* Remove the '{', and replace the '}' with '\n'. */
230 $2[strlen ($2) - 1] = '\n';
231 muscle_code_grow ("before_definitions", $2+1, @2);
232 }
d0829076 233| "%debug" { debug_flag = true; }
c66dfadd
PE
234| "%define" string_content
235 {
236 static char one[] = "1";
237 muscle_insert ($2, one);
238 }
e9955c83 239| "%define" string_content string_content { muscle_insert ($2, $3); }
d0829076
PE
240| "%defines" { defines_flag = true; }
241| "%error-verbose" { error_verbose = true; }
d6328241 242| "%expect" INT { expected_sr_conflicts = $2; }
04098407 243| "%expect-rr" INT { expected_rr_conflicts = $2; }
e9955c83 244| "%file-prefix" "=" string_content { spec_file_prefix = $3; }
cd3684cf 245| "%glr-parser"
c66dfadd
PE
246 {
247 nondeterministic_parser = true;
248 glr_parser = true;
249 }
e9071366 250| "%initial-action" "{...}"
c66dfadd 251 {
e9071366 252 muscle_code_grow ("initial_action", translate_symbol_action ($2, @2), @2);
c66dfadd 253 }
e9071366 254| "%lex-param" "{...}" { add_param ("lex_param", $2, @2); }
d0829076 255| "%locations" { locations_flag = true; }
e9955c83 256| "%name-prefix" "=" string_content { spec_name_prefix = $3; }
d0829076 257| "%no-lines" { no_lines_flag = true; }
04098407 258| "%nondeterministic-parser" { nondeterministic_parser = true; }
e9955c83 259| "%output" "=" string_content { spec_outfile = $3; }
e9071366 260| "%parse-param" "{...}" { add_param ("parse_param", $2, @2); }
916708d5 261| "%pure-parser" { pure_parser = true; }
b50d2359 262| "%require" string_content { version_check (&@2, $2); }
e9955c83 263| "%skeleton" string_content { skeleton = $2; }
d0829076 264| "%token-table" { token_table_flag = true; }
9dd5b378 265| "%verbose" { report_flag = report_states; }
d0829076 266| "%yacc" { yacc_flag = true; }
cd3684cf 267| /*FIXME: Err? What is this horror doing here? */ ";"
e9955c83
AD
268;
269
2c569025
AD
270grammar_declaration:
271 precedence_declaration
272| symbol_declaration
e9955c83
AD
273| "%start" symbol
274 {
8efe435c 275 grammar_start_symbol_set ($2, @2);
e9955c83 276 }
e9071366 277| "%destructor" "{...}" symbols.1
9280d3ef 278 {
3d2cbc26 279 symbol_list *list;
e9071366
AD
280 const char *action = translate_symbol_action ($2, @2);
281 for (list = $3; list; list = list->next)
282 symbol_destructor_set (list->sym, action, @2);
283 symbol_list_free ($3);
9280d3ef 284 }
e9071366 285| "%printer" "{...}" symbols.1
366eea36 286 {
3d2cbc26 287 symbol_list *list;
e9071366
AD
288 const char *action = translate_symbol_action ($2, @2);
289 for (list = $3; list; list = list->next)
290 symbol_printer_set (list->sym, action, @2);
291 symbol_list_free ($3);
366eea36 292 }
22fccf95 293| "%default-prec"
39a06c25 294 {
22fccf95
PE
295 default_prec = true;
296 }
297| "%no-default-prec"
298 {
299 default_prec = false;
39a06c25 300 }
2c569025
AD
301;
302
58d7a1a1
AD
303
304/*----------*
305 | %union. |
306 *----------*/
307
308%token PERCENT_UNION "%union";
309
310union_name:
311 /* Nothing. */ {}
312| ID { muscle_code_grow ("union_name", $1, @1); }
313;
314
315grammar_declaration:
316 "%union" union_name "{...}"
317 {
318 char const *body = $3;
319
320 if (typed)
321 {
322 /* Concatenate the union bodies, turning the first one's
323 trailing '}' into '\n', and omitting the second one's '{'. */
324 char *code = muscle_find ("stype");
325 code[strlen (code) - 1] = '\n';
326 body++;
327 }
328
329 typed = true;
330 muscle_code_grow ("stype", body, @3);
331 }
332;
333
334
335
336
2c569025
AD
337symbol_declaration:
338 "%nterm" { current_class = nterm_sym; } symbol_defs.1
e9955c83
AD
339 {
340 current_class = unknown_sym;
341 current_type = NULL;
342 }
2c569025 343| "%token" { current_class = token_sym; } symbol_defs.1
e9955c83 344 {
2c569025 345 current_class = unknown_sym;
e9955c83
AD
346 current_type = NULL;
347 }
1e0bab92 348| "%type" TYPE symbols.1
e9955c83 349 {
3d2cbc26 350 symbol_list *list;
1e0bab92 351 for (list = $3; list; list = list->next)
1a31ed21 352 symbol_type_set (list->sym, $2, @2);
dafdc66f 353 symbol_list_free ($3);
e9955c83
AD
354 }
355;
356
2c569025 357precedence_declaration:
1e0bab92
AD
358 precedence_declarator type.opt symbols.1
359 {
3d2cbc26 360 symbol_list *list;
1e0bab92
AD
361 ++current_prec;
362 for (list = $3; list; list = list->next)
363 {
1a31ed21
AD
364 symbol_type_set (list->sym, current_type, @2);
365 symbol_precedence_set (list->sym, current_prec, $1, @1);
1e0bab92 366 }
dafdc66f 367 symbol_list_free ($3);
1e0bab92
AD
368 current_type = NULL;
369 }
e9955c83
AD
370;
371
2c569025 372precedence_declarator:
e9955c83
AD
373 "%left" { $$ = left_assoc; }
374| "%right" { $$ = right_assoc; }
375| "%nonassoc" { $$ = non_assoc; }
376;
377
378type.opt:
87fbb0bf 379 /* Nothing. */ { current_type = NULL; }
e9955c83
AD
380| TYPE { current_type = $1; }
381;
382
383/* One or more nonterminals to be %typed. */
1e0bab92
AD
384symbols.1:
385 symbol { $$ = symbol_list_new ($1, @1); }
386| symbols.1 symbol { $$ = symbol_list_prepend ($1, $2, @2); }
e9955c83
AD
387;
388
e9955c83
AD
389/* One token definition. */
390symbol_def:
391 TYPE
392 {
393 current_type = $1;
394 }
58d7a1a1 395| id
e9955c83 396 {
073f9288 397 symbol_class_set ($1, current_class, @1, true);
1a31ed21 398 symbol_type_set ($1, current_type, @1);
e9955c83 399 }
58d7a1a1 400| id INT
e9955c83 401 {
073f9288 402 symbol_class_set ($1, current_class, @1, true);
1a31ed21 403 symbol_type_set ($1, current_type, @1);
e776192e 404 symbol_user_token_number_set ($1, $2, @2);
e9955c83 405 }
58d7a1a1 406| id string_as_id
e9955c83 407 {
073f9288 408 symbol_class_set ($1, current_class, @1, true);
1a31ed21 409 symbol_type_set ($1, current_type, @1);
a5d50994 410 symbol_make_alias ($1, $2, @$);
e9955c83 411 }
58d7a1a1 412| id INT string_as_id
e9955c83 413 {
073f9288 414 symbol_class_set ($1, current_class, @1, true);
1a31ed21 415 symbol_type_set ($1, current_type, @1);
e776192e 416 symbol_user_token_number_set ($1, $2, @2);
a5d50994 417 symbol_make_alias ($1, $3, @$);
e9955c83
AD
418 }
419;
420
421/* One or more symbol definitions. */
422symbol_defs.1:
423 symbol_def
e9955c83 424| symbol_defs.1 symbol_def
e9955c83
AD
425;
426
2c569025
AD
427
428 /*------------------------------------------.
429 | The grammar section: between the two %%. |
430 `------------------------------------------*/
431
432grammar:
1921f1d7
AD
433 rules_or_grammar_declaration
434| grammar rules_or_grammar_declaration
435;
436
437/* As a Bison extension, one can use the grammar declarations in the
b7295522 438 body of the grammar. */
1921f1d7 439rules_or_grammar_declaration:
e9955c83 440 rules
8d0a98bb 441| grammar_declaration ";"
b275314e
AD
442| error ";"
443 {
444 yyerrok;
445 }
e9955c83
AD
446;
447
448rules:
58d7a1a1 449 id_colon { current_lhs = $1; current_lhs_location = @1; } rhses.1
e9955c83
AD
450;
451
452rhses.1:
8f3596a6
AD
453 rhs { grammar_current_rule_end (@1); }
454| rhses.1 "|" rhs { grammar_current_rule_end (@3); }
8d0a98bb 455| rhses.1 ";"
e9955c83
AD
456;
457
458rhs:
459 /* Nothing. */
8f3596a6 460 { grammar_current_rule_begin (current_lhs, current_lhs_location); }
e9955c83 461| rhs symbol
8efe435c 462 { grammar_current_rule_symbol_append ($2, @2); }
e9071366
AD
463| rhs "{...}"
464 { grammar_current_rule_action_append (gram_last_string,
465 gram_last_braced_code_loc); }
e9955c83 466| rhs "%prec" symbol
e776192e 467 { grammar_current_rule_prec_set ($3, @3); }
676385e2
PH
468| rhs "%dprec" INT
469 { grammar_current_rule_dprec_set ($3, @3); }
470| rhs "%merge" TYPE
471 { grammar_current_rule_merge_set ($3, @3); }
e9955c83
AD
472;
473
58d7a1a1
AD
474
475/*---------------*
476 | Identifiers. |
477 *---------------*/
478
33ad1a9c
PE
479/* Identifiers are returned as uniqstr values by the scanner.
480 Depending on their use, we may need to make them genuine symbols. */
58d7a1a1
AD
481
482id:
33ad1a9c 483 ID
203b9274 484 { $$ = symbol_from_uniqstr ($1, @1); }
33ad1a9c
PE
485| CHAR
486 {
487 $$ = symbol_get (char_name ($1), @1);
488 symbol_class_set ($$, token_sym, @1, false);
489 symbol_user_token_number_set ($$, $1, @1);
490 }
58d7a1a1
AD
491;
492
493id_colon:
203b9274 494 ID_COLON { $$ = symbol_from_uniqstr ($1, @1); }
58d7a1a1
AD
495;
496
497
e9955c83 498symbol:
58d7a1a1
AD
499 id
500| string_as_id
e9955c83
AD
501;
502
ca407bdf 503/* A string used as an ID: quote it. */
e9955c83
AD
504string_as_id:
505 STRING
506 {
ca407bdf 507 $$ = symbol_get (quotearg_style (c_quoting_style, $1), @1);
073f9288 508 symbol_class_set ($$, token_sym, @1, false);
e9955c83
AD
509 }
510;
511
ca407bdf 512/* A string used for its contents. Don't quote it. */
e9955c83
AD
513string_content:
514 STRING
ca407bdf
PE
515 { $$ = $1; }
516;
e9955c83
AD
517
518
519epilogue.opt:
520 /* Nothing. */
e9955c83
AD
521| "%%" EPILOGUE
522 {
e9071366
AD
523 muscle_code_grow ("epilogue", translate_code ($2, @2), @2);
524 gram_scanner_last_string_free ();
e9955c83
AD
525 }
526;
527
e9955c83 528%%
b7295522
PE
529
530
531/* Return the location of the left-hand side of a rule whose
532 right-hand side is RHS[1] ... RHS[N]. Ignore empty nonterminals in
533 the right-hand side, and return an empty location equal to the end
534 boundary of RHS[0] if the right-hand side is empty. */
535
536static YYLTYPE
537lloc_default (YYLTYPE const *rhs, int n)
538{
539 int i;
a737b216 540 YYLTYPE loc;
62cb8a99
PE
541
542 /* SGI MIPSpro 7.4.1m miscompiles "loc.start = loc.end = rhs[n].end;".
543 The bug is fixed in 7.4.2m, but play it safe for now. */
544 loc.start = rhs[n].end;
545 loc.end = rhs[n].end;
b7295522 546
5320ca4d
PE
547 /* Ignore empty nonterminals the start of the the right-hand side.
548 Do not bother to ignore them at the end of the right-hand side,
549 since empty nonterminals have the same end as their predecessors. */
b7295522
PE
550 for (i = 1; i <= n; i++)
551 if (! equal_boundaries (rhs[i].start, rhs[i].end))
552 {
a737b216 553 loc.start = rhs[i].start;
b7295522
PE
554 break;
555 }
556
a737b216 557 return loc;
b7295522
PE
558}
559
560
561/* Add a lex-param or a parse-param (depending on TYPE) with
562 declaration DECL and location LOC. */
563
1773ceee 564static void
e9ce5688 565add_param (char const *type, char *decl, location loc)
1773ceee 566{
ead9e56e 567 static char const alphanum[26 + 26 + 1 + 10] =
1773ceee
PE
568 "abcdefghijklmnopqrstuvwxyz"
569 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
ead9e56e
PE
570 "_"
571 "0123456789";
1773ceee 572 char const *name_start = NULL;
e9ce5688 573 char *p;
1773ceee 574
e503aa60
AD
575 /* Stop on last actual character. */
576 for (p = decl; p[1]; p++)
ead9e56e
PE
577 if ((p == decl
578 || ! memchr (alphanum, p[-1], sizeof alphanum))
579 && memchr (alphanum, p[0], sizeof alphanum - 10))
1773ceee
PE
580 name_start = p;
581
ead9e56e
PE
582 /* Strip the surrounding '{' and '}', and any blanks just inside
583 the braces. */
584 while (*--p == ' ' || *p == '\t')
585 continue;
e503aa60 586 p[1] = '\0';
ead9e56e
PE
587 while (*++decl == ' ' || *decl == '\t')
588 continue;
e9ce5688 589
1773ceee
PE
590 if (! name_start)
591 complain_at (loc, _("missing identifier in parameter declaration"));
592 else
593 {
594 char *name;
595 size_t name_len;
596
597 for (name_len = 1;
ead9e56e 598 memchr (alphanum, name_start[name_len], sizeof alphanum);
1773ceee
PE
599 name_len++)
600 continue;
601
602 name = xmalloc (name_len + 1);
603 memcpy (name, name_start, name_len);
604 name[name_len] = '\0';
605 muscle_pair_list_grow (type, decl, name);
606 free (name);
607 }
608
e9071366 609 gram_scanner_last_string_free ();
1773ceee
PE
610}
611
b50d2359
AD
612static void
613version_check (location const *loc, char const *version)
614{
615 if (strverscmp (version, PACKAGE_VERSION) > 0)
9b8a5ce0
AD
616 {
617 complain_at (*loc, "require bison %s, but have %s",
618 version, PACKAGE_VERSION);
619 exit (63);
620 }
b50d2359
AD
621}
622
1fec91df 623static void
3d2cbc26 624gram_error (location const *loc, char const *msg)
e9955c83 625{
ad8a3efc 626 complain_at (*loc, "%s", msg);
e9955c83 627}
e9ce5688
PE
628
629char const *
630token_name (int type)
631{
fc01665e 632 return yytname[YYTRANSLATE (type)];
e9ce5688 633}
33ad1a9c
PE
634
635static char const *
636char_name (char c)
637{
638 if (c == '\'')
639 return "'\\''";
640 else
641 {
642 char buf[4];
643 buf[0] = '\''; buf[1] = c; buf[2] = '\''; buf[3] = '\0';
644 return quotearg_style (escape_quoting_style, buf);
645 }
646}