mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 08:43:03 +00:00
* src/symtab.h, src/symtab.c (symbol_t): printer and
printer_location are new members. (symbol_printer_set): New. * src/parse-gram.y (PERCENT_PRINTER): New token. Handle its associated rule. * src/scan-gram.l: Adjust. (handle_destructor_at, handle_destructor_dollar): Rename as... (handle_symbol_code_at, handle_symbol_code_dollar): these. * src/output.c (symbol_printers_output): New. (output_skeleton): Call it. * data/bison.simple (yysymprint): New. Cannot be named yyprint since there are already many grammar files with a user `yyprint'. Replace the calls to YYPRINT to calls to yysymprint. * tests/calc.at: Adjust. * tests/torture.at (AT_DATA_STACK_TORTURE): Remove YYPRINT: it was taking advantage of parser very internal details (stack size!).
This commit is contained in:
20
ChangeLog
20
ChangeLog
@@ -1,10 +1,28 @@
|
|||||||
|
2002-06-20 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* src/symtab.h, src/symtab.c (symbol_t): printer and
|
||||||
|
printer_location are new members.
|
||||||
|
(symbol_printer_set): New.
|
||||||
|
* src/parse-gram.y (PERCENT_PRINTER): New token.
|
||||||
|
Handle its associated rule.
|
||||||
|
* src/scan-gram.l: Adjust.
|
||||||
|
(handle_destructor_at, handle_destructor_dollar): Rename as...
|
||||||
|
(handle_symbol_code_at, handle_symbol_code_dollar): these.
|
||||||
|
* src/output.c (symbol_printers_output): New.
|
||||||
|
(output_skeleton): Call it.
|
||||||
|
* data/bison.simple (yysymprint): New. Cannot be named yyprint
|
||||||
|
since there are already many grammar files with a user `yyprint'.
|
||||||
|
Replace the calls to YYPRINT to calls to yysymprint.
|
||||||
|
* tests/calc.at: Adjust.
|
||||||
|
* tests/torture.at (AT_DATA_STACK_TORTURE): Remove YYPRINT: it was
|
||||||
|
taking advantage of parser very internal details (stack size!).
|
||||||
|
|
||||||
2002-06-20 Akim Demaille <akim@epita.fr>
|
2002-06-20 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/scan-gram.l: Complete the scanner with the missing patterns
|
* src/scan-gram.l: Complete the scanner with the missing patterns
|
||||||
to pacify Flex.
|
to pacify Flex.
|
||||||
Use `quote' and `symbol_tag_get' where appropriate.
|
Use `quote' and `symbol_tag_get' where appropriate.
|
||||||
|
|
||||||
|
|
||||||
2002-06-19 Akim Demaille <akim@epita.fr>
|
2002-06-19 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* tests/actions.at (Destructors): Augment to test locations.
|
* tests/actions.at (Destructors): Augment to test locations.
|
||||||
|
|||||||
@@ -671,6 +671,10 @@ int yyparse (void);
|
|||||||
#if defined (__STDC__) || defined (__cplusplus)
|
#if defined (__STDC__) || defined (__cplusplus)
|
||||||
static void yydestructor (int yytype,
|
static void yydestructor (int yytype,
|
||||||
YYSTYPE yyvalue[]b4_location_if([, YYLTYPE yylocation]));
|
YYSTYPE yyvalue[]b4_location_if([, YYLTYPE yylocation]));
|
||||||
|
# if YYDEBUG
|
||||||
|
static void yysymprint (FILE* out, int yytype,
|
||||||
|
YYSTYPE yyvalue[]b4_location_if([, YYLTYPE yylocation]));
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m4_divert_push([KILL])# ======================== M4 code.
|
m4_divert_push([KILL])# ======================== M4 code.
|
||||||
@@ -887,14 +891,9 @@ yybackup:
|
|||||||
which are defined only if `YYDEBUG' is set. */
|
which are defined only if `YYDEBUG' is set. */
|
||||||
if (yydebug)
|
if (yydebug)
|
||||||
{
|
{
|
||||||
YYFPRINTF (stderr, "Next token is %d (%s",
|
YYFPRINTF (stderr, "Next token is ");
|
||||||
yychar, yytname[yychar1]);
|
yysymprint (stderr, yychar1, yylval]b4_location_if([, yyloc])[);
|
||||||
/* Give the individual parser a way to print the precise
|
YYFPRINTF (stderr, "\n");
|
||||||
meaning of a token, for further debugging info. */
|
|
||||||
# ifdef YYPRINT
|
|
||||||
YYPRINT (stderr, yychar, yylval);
|
|
||||||
# endif
|
|
||||||
YYFPRINTF (stderr, ")\n");
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -1113,21 +1112,11 @@ yyerrlab1:
|
|||||||
#if YYDEBUG
|
#if YYDEBUG
|
||||||
if (yydebug)
|
if (yydebug)
|
||||||
{
|
{
|
||||||
if (yystos[*yyssp] < YYNTOKENS)
|
YYFPRINTF (stderr, "Error: popping ");
|
||||||
{
|
yysymprint (stderr,
|
||||||
YYFPRINTF (stderr, "Error: popping token %d (%s",
|
yystos[*yyssp],
|
||||||
yytoknum[yystos[*yyssp]],
|
*yyvsp]b4_location_if([, *yylsp])[);
|
||||||
yytname[yystos[*yyssp]]);
|
YYFPRINTF (stderr, "\n");
|
||||||
# ifdef YYPRINT
|
|
||||||
YYPRINT (stderr, yytoknum[yystos[*yyssp]], *yyvsp);
|
|
||||||
# endif
|
|
||||||
YYFPRINTF (stderr, ")\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
YYFPRINTF (stderr, "Error: popping nonterminal (%s)\n",
|
|
||||||
yytname[yystos[*yyssp]]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
yydestructor (yystos[*yyssp], *yyvsp]b4_location_if([, *yylsp])[);
|
yydestructor (yystos[*yyssp], *yyvsp]b4_location_if([, *yylsp])[);
|
||||||
@@ -1168,20 +1157,11 @@ yyerrlab1:
|
|||||||
#if YYDEBUG
|
#if YYDEBUG
|
||||||
if (yydebug)
|
if (yydebug)
|
||||||
{
|
{
|
||||||
if (yystos[yystate] < YYNTOKENS)
|
YYFPRINTF (stderr, "Error: popping ");
|
||||||
{
|
yysymprint (stderr,
|
||||||
YYFPRINTF (stderr, "Error: popping token %d (%s",
|
yystos[*yyssp],
|
||||||
yytoknum[yystos[yystate]], yytname[yystos[yystate]]);
|
*yyvsp]b4_location_if([, *yylsp])[);
|
||||||
# ifdef YYPRINT
|
YYFPRINTF (stderr, "\n");
|
||||||
YYPRINT (stderr, yytoknum[yystos[yystate]], *yyvsp);
|
|
||||||
# endif
|
|
||||||
YYFPRINTF (stderr, ")\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
YYFPRINTF (stderr, "Error: popping nonterminal (%s)\n",
|
|
||||||
yytname[yystos[yystate]]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1247,9 +1227,9 @@ yyreturn:
|
|||||||
]}
|
]}
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------.
|
/*-----------------------------------------------.
|
||||||
| Release the memory associated to SYMBOL-NUMBER. |
|
| Release the memory associated to this symbol. |
|
||||||
`-------------------------------------------------*/
|
`-----------------------------------------------*/
|
||||||
|
|
||||||
m4_divert_push([KILL])# M4 code.
|
m4_divert_push([KILL])# M4 code.
|
||||||
# b4_symbol_destructor(SYMBOL-NUMBER, DESTRUCTOR, TYPE-NAME)
|
# b4_symbol_destructor(SYMBOL-NUMBER, DESTRUCTOR, TYPE-NAME)
|
||||||
@@ -1274,12 +1254,53 @@ yydestructor (int yytype,
|
|||||||
{
|
{
|
||||||
m4_map([b4_symbol_destructor], m4_defn([b4_symbol_destructors]))dnl
|
m4_map([b4_symbol_destructor], m4_defn([b4_symbol_destructors]))dnl
|
||||||
default:
|
default:
|
||||||
YYDPRINTF ((stderr, "yydestructor: unknown symbol type: %d (%s)\n",
|
|
||||||
yytype, yytname[[yytype]]));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if YYDEBUG
|
||||||
|
/*---------------------------.
|
||||||
|
| Print this symbol on OUT. |
|
||||||
|
`---------------------------*/
|
||||||
|
|
||||||
|
m4_divert_push([KILL])# M4 code.
|
||||||
|
# b4_symbol_printer(SYMBOL-NUMBER, PRINTER, TYPE-NAME)
|
||||||
|
# ----------------------------------------------------------
|
||||||
|
m4_define([b4_symbol_printer],
|
||||||
|
[m4_pushdef([b4_dollar_dollar], [yyvalue.$6])dnl
|
||||||
|
m4_pushdef([b4_at_dollar], [yylocation])dnl
|
||||||
|
case $4: /* $3 */
|
||||||
|
#line $2 "$1"
|
||||||
|
$5;
|
||||||
|
#line __oline__ "__ofile__"
|
||||||
|
break;
|
||||||
|
m4_popdef([b4_at_dollar])dnl
|
||||||
|
m4_popdef([b4_dollar_dollar])])
|
||||||
|
|
||||||
|
m4_divert_pop([KILL])dnl# End of M4 code.
|
||||||
|
static void
|
||||||
|
yysymprint (FILE* out, int yytype,
|
||||||
|
YYSTYPE yyvalue[]b4_location_if([, YYLTYPE yylocation]))
|
||||||
|
{
|
||||||
|
if (yytype < YYNTOKENS)
|
||||||
|
YYFPRINTF (out, "token %d (%s ", yytoknum[[yytype]], yytname[[yytype]]);
|
||||||
|
else
|
||||||
|
YYFPRINTF (out, "nterm %s (", yytname[[yytype]]);
|
||||||
|
# ifdef YYPRINT
|
||||||
|
YYPRINT (out, yytype, yyvalue);
|
||||||
|
# else
|
||||||
|
switch (yytype)
|
||||||
|
{
|
||||||
|
m4_map([b4_symbol_printer], m4_defn([b4_symbol_printers]))dnl
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
# endif /* !defined YYPRINT. */
|
||||||
|
YYFPRINTF (out, ")");
|
||||||
|
}
|
||||||
|
#endif /* YYDEBUG. */
|
||||||
|
|
||||||
b4_epilogue
|
b4_epilogue
|
||||||
m4_if(b4_defines_flag, 0, [],
|
m4_if(b4_defines_flag, 0, [],
|
||||||
[#output "b4_output_header_name"
|
[#output "b4_output_header_name"
|
||||||
|
|||||||
34
src/output.c
34
src/output.c
@@ -639,6 +639,39 @@ symbol_destructors_output (FILE *out)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------.
|
||||||
|
| Output the symbol printers to OOUT. |
|
||||||
|
`-------------------------------------*/
|
||||||
|
|
||||||
|
static void
|
||||||
|
symbol_printers_output (FILE *out)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int first = 1;
|
||||||
|
|
||||||
|
fputs ("m4_define([b4_symbol_printers], \n[", out);
|
||||||
|
for (i = 0; i < nsyms; ++i)
|
||||||
|
if (symbols[i]->destructor)
|
||||||
|
{
|
||||||
|
symbol_t *symbol = symbols[i];
|
||||||
|
|
||||||
|
/* Filename, lineno,
|
||||||
|
Symbol-name, Symbol-number,
|
||||||
|
destructor, typename. */
|
||||||
|
fprintf (out, "%s[[[%s]], [[%d]], [[%s]], [[%d]], [[%s]], [[%s]]]",
|
||||||
|
first ? "" : ",\n",
|
||||||
|
infile, symbol->printer_location.first_line,
|
||||||
|
symbol_tag_get (symbol),
|
||||||
|
symbol->number,
|
||||||
|
symbol->printer,
|
||||||
|
symbol->type_name);
|
||||||
|
|
||||||
|
first = 0;
|
||||||
|
}
|
||||||
|
fputs ("])\n\n", out);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
save_column (int symbol, int default_state)
|
save_column (int symbol, int default_state)
|
||||||
{
|
{
|
||||||
@@ -1053,6 +1086,7 @@ output_skeleton (void)
|
|||||||
actions_output (out);
|
actions_output (out);
|
||||||
token_definitions_output (out);
|
token_definitions_output (out);
|
||||||
symbol_destructors_output (out);
|
symbol_destructors_output (out);
|
||||||
|
symbol_printers_output (out);
|
||||||
|
|
||||||
muscles_m4_output (out);
|
muscles_m4_output (out);
|
||||||
|
|
||||||
|
|||||||
797
src/parse-gram.c
797
src/parse-gram.c
File diff suppressed because it is too large
Load Diff
130
src/parse-gram.h
130
src/parse-gram.h
@@ -15,37 +15,38 @@
|
|||||||
PERCENT_NTERM = 262,
|
PERCENT_NTERM = 262,
|
||||||
PERCENT_TYPE = 263,
|
PERCENT_TYPE = 263,
|
||||||
PERCENT_DESTRUCTOR = 264,
|
PERCENT_DESTRUCTOR = 264,
|
||||||
PERCENT_UNION = 265,
|
PERCENT_PRINTER = 265,
|
||||||
PERCENT_LEFT = 266,
|
PERCENT_UNION = 266,
|
||||||
PERCENT_RIGHT = 267,
|
PERCENT_LEFT = 267,
|
||||||
PERCENT_NONASSOC = 268,
|
PERCENT_RIGHT = 268,
|
||||||
PERCENT_EXPECT = 269,
|
PERCENT_NONASSOC = 269,
|
||||||
PERCENT_START = 270,
|
PERCENT_EXPECT = 270,
|
||||||
PERCENT_PREC = 271,
|
PERCENT_START = 271,
|
||||||
PERCENT_VERBOSE = 272,
|
PERCENT_PREC = 272,
|
||||||
PERCENT_ERROR_VERBOSE = 273,
|
PERCENT_VERBOSE = 273,
|
||||||
PERCENT_OUTPUT = 274,
|
PERCENT_ERROR_VERBOSE = 274,
|
||||||
PERCENT_FILE_PREFIX = 275,
|
PERCENT_OUTPUT = 275,
|
||||||
PERCENT_NAME_PREFIX = 276,
|
PERCENT_FILE_PREFIX = 276,
|
||||||
PERCENT_DEFINE = 277,
|
PERCENT_NAME_PREFIX = 277,
|
||||||
PERCENT_PURE_PARSER = 278,
|
PERCENT_DEFINE = 278,
|
||||||
PERCENT_DEFINES = 279,
|
PERCENT_PURE_PARSER = 279,
|
||||||
PERCENT_YACC = 280,
|
PERCENT_DEFINES = 280,
|
||||||
PERCENT_DEBUG = 281,
|
PERCENT_YACC = 281,
|
||||||
PERCENT_LOCATIONS = 282,
|
PERCENT_DEBUG = 282,
|
||||||
PERCENT_NO_LINES = 283,
|
PERCENT_LOCATIONS = 283,
|
||||||
PERCENT_SKELETON = 284,
|
PERCENT_NO_LINES = 284,
|
||||||
PERCENT_TOKEN_TABLE = 285,
|
PERCENT_SKELETON = 285,
|
||||||
TYPE = 286,
|
PERCENT_TOKEN_TABLE = 286,
|
||||||
EQUAL = 287,
|
TYPE = 287,
|
||||||
SEMICOLON = 288,
|
EQUAL = 288,
|
||||||
COLON = 289,
|
SEMICOLON = 289,
|
||||||
PIPE = 290,
|
COLON = 290,
|
||||||
ID = 291,
|
PIPE = 291,
|
||||||
PERCENT_PERCENT = 292,
|
ID = 292,
|
||||||
PROLOGUE = 293,
|
PERCENT_PERCENT = 293,
|
||||||
EPILOGUE = 294,
|
PROLOGUE = 294,
|
||||||
BRACED_CODE = 295
|
EPILOGUE = 295,
|
||||||
|
BRACED_CODE = 296
|
||||||
};
|
};
|
||||||
# endif
|
# endif
|
||||||
/* POSIX requires `int' for tokens in interfaces. */
|
/* POSIX requires `int' for tokens in interfaces. */
|
||||||
@@ -59,37 +60,38 @@
|
|||||||
#define PERCENT_NTERM 262
|
#define PERCENT_NTERM 262
|
||||||
#define PERCENT_TYPE 263
|
#define PERCENT_TYPE 263
|
||||||
#define PERCENT_DESTRUCTOR 264
|
#define PERCENT_DESTRUCTOR 264
|
||||||
#define PERCENT_UNION 265
|
#define PERCENT_PRINTER 265
|
||||||
#define PERCENT_LEFT 266
|
#define PERCENT_UNION 266
|
||||||
#define PERCENT_RIGHT 267
|
#define PERCENT_LEFT 267
|
||||||
#define PERCENT_NONASSOC 268
|
#define PERCENT_RIGHT 268
|
||||||
#define PERCENT_EXPECT 269
|
#define PERCENT_NONASSOC 269
|
||||||
#define PERCENT_START 270
|
#define PERCENT_EXPECT 270
|
||||||
#define PERCENT_PREC 271
|
#define PERCENT_START 271
|
||||||
#define PERCENT_VERBOSE 272
|
#define PERCENT_PREC 272
|
||||||
#define PERCENT_ERROR_VERBOSE 273
|
#define PERCENT_VERBOSE 273
|
||||||
#define PERCENT_OUTPUT 274
|
#define PERCENT_ERROR_VERBOSE 274
|
||||||
#define PERCENT_FILE_PREFIX 275
|
#define PERCENT_OUTPUT 275
|
||||||
#define PERCENT_NAME_PREFIX 276
|
#define PERCENT_FILE_PREFIX 276
|
||||||
#define PERCENT_DEFINE 277
|
#define PERCENT_NAME_PREFIX 277
|
||||||
#define PERCENT_PURE_PARSER 278
|
#define PERCENT_DEFINE 278
|
||||||
#define PERCENT_DEFINES 279
|
#define PERCENT_PURE_PARSER 279
|
||||||
#define PERCENT_YACC 280
|
#define PERCENT_DEFINES 280
|
||||||
#define PERCENT_DEBUG 281
|
#define PERCENT_YACC 281
|
||||||
#define PERCENT_LOCATIONS 282
|
#define PERCENT_DEBUG 282
|
||||||
#define PERCENT_NO_LINES 283
|
#define PERCENT_LOCATIONS 283
|
||||||
#define PERCENT_SKELETON 284
|
#define PERCENT_NO_LINES 284
|
||||||
#define PERCENT_TOKEN_TABLE 285
|
#define PERCENT_SKELETON 285
|
||||||
#define TYPE 286
|
#define PERCENT_TOKEN_TABLE 286
|
||||||
#define EQUAL 287
|
#define TYPE 287
|
||||||
#define SEMICOLON 288
|
#define EQUAL 288
|
||||||
#define COLON 289
|
#define SEMICOLON 289
|
||||||
#define PIPE 290
|
#define COLON 290
|
||||||
#define ID 291
|
#define PIPE 291
|
||||||
#define PERCENT_PERCENT 292
|
#define ID 292
|
||||||
#define PROLOGUE 293
|
#define PERCENT_PERCENT 293
|
||||||
#define EPILOGUE 294
|
#define PROLOGUE 294
|
||||||
#define BRACED_CODE 295
|
#define EPILOGUE 295
|
||||||
|
#define BRACED_CODE 296
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -103,8 +105,8 @@ typedef union {
|
|||||||
char *string;
|
char *string;
|
||||||
associativity assoc;
|
associativity assoc;
|
||||||
} yystype;
|
} yystype;
|
||||||
/* Line 1271 of /usr/local/share/bison/bison.simple. */
|
/* Line 1313 of /usr/local/share/bison/bison.simple. */
|
||||||
#line 108 "y.tab.h"
|
#line 110 "y.tab.h"
|
||||||
# define YYSTYPE yystype
|
# define YYSTYPE yystype
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -103,9 +103,13 @@ braced_code_t current_braced_code = action_braced_code;
|
|||||||
|
|
||||||
%token PERCENT_TOKEN "%token"
|
%token PERCENT_TOKEN "%token"
|
||||||
%token PERCENT_NTERM "%nterm"
|
%token PERCENT_NTERM "%nterm"
|
||||||
|
|
||||||
%token PERCENT_TYPE "%type"
|
%token PERCENT_TYPE "%type"
|
||||||
%token PERCENT_DESTRUCTOR "%destructor"
|
%token PERCENT_DESTRUCTOR "%destructor"
|
||||||
|
%token PERCENT_PRINTER "%printer"
|
||||||
|
|
||||||
%token PERCENT_UNION "%union"
|
%token PERCENT_UNION "%union"
|
||||||
|
|
||||||
%token PERCENT_LEFT "%left"
|
%token PERCENT_LEFT "%left"
|
||||||
%token PERCENT_RIGHT "%right"
|
%token PERCENT_RIGHT "%right"
|
||||||
%token PERCENT_NONASSOC "%nonassoc"
|
%token PERCENT_NONASSOC "%nonassoc"
|
||||||
@@ -212,6 +216,16 @@ grammar_declaration:
|
|||||||
symbol_list_free ($4);
|
symbol_list_free ($4);
|
||||||
current_braced_code = action_braced_code;
|
current_braced_code = action_braced_code;
|
||||||
}
|
}
|
||||||
|
| "%printer"
|
||||||
|
{ current_braced_code = printer_braced_code; }
|
||||||
|
BRACED_CODE symbols.1
|
||||||
|
{
|
||||||
|
symbol_list_t *list;
|
||||||
|
for (list = $4; list; list = list->next)
|
||||||
|
symbol_printer_set (list->sym, $3, list->location);
|
||||||
|
symbol_list_free ($4);
|
||||||
|
current_braced_code = action_braced_code;
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
symbol_declaration:
|
symbol_declaration:
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ int gram_parse (void *control);
|
|||||||
typedef enum braced_code_e
|
typedef enum braced_code_e
|
||||||
{
|
{
|
||||||
action_braced_code,
|
action_braced_code,
|
||||||
destructor_braced_code
|
destructor_braced_code,
|
||||||
|
printer_braced_code
|
||||||
} braced_code_t;
|
} braced_code_t;
|
||||||
/* FIXME: This is really a dirty hack which demonstrates that we
|
/* FIXME: This is really a dirty hack which demonstrates that we
|
||||||
should probably not try to parse the actions now. */
|
should probably not try to parse the actions now. */
|
||||||
|
|||||||
880
src/scan-gram.c
880
src/scan-gram.c
File diff suppressed because it is too large
Load Diff
@@ -136,6 +136,7 @@ blanks [ \t\f]+
|
|||||||
"%nterm" return PERCENT_NTERM;
|
"%nterm" return PERCENT_NTERM;
|
||||||
"%output" return PERCENT_OUTPUT;
|
"%output" return PERCENT_OUTPUT;
|
||||||
"%prec" return PERCENT_PREC;
|
"%prec" return PERCENT_PREC;
|
||||||
|
"%printer" return PERCENT_PRINTER;
|
||||||
"%pure"[-_]"parser" return PERCENT_PURE_PARSER;
|
"%pure"[-_]"parser" return PERCENT_PURE_PARSER;
|
||||||
"%right" return PERCENT_RIGHT;
|
"%right" return PERCENT_RIGHT;
|
||||||
"%skeleton" return PERCENT_SKELETON;
|
"%skeleton" return PERCENT_SKELETON;
|
||||||
@@ -524,7 +525,7 @@ blanks [ \t\f]+
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
/*------------------------------------------------------------------.
|
/*------------------------------------------------------------------.
|
||||||
| CP is pointing to a wannabee semantic value (i.e., a `$'). |
|
| TEXT is pointing to a wannabee semantic value (i.e., a `$'). |
|
||||||
| |
|
| |
|
||||||
| Possible inputs: $[<TYPENAME>]($|integer) |
|
| Possible inputs: $[<TYPENAME>]($|integer) |
|
||||||
| |
|
| |
|
||||||
@@ -532,11 +533,10 @@ blanks [ \t\f]+
|
|||||||
`------------------------------------------------------------------*/
|
`------------------------------------------------------------------*/
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
handle_action_dollar (char *cp, location_t location)
|
handle_action_dollar (char *text, location_t location)
|
||||||
{
|
{
|
||||||
const char *type_name = NULL;
|
const char *type_name = NULL;
|
||||||
|
char *cp = text + 1;
|
||||||
++cp;
|
|
||||||
|
|
||||||
/* Get the type name if explicit. */
|
/* Get the type name if explicit. */
|
||||||
if (*cp == '<')
|
if (*cp == '<')
|
||||||
@@ -588,31 +588,24 @@ handle_action_dollar (char *cp, location_t location)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char buf[] = "$c";
|
complain_at (location, _("%s is invalid"), quote (text));
|
||||||
buf[1] = *cp;
|
|
||||||
complain_at (location, _("%s is invalid"), quote (buf));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------.
|
/*---------------------------------------------------------------.
|
||||||
| CP is pointing to $$ in a destructor. |
|
| TEXT is expexted tp be $$ in some code associated to a symbol: |
|
||||||
`---------------------------------------*/
|
| destructor or printer. |
|
||||||
|
`---------------------------------------------------------------*/
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
handle_destructor_dollar (char *cp, location_t location)
|
handle_symbol_code_dollar (char *text, location_t location)
|
||||||
{
|
{
|
||||||
++cp;
|
char *cp = text + 1;
|
||||||
if (*cp == '$')
|
if (*cp == '$')
|
||||||
{
|
obstack_sgrow (&string_obstack, "]b4_dollar_dollar[");
|
||||||
obstack_sgrow (&string_obstack, "]b4_dollar_dollar[");
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
complain_at (location, _("%s is invalid"), quote (text));
|
||||||
char buf[] = "$c";
|
|
||||||
buf[1] = *cp;
|
|
||||||
complain_at (location, _("%s is invalid"), quote (buf));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -632,7 +625,8 @@ handle_dollar (braced_code_t braced_code_kind,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case destructor_braced_code:
|
case destructor_braced_code:
|
||||||
handle_destructor_dollar (text, location);
|
case printer_braced_code:
|
||||||
|
handle_symbol_code_dollar (text, location);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -646,21 +640,21 @@ handle_dollar (braced_code_t braced_code_kind,
|
|||||||
static inline void
|
static inline void
|
||||||
handle_action_at (char *text, location_t location)
|
handle_action_at (char *text, location_t location)
|
||||||
{
|
{
|
||||||
|
char *cp = text + 1;
|
||||||
locations_flag = 1;
|
locations_flag = 1;
|
||||||
++text;
|
|
||||||
|
|
||||||
if (*text == '$')
|
if (*cp == '$')
|
||||||
{
|
{
|
||||||
obstack_sgrow (&string_obstack, "]b4_lhs_location[");
|
obstack_sgrow (&string_obstack, "]b4_lhs_location[");
|
||||||
}
|
}
|
||||||
else if (isdigit (*text) || *text == '-')
|
else if (isdigit (*cp) || *cp == '-')
|
||||||
{
|
{
|
||||||
/* RULE_LENGTH is the number of values in the current rule so
|
/* RULE_LENGTH is the number of values in the current rule so
|
||||||
far, which says where to find `$0' with respect to the top of
|
far, which says where to find `$0' with respect to the top of
|
||||||
the stack. It is not the same as the rule->length in the
|
the stack. It is not the same as the rule->length in the
|
||||||
case of mid rule actions. */
|
case of mid rule actions. */
|
||||||
int rule_length = symbol_list_length (current_rule->next);
|
int rule_length = symbol_list_length (current_rule->next);
|
||||||
int n = strtol (text, &text, 10);
|
int n = strtol (cp, &cp, 10);
|
||||||
|
|
||||||
if (n > rule_length)
|
if (n > rule_length)
|
||||||
complain_at (location, _("invalid value: %s%d"), "@", n);
|
complain_at (location, _("invalid value: %s%d"), "@", n);
|
||||||
@@ -670,31 +664,24 @@ handle_action_at (char *text, location_t location)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char buf[] = "@c";
|
complain_at (location, _("%s is invalid"), quote (text));
|
||||||
buf[1] = *text;
|
|
||||||
complain_at (location, _("%s is invalid"), quote (buf));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*--------------------------------------------.
|
/*---------------------------------------------------------------.
|
||||||
| TEXT is expexted tp be @$ in a destructor. |
|
| TEXT is expexted tp be @$ in some code associated to a symbol: |
|
||||||
`--------------------------------------------*/
|
| destructor or printer. |
|
||||||
|
`---------------------------------------------------------------*/
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
handle_destructor_at (char *text, location_t location)
|
handle_symbol_code_at (char *text, location_t location)
|
||||||
{
|
{
|
||||||
++text;
|
char *cp = text + 1;
|
||||||
if (*text == '$')
|
if (*cp == '$')
|
||||||
{
|
obstack_sgrow (&string_obstack, "]b4_at_dollar[");
|
||||||
obstack_sgrow (&string_obstack, "]b4_at_dollar[");
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
complain_at (location, _("%s is invalid"), quote (text));
|
||||||
char buf[] = "$c";
|
|
||||||
buf[1] = *text;
|
|
||||||
complain_at (location, _("%s is invalid"), quote (buf));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -714,7 +701,8 @@ handle_at (braced_code_t braced_code_kind,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case destructor_braced_code:
|
case destructor_braced_code:
|
||||||
handle_destructor_at (text, location);
|
case printer_braced_code:
|
||||||
|
handle_symbol_code_at (text, location);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
26
src/symtab.c
26
src/symtab.c
@@ -118,8 +118,7 @@ symbol_type_set (symbol_t *symbol, location_t location, char *type_name)
|
|||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------.
|
/*-------------------------------------------------------------------.
|
||||||
| Set the DESTRUCTOR associated to SYMBOL. Does nothing if passed 0 |
|
| Set the DESTRUCTOR associated to SYMBOL. Do nothing if passed 0. |
|
||||||
| as DESTRUCTOR. |
|
|
||||||
`-------------------------------------------------------------------*/
|
`-------------------------------------------------------------------*/
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -129,14 +128,33 @@ symbol_destructor_set (symbol_t *symbol, location_t location, char *destructor)
|
|||||||
{
|
{
|
||||||
if (symbol->destructor)
|
if (symbol->destructor)
|
||||||
complain_at (location,
|
complain_at (location,
|
||||||
_("destructor redeclaration for %s"),
|
_("%s redeclaration for %s"),
|
||||||
symbol_tag_get (symbol));
|
"%destructor", symbol_tag_get (symbol));
|
||||||
symbol->destructor = destructor;
|
symbol->destructor = destructor;
|
||||||
symbol->destructor_location = location;
|
symbol->destructor_location = location;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------.
|
||||||
|
| Set the PRITNER associated to SYMBOL. Do nothing if passed 0. |
|
||||||
|
`----------------------------------------------------------------*/
|
||||||
|
|
||||||
|
void
|
||||||
|
symbol_printer_set (symbol_t *symbol, char *printer, location_t location)
|
||||||
|
{
|
||||||
|
if (printer)
|
||||||
|
{
|
||||||
|
if (symbol->printer)
|
||||||
|
complain_at (location,
|
||||||
|
_("%s redeclaration for %s"),
|
||||||
|
"%printer", symbol_tag_get (symbol));
|
||||||
|
symbol->printer = printer;
|
||||||
|
symbol->printer_location = location;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------.
|
/*------------------------------------------------------------------.
|
||||||
| Set the PRECEDENCE associated to SYMBOL. Does nothing if invoked |
|
| Set the PRECEDENCE associated to SYMBOL. Does nothing if invoked |
|
||||||
| with UNDEF_ASSOC as ASSOC. |
|
| with UNDEF_ASSOC as ASSOC. |
|
||||||
|
|||||||
@@ -59,11 +59,12 @@ struct symbol_s
|
|||||||
/* The location of its first occurence. */
|
/* The location of its first occurence. */
|
||||||
location_t location;
|
location_t location;
|
||||||
|
|
||||||
/* Its %type and associated destructor. */
|
/* Its %type and associated printer and destructor. */
|
||||||
char *type_name;
|
char *type_name;
|
||||||
char *destructor;
|
char *destructor;
|
||||||
location_t destructor_location;
|
location_t destructor_location;
|
||||||
|
char *printer;
|
||||||
|
location_t printer_location;
|
||||||
|
|
||||||
symbol_number_t number;
|
symbol_number_t number;
|
||||||
short prec;
|
short prec;
|
||||||
@@ -116,6 +117,10 @@ void symbol_type_set PARAMS ((symbol_t *symbol, location_t location,
|
|||||||
void symbol_destructor_set PARAMS ((symbol_t *symbol, location_t location,
|
void symbol_destructor_set PARAMS ((symbol_t *symbol, location_t location,
|
||||||
char *destructor));
|
char *destructor));
|
||||||
|
|
||||||
|
/* Set the PRINTER associated to SYMBOL. */
|
||||||
|
void symbol_printer_set PARAMS ((symbol_t *symbol,
|
||||||
|
char *printer, location_t location));
|
||||||
|
|
||||||
/* Set the PRECEDENCE associated to SYMBOL. Ensures that SYMBOL is a
|
/* Set the PRECEDENCE associated to SYMBOL. Ensures that SYMBOL is a
|
||||||
terminal. Does nothing if invoked with UNDEF_ASSOC as ASSOC. */
|
terminal. Does nothing if invoked with UNDEF_ASSOC as ASSOC. */
|
||||||
void symbol_precedence_set PARAMS ((symbol_t *symbol, location_t location,
|
void symbol_precedence_set PARAMS ((symbol_t *symbol, location_t location,
|
||||||
|
|||||||
@@ -415,40 +415,34 @@ _AT_CHECK_CALC([$1],
|
|||||||
(2^2)^3 = 64], [486])
|
(2^2)^3 = 64], [486])
|
||||||
|
|
||||||
# Some parse errors.
|
# Some parse errors.
|
||||||
_AT_CHECK_CALC_ERROR([$1], [0 0], [12],
|
_AT_CHECK_CALC_ERROR([$1], [0 0], [11],
|
||||||
[1.3-1.4: parse error, unexpected "number"])
|
[1.3-1.4: parse error, unexpected "number"])
|
||||||
_AT_CHECK_CALC_ERROR([$1], [1//2], [17],
|
_AT_CHECK_CALC_ERROR([$1], [1//2], [15],
|
||||||
[1.3-1.4: parse error, unexpected '/', expecting "number" or '-' or '('])
|
[1.3-1.4: parse error, unexpected '/', expecting "number" or '-' or '('])
|
||||||
_AT_CHECK_CALC_ERROR([$1], [error], [4],
|
_AT_CHECK_CALC_ERROR([$1], [error], [4],
|
||||||
[1.1-1.2: parse error, unexpected $undefined., expecting "number" or '-' or '\n' or '('])
|
[1.1-1.2: parse error, unexpected $undefined., expecting "number" or '-' or '\n' or '('])
|
||||||
_AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3], [25],
|
_AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3], [22],
|
||||||
[1.7-1.8: parse error, unexpected '='])
|
[1.7-1.8: parse error, unexpected '='])
|
||||||
_AT_CHECK_CALC_ERROR([$1],
|
_AT_CHECK_CALC_ERROR([$1],
|
||||||
[
|
[
|
||||||
+1],
|
+1],
|
||||||
[15],
|
[14],
|
||||||
[2.1-2.2: parse error, unexpected '+'])
|
[2.1-2.2: parse error, unexpected '+'])
|
||||||
# Exercise error messages with EOF: work on an empty file.
|
# Exercise error messages with EOF: work on an empty file.
|
||||||
_AT_CHECK_CALC_ERROR([$1],
|
_AT_CHECK_CALC_ERROR([$1], [/dev/null], [4],
|
||||||
[/dev/null],
|
|
||||||
[4],
|
|
||||||
[1.1-1.2: parse error, unexpected "end of file", expecting "number" or '-' or '\n' or '('])
|
[1.1-1.2: parse error, unexpected "end of file", expecting "number" or '-' or '\n' or '('])
|
||||||
|
|
||||||
# Exercise the error token: without it, we die at the first error,
|
# Exercise the error token: without it, we die at the first error,
|
||||||
# hence be sure i. to have several errors, ii. to test the action
|
# hence be sure i. to have several errors, ii. to test the action
|
||||||
# associated to `error'.
|
# associated to `error'.
|
||||||
_AT_CHECK_CALC_ERROR([$1],
|
_AT_CHECK_CALC_ERROR([$1], [(1 ++ 2) + (0 0) = 1], [82],
|
||||||
[(1 ++ 2) + (0 0) = 1],
|
|
||||||
[91],
|
|
||||||
[1.5-1.6: parse error, unexpected '+', expecting "number" or '-' or '('
|
[1.5-1.6: parse error, unexpected '+', expecting "number" or '-' or '('
|
||||||
1.15-1.16: parse error, unexpected "number"
|
1.15-1.16: parse error, unexpected "number"
|
||||||
calc: error: 0 != 1])
|
calc: error: 0 != 1])
|
||||||
|
|
||||||
# Add a studid example demonstrating that Bison can further improve the
|
# Add a studid example demonstrating that Bison can further improve the
|
||||||
# error message. FIXME: Fix this ridiculous message.
|
# error message. FIXME: Fix this ridiculous message.
|
||||||
_AT_CHECK_CALC_ERROR([$1],
|
_AT_CHECK_CALC_ERROR([$1], [()], [21],
|
||||||
[()],
|
|
||||||
[21],
|
|
||||||
[1.2-1.3: parse error, unexpected ')', expecting error or "number" or '-' or '('])
|
[1.2-1.3: parse error, unexpected ')', expecting error or "number" or '-' or '('])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|||||||
@@ -371,9 +371,6 @@ AT_DATA([input.y],
|
|||||||
]$1[
|
]$1[
|
||||||
static int yylex (void);
|
static int yylex (void);
|
||||||
static void yyerror (const char *msg);
|
static void yyerror (const char *msg);
|
||||||
#define YYPRINT(File, Type, Value) \
|
|
||||||
fprintf (File, " (%d, stack size = %d, max = %d)", \
|
|
||||||
Value, yyssp - yyss + 1, yystacksize);
|
|
||||||
%}
|
%}
|
||||||
%error-verbose
|
%error-verbose
|
||||||
%debug
|
%debug
|
||||||
|
|||||||
Reference in New Issue
Block a user