mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-17 08:13:02 +00:00
* data/glr.c, data/lalr1.cc, data/yacc.c: When YYABORT was
invoked, yydestruct the lookahead. * tests/calc.at (Calculator $1): Update the expected lengths of traces: there is an added line for the discarded lookahead. * doc/bison.texinfo (Destructor Decl): Some rewording. Define "discarded" symbols.
This commit is contained in:
@@ -1,3 +1,12 @@
|
|||||||
|
2004-09-03 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* data/glr.c, data/lalr1.cc, data/yacc.c: When YYABORT was
|
||||||
|
invoked, yydestruct the lookahead.
|
||||||
|
* tests/calc.at (Calculator $1): Update the expected lengths of
|
||||||
|
traces: there is an added line for the discarded lookahead.
|
||||||
|
* doc/bison.texinfo (Destructor Decl): Some rewording.
|
||||||
|
Define "discarded" symbols.
|
||||||
|
|
||||||
2004-09-02 Akim Demaille <akim@epita.fr>
|
2004-09-02 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* data/lalr1.cc (translate_, destruct_): No reason to be static.
|
* data/lalr1.cc (translate_, destruct_): No reason to be static.
|
||||||
|
|||||||
@@ -1916,7 +1916,13 @@ yyrecoverSyntaxError (yyGLRStack* yystack,
|
|||||||
yyposn = yystack.yytops.yystates[0]->yyposn;
|
yyposn = yystack.yytops.yystates[0]->yyposn;
|
||||||
}
|
}
|
||||||
yyDone:
|
yyDone:
|
||||||
;
|
/* On YYABORT, free the lookahead. */
|
||||||
|
if (yystack.yyerrflag == 1 && yytoken != YYEMPTY)
|
||||||
|
{
|
||||||
|
YY_SYMBOL_PRINT ("Error: discarding lookahead",
|
||||||
|
yytoken, yylvalp, yyllocp);
|
||||||
|
yydestruct (yytoken, yylvalp]b4_location_if([, yyllocp])[);
|
||||||
|
}
|
||||||
|
|
||||||
yyfreeGLRStack (&yystack);
|
yyfreeGLRStack (&yystack);
|
||||||
return yystack.yyerrflag;
|
return yystack.yyerrflag;
|
||||||
|
|||||||
@@ -714,6 +714,10 @@ yyacceptlab:
|
|||||||
|
|
||||||
/* Abort. */
|
/* Abort. */
|
||||||
yyabortlab:
|
yyabortlab:
|
||||||
|
/* Free the lookahead. */
|
||||||
|
YY_SYMBOL_PRINT ("Error: discarding lookahead", ilooka_, &value, &location);
|
||||||
|
destruct_ (ilooka_, &value, &location);
|
||||||
|
looka_ = empty_;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1209,6 +1209,9 @@ yyacceptlab:
|
|||||||
| yyabortlab -- YYABORT comes here. |
|
| yyabortlab -- YYABORT comes here. |
|
||||||
`-----------------------------------*/
|
`-----------------------------------*/
|
||||||
yyabortlab:
|
yyabortlab:
|
||||||
|
YY_SYMBOL_PRINT ("Error: discarding lookahead", yytoken, &yylval, &yylloc);
|
||||||
|
yydestruct (yytoken, &yylval]b4_location_if([, &yylloc])[);
|
||||||
|
yychar = YYEMPTY;
|
||||||
yyresult = 1;
|
yyresult = 1;
|
||||||
goto yyreturn;
|
goto yyreturn;
|
||||||
|
|
||||||
|
|||||||
@@ -3734,14 +3734,13 @@ terminal symbol. All kinds of token declarations allow
|
|||||||
@cindex freeing discarded symbols
|
@cindex freeing discarded symbols
|
||||||
@findex %destructor
|
@findex %destructor
|
||||||
|
|
||||||
Some symbols can be discarded by the parser, typically during error
|
Some symbols can be discarded by the parser. For instance, during error
|
||||||
recovery (@pxref{Error Recovery}). Basically, during error recovery,
|
recovery (@pxref{Error Recovery}), embarrassing symbols already pushed
|
||||||
embarrassing symbols already pushed on the stack, and embarrassing
|
on the stack, and embarrassing tokens coming from the rest of the file
|
||||||
tokens coming from the rest of the file are thrown away until the parser
|
are thrown away until the parser falls on its feet. If these symbols
|
||||||
falls on its feet. If these symbols convey heap based information, this
|
convey heap based information, this memory is lost. While this behavior
|
||||||
memory is lost. While this behavior is tolerable for batch parsers,
|
can be tolerable for batch parsers, such as in compilers, it is not for
|
||||||
such as in compilers, it is unacceptable for parsers that can
|
possibly ``never ending'' parsers such as shells, or implementations of
|
||||||
possibility ``never end'' such as shells, or implementations of
|
|
||||||
communication protocols.
|
communication protocols.
|
||||||
|
|
||||||
The @code{%destructor} directive allows for the definition of code that
|
The @code{%destructor} directive allows for the definition of code that
|
||||||
@@ -3794,6 +3793,22 @@ typeless: string; // $$ = $1 does not apply; $1 is destroyed.
|
|||||||
typefull: string; // $$ = $1 applies, $1 is not destroyed.
|
typefull: string; // $$ = $1 applies, $1 is not destroyed.
|
||||||
@end smallexample
|
@end smallexample
|
||||||
|
|
||||||
|
@sp 1
|
||||||
|
|
||||||
|
@cindex discarded symbols
|
||||||
|
@dfn{Discarded symbols} are the following:
|
||||||
|
|
||||||
|
@itemize
|
||||||
|
@item
|
||||||
|
stacked symbols popped during the first phase of error recovery,
|
||||||
|
@item
|
||||||
|
incoming terminals during the second phase of error recovery,
|
||||||
|
@item
|
||||||
|
the current lookahead when the parser aborts (either via an explicit
|
||||||
|
call to @code{YYABORT}, or as a consequence of a failed error recovery).
|
||||||
|
@end itemize
|
||||||
|
|
||||||
|
|
||||||
@node Expect Decl
|
@node Expect Decl
|
||||||
@subsection Suppressing Conflict Warnings
|
@subsection Suppressing Conflict Warnings
|
||||||
@cindex suppressing conflict warnings
|
@cindex suppressing conflict warnings
|
||||||
|
|||||||
@@ -466,21 +466,21 @@ _AT_CHECK_CALC([$1],
|
|||||||
[486])
|
[486])
|
||||||
|
|
||||||
# Some syntax errors.
|
# Some syntax errors.
|
||||||
_AT_CHECK_CALC_ERROR([$1], [1], [0 0], [11],
|
_AT_CHECK_CALC_ERROR([$1], [1], [0 0], [12],
|
||||||
[1.2: syntax error, unexpected "number"])
|
[1.2: syntax error, unexpected "number"])
|
||||||
_AT_CHECK_CALC_ERROR([$1], [1], [1//2], [15],
|
_AT_CHECK_CALC_ERROR([$1], [1], [1//2], [16],
|
||||||
[1.2: syntax error, unexpected '/', expecting "number" or '-' or '(' or '!'])
|
[1.2: syntax error, unexpected '/', expecting "number" or '-' or '(' or '!'])
|
||||||
_AT_CHECK_CALC_ERROR([$1], [1], [error], [4],
|
_AT_CHECK_CALC_ERROR([$1], [1], [error], [5],
|
||||||
[1.0: syntax error, unexpected $undefined])
|
[1.0: syntax error, unexpected $undefined])
|
||||||
_AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3], [22],
|
_AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3], [23],
|
||||||
[1.6: syntax error, unexpected '='])
|
[1.6: syntax error, unexpected '='])
|
||||||
_AT_CHECK_CALC_ERROR([$1], [1],
|
_AT_CHECK_CALC_ERROR([$1], [1],
|
||||||
[
|
[
|
||||||
+1],
|
+1],
|
||||||
[14],
|
[15],
|
||||||
[2.0: syntax error, unexpected '+'])
|
[2.0: syntax 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], [1], [/dev/null], [4],
|
_AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [5],
|
||||||
[1.0: syntax error, unexpected "end of input"])
|
[1.0: syntax error, unexpected "end of input"])
|
||||||
|
|
||||||
# Exercise the error token: without it, we die at the first error,
|
# Exercise the error token: without it, we die at the first error,
|
||||||
|
|||||||
Reference in New Issue
Block a user