* data/c.m4 (b4_yydestruct_generate, b4_symbol_actions): New.

* data/yacc.c: Rename yychar1 as yytoken, as in glr.c.
Don't work on yychar (i.e., do set it to YYEMPTY, don't match
it against YYEMPTY and so forth), work on yytoken (i.e., set
it to YYEMPTY etc.).
(yydestruct): Replace with a b4_yydestruct_generate invocation.
(b4_symbol_actions): Remove.
* data/glr.c (YYTRANSLATE): As for yacc.c, if negative, it stands
for 0, end-of-input.
This commit is contained in:
Akim Demaille
2002-11-12 08:45:40 +00:00
parent 72f889cca3
commit b0400cc6ef
4 changed files with 92 additions and 80 deletions

View File

@@ -1,3 +1,15 @@
2002-11-12 Akim Demaille <akim@epita.fr>
* data/c.m4 (b4_yydestruct_generate, b4_symbol_actions): New.
* data/yacc.c: Rename yychar1 as yytoken, as in glr.c.
Don't work on yychar (i.e., do set it to YYEMPTY, don't match
it against YYEMPTY and so forth), work on yytoken (i.e., set
it to YYEMPTY etc.).
(yydestruct): Replace with a b4_yydestruct_generate invocation.
(b4_symbol_actions): Remove.
* data/glr.c (YYTRANSLATE): As for yacc.c, if negative, it stands
for 0, end-of-input.
2002-11-12 Akim Demaille <akim@epita.fr> 2002-11-12 Akim Demaille <akim@epita.fr>
* doc/bison.texinfo (Destructor Decl): New. * doc/bison.texinfo (Destructor Decl): New.

View File

@@ -320,3 +320,50 @@ m4_define([b4_c_arg],
m4_define([b4_syncline], m4_define([b4_syncline],
[m4_if(b4_synclines_flag, 1, [m4_if(b4_synclines_flag, 1,
[[#]line $1 $2])]) [[#]line $1 $2])])
# b4_symbol_actions(FILENAME, LINENO,
# SYMBOL-TAG, SYMBOL-NUM,
# SYMBOL-ACTION, SYMBOL-TYPENAME)
# -------------------------------------------------
m4_define([b4_symbol_actions],
[m4_pushdef([b4_dollar_dollar], [yyvalue.$6])dnl
m4_pushdef([b4_at_dollar], [yylocation])dnl
case $4: /* $3 */
b4_syncline([$2], [$1])
$5;
b4_syncline([@oline@], [@ofile@])
break;
m4_popdef([b4_at_dollar])dnl
m4_popdef([b4_dollar_dollar])dnl
])
# b4_yydestruct_generate(FUNTION-DECLARATOR)
# ------------------------------------------
# Generate the "yydestruct" function, which declaration is issued using
# FUNTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C
# or "b4_c_function_def" for K&R.
m4_define([b4_yydestruct_generate],
[[/*-----------------------------------------------.
| Release the memory associated to this symbol. |
`-----------------------------------------------*/
]$1([yydestruct],
[static void],
[[int yytype], [yytype]],
[[YYSTYPE yyvalue], [yyvalue]]b4_location_if([,
[[YYLTYPE yylocation], [yylocation]]]))[
{
/* Pacify ``unused variable'' warnings. */
(void) yyvalue;
]b4_location_if([ (void) yylocation;
])[
switch (yytype)
{
]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
default:
break;
}
}]dnl
])

View File

@@ -267,8 +267,9 @@ b4_syncline([@oline@], [@ofile@])
#define YYUNDEFTOK ]b4_undef_token_number[ #define YYUNDEFTOK ]b4_undef_token_number[
#define YYMAXUTOK ]b4_user_token_number_max[ #define YYMAXUTOK ]b4_user_token_number_max[
#define YYTRANSLATE(YYX) \ #define YYTRANSLATE(YYX) \
((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) ((YYX <= 0) ? YYEOF : \
(unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
static const ]b4_int_type_for([b4_translate])[ yytranslate[] = static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
@@ -1505,7 +1506,7 @@ yyprocessOneStack (yyGLRStack* yystack, int yyk,
{ {
YYDPRINTF ((stderr, "Reading a token: ")); YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX; yychar = YYLEX;
*yytokenp = YYTRANSLATE(yychar); *yytokenp = YYTRANSLATE (yychar);
YYDPRINTF ((stderr, "Next token is %s\n", YYDPRINTF ((stderr, "Next token is %s\n",
yytokenName (*yytokenp))); yytokenName (*yytokenp)));
} }
@@ -1578,8 +1579,7 @@ yyreportParseError (yyGLRStack* yystack,
yysize += strlen (yytokenName (yyx)) + strlen (yyprefix), yysize += strlen (yytokenName (yyx)) + strlen (yyprefix),
yycount += 1, yyprefix = " or "; yycount += 1, yyprefix = " or ";
yymsg = yyp = (char*) malloc (yysize); yymsg = yyp = (char*) malloc (yysize);
sprintf (yyp, "parse error, unexpected %s", sprintf (yyp, "parse error, unexpected %s", yytokenName (*yytokenp));
yytokenName (*yytokenp));
yyp += strlen (yyp); yyp += strlen (yyp);
if (yycount < 5) if (yycount < 5)
{ {

View File

@@ -133,23 +133,6 @@ m4_define([b4_rhs_location],
## Defining symbol actions, e.g., printers and destructors. ## ## Defining symbol actions, e.g., printers and destructors. ##
## --------------------------------------------------------- ## ## --------------------------------------------------------- ##
# b4_symbol_actions(FILENAME, LINENO,
# SYMBOL-TAG, SYMBOL-NUM,
# SYMBOL-ACTION, SYMBOL-TYPENAME)
# -------------------------------------------------
m4_define([b4_symbol_actions],
[m4_pushdef([b4_dollar_dollar], [yyvalue.$6])dnl
m4_pushdef([b4_at_dollar], [yylocation])dnl
case $4: /* $3 */
b4_syncline([$2], [$1])
$5;
b4_syncline([@oline@], [@ofile@])
break;
m4_popdef([b4_at_dollar])dnl
m4_popdef([b4_dollar_dollar])dnl
])
# We do want M4 expansion after # for CPP macros. # We do want M4 expansion after # for CPP macros.
m4_changecom() m4_changecom()
m4_divert(0)dnl m4_divert(0)dnl
@@ -348,15 +331,16 @@ b4_location_if(
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
#define YYUNDEFTOK b4_undef_token_number #define YYUNDEFTOK b4_undef_token_number
#define YYMAXUTOK b4_user_token_number_max #define YYMAXUTOK b4_user_token_number_max[
#define YYTRANSLATE(X) \ #define YYTRANSLATE(YYX) \
((unsigned)(X) <= YYMAXUTOK ? yytranslate[[X]] : YYUNDEFTOK) ((YYX <= 0) ? YYEOF : \
(unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
/* YYTRANSLATE[[YYLEX]] -- Bison symbol number corresponding to YYLEX. */ /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
static const b4_int_type_for([b4_translate]) yytranslate[[]] = static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
{ {
b4_translate ]b4_translate
}; };
#if YYDEBUG #if YYDEBUG
@@ -477,7 +461,7 @@ static const b4_int_type_for([b4_stos]) yystos[[]] =
#endif #endif
#define yyerrok (yyerrstatus = 0) #define yyerrok (yyerrstatus = 0)
#define yyclearin (yychar = YYEMPTY) #define yyclearin (yytoken = YYEMPTY)
#define YYEMPTY -2 #define YYEMPTY -2
#define YYEOF 0 #define YYEOF 0
@@ -495,11 +479,11 @@ static const b4_int_type_for([b4_stos]) yystos[[]] =
#define YYBACKUP(Token, Value) \ #define YYBACKUP(Token, Value) \
do \ do \
if (yychar == YYEMPTY && yylen == 1) \ if (yytoken == YYEMPTY && yylen == 1) \
{ \ { \
yychar = (Token); \ yychar = (Token); \
yylval = (Value); \ yylval = (Value); \
yychar1 = YYTRANSLATE (yychar); \ yytoken = YYTRANSLATE (yychar); \
YYPOPSTACK; \ YYPOPSTACK; \
goto yybackup; \ goto yybackup; \
} \ } \
@@ -672,30 +656,7 @@ m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
} }
#endif /* YYDEBUG. */ #endif /* YYDEBUG. */
b4_yydestruct_generate([b4_c_function_def])
/*-----------------------------------------------.
| Release the memory associated to this symbol. |
`-----------------------------------------------*/
b4_c_function_def([yydestruct],
[static void],
[[int yytype], [yytype]],
[[YYSTYPE yyvalue], [yyvalue]]b4_location_if([,
[[YYLTYPE yylocation], [yylocation]]]))
{
/* Pacify ``unused variable'' warnings. */
(void) yyvalue;
b4_location_if([ (void) yylocation;
])dnl
switch (yytype)
{
m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))dnl
default:
break;
}
}
/* Prevent warnings from -Wmissing-prototypes. */ /* Prevent warnings from -Wmissing-prototypes. */
@@ -756,7 +717,7 @@ b4_c_function_def([yyparse], [int], b4_parse_param)
/* Number of tokens to shift before error messages enabled. */ /* Number of tokens to shift before error messages enabled. */
int yyerrstatus; int yyerrstatus;
/* Lookahead token as an internal (translated) token number. */ /* Lookahead token as an internal (translated) token number. */
int yychar1 = 0; int yytoken = 0;
/* Three stacks and their tools: /* Three stacks and their tools:
`yyss': related to states, `yyss': related to states,
@@ -800,7 +761,7 @@ b4_c_function_def([yyparse], [int], b4_parse_param)
yystate = 0; yystate = 0;
yyerrstatus = 0; yyerrstatus = 0;
yynerrs = 0; yynerrs = 0;
yychar = YYEMPTY; /* Cause a token to be read. */ yychar = yytoken = YYEMPTY; /* Cause a token to be read. */
/* Initialize stack pointers. /* Initialize stack pointers.
Waste one element of value and location stack Waste one element of value and location stack
@@ -910,39 +871,31 @@ yybackup:
/* Not known => get a lookahead token if don't already have one. */ /* Not known => get a lookahead token if don't already have one. */
/* yychar is either YYEMPTY or YYEOF /* YYTOKEN is either YYEMPTY or YYEOF or a valid token. */
or a valid token in external form. */ if (yytoken == YYEMPTY)
if (yychar == YYEMPTY)
{ {
YYDPRINTF ((stderr, "Reading a token: ")); YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX; yychar = YYLEX;
yytoken = YYTRANSLATE (yychar);
} }
/* Convert token to internal form (in yychar1) for indexing tables with. */ if (yytoken == YYEOF)
if (yychar <= 0) /* This means end of input. */
{ {
yychar1 = 0;
yychar = YYEOF; /* Don't call YYLEX any more. */
YYDPRINTF ((stderr, "Now at end of input.\n")); YYDPRINTF ((stderr, "Now at end of input.\n"));
} }
else else
{ {
yychar1 = YYTRANSLATE (yychar);
/* We have to keep this `#if YYDEBUG', since we use variables /* We have to keep this `#if YYDEBUG', since we use variables
which are defined only if `YYDEBUG' is set. */ which are defined only if `YYDEBUG' is set. */
YYDPRINTF ((stderr, "Next token is ")); YYDPRINTF ((stderr, "Next token is "));
YYDSYMPRINT ((stderr, yychar1, yylval]b4_location_if([, yyloc])[)); YYDSYMPRINT ((stderr, yytoken, yylval]b4_location_if([, yyloc])[));
YYDPRINTF ((stderr, "\n")); YYDPRINTF ((stderr, "\n"));
} }
/* If the proper action on seeing token YYCHAR1 is to reduce or to /* If the proper action on seeing token YYTOKEN is to reduce or to
detect an error, take that action. */ detect an error, take that action. */
yyn += yychar1; yyn += yytoken;
if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yychar1) if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
goto yydefault; goto yydefault;
yyn = yytable[yyn]; yyn = yytable[yyn];
if (yyn <= 0) if (yyn <= 0)
@@ -958,11 +911,11 @@ yybackup:
/* Shift the lookahead token. */ /* Shift the lookahead token. */
YYDPRINTF ((stderr, "Shifting token %d (%s), ", YYDPRINTF ((stderr, "Shifting token %d (%s), ",
yychar, yytname[yychar1])); yytoken, yytname[yytoken]));
/* Discard the token being shifted unless it is eof. */ /* Discard the token being shifted unless it is eof. */
if (yychar != YYEOF) if (yytoken != YYEOF)
yychar = YYEMPTY; yytoken = YYEMPTY;
*++yyvsp = yylval; *++yyvsp = yylval;
]b4_location_if([ *++yylsp = yylloc;])[ ]b4_location_if([ *++yylsp = yylloc;])[
@@ -1134,7 +1087,7 @@ yyerrlab1:
error, discard it. */ error, discard it. */
/* Return failure if at end of input. */ /* Return failure if at end of input. */
if (yychar == YYEOF) if (yytoken == YYEOF)
{ {
/* Pop the error token. */ /* Pop the error token. */
YYPOPSTACK; YYPOPSTACK;
@@ -1153,9 +1106,9 @@ yyerrlab1:
} }
YYDPRINTF ((stderr, "Discarding token %d (%s).\n", YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
yychar, yytname[yychar1])); yytoken, yytname[yytoken]));
yydestruct (yychar1, yylval]b4_location_if([, yylloc])[); yydestruct (yytoken, yylval]b4_location_if([, yylloc])[);
yychar = YYEMPTY; yytoken = YYEMPTY;
} }
/* Else will try to reuse lookahead token after shifting the error /* Else will try to reuse lookahead token after shifting the error