mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 00:33:03 +00:00
* data/yacc.c, data/glr.c, data/lal1.cc: Use similar code to
generate verbose error messages. Use the number of tokens as an upper bound in yytname, as it cannot be a non terminal.
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
2003-03-02 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* data/yacc.c, data/glr.c, data/lal1.cc: Use similar code to
|
||||||
|
generate verbose error messages.
|
||||||
|
Use the number of tokens as an upper bound in yytname, as it
|
||||||
|
cannot be a non terminal.
|
||||||
|
|
||||||
2003-03-02 Akim Demaille <akim@epita.fr>
|
2003-03-02 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* tests/regression.at (_AT_DATA_DANCER_Y): Fix the expected error
|
* tests/regression.at (_AT_DATA_DANCER_Y): Fix the expected error
|
||||||
|
|||||||
13
data/glr.c
13
data/glr.c
@@ -1597,29 +1597,28 @@ yyreportSyntaxError (yyGLRStack* yystack,
|
|||||||
#if YYERROR_VERBOSE
|
#if YYERROR_VERBOSE
|
||||||
yySymbol* const yytokenp = yystack->yytokenp;
|
yySymbol* const yytokenp = yystack->yytokenp;
|
||||||
int yyn;
|
int yyn;
|
||||||
const char* yyprefix;
|
|
||||||
yyn = yypact[yystack->yytops.yystates[0]->yylrState];
|
yyn = yypact[yystack->yytops.yystates[0]->yylrState];
|
||||||
if (YYPACT_NINF < yyn && yyn < YYLAST)
|
if (YYPACT_NINF < yyn && yyn < YYLAST)
|
||||||
{
|
{
|
||||||
size_t yysize = 0;
|
size_t yysize = 0;
|
||||||
|
const char* yyprefix;
|
||||||
char* yymsg;
|
char* yymsg;
|
||||||
int yyx;
|
int yyx;
|
||||||
|
|
||||||
/* Start YYX at -YYN if negative to avoid negative indexes in
|
/* Start YYX at -YYN if negative to avoid negative indexes in
|
||||||
YYCHECK. */
|
YYCHECK. */
|
||||||
int yyxbase = yyn < 0 ? -yyn : 0;
|
int yyxbegin = yyn < 0 ? -yyn : 0;
|
||||||
|
|
||||||
/* Stay within bounds of both yycheck and yytname. */
|
/* Stay within bounds of both yycheck and yytname. */
|
||||||
int yychecklim = YYLAST - yyn;
|
int yychecklim = YYLAST - yyn;
|
||||||
int yynsyms = sizeof (yytname) / sizeof (yytname[0]);
|
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
|
||||||
int yyxlim = yychecklim < yynsyms ? yychecklim : yynsyms;
|
|
||||||
int yycount = 0;
|
int yycount = 0;
|
||||||
|
|
||||||
yyprefix = ", expecting ";
|
yyprefix = ", expecting ";
|
||||||
for (yyx = yyxbase; yyx < yyxlim && yycount < 5; yyx += 1)
|
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
|
||||||
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
|
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
|
||||||
{
|
{
|
||||||
yysize += strlen (yytokenName (yyx)) + strlen (yyprefix);
|
yysize += strlen (yyprefix) + strlen (yytokenName (yyx));
|
||||||
yycount += 1;
|
yycount += 1;
|
||||||
if (yycount == 5)
|
if (yycount == 5)
|
||||||
{
|
{
|
||||||
@@ -1640,7 +1639,7 @@ yyreportSyntaxError (yyGLRStack* yystack,
|
|||||||
if (yycount < 5)
|
if (yycount < 5)
|
||||||
{
|
{
|
||||||
yyprefix = ", expecting ";
|
yyprefix = ", expecting ";
|
||||||
for (yyx = yyxbase; yyx < yyxlim; yyx += 1)
|
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
|
||||||
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
|
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
|
||||||
{
|
{
|
||||||
sprintf (yyp, "%s%s", yyprefix, yytokenName (yyx));
|
sprintf (yyp, "%s%s", yyprefix, yytokenName (yyx));
|
||||||
|
|||||||
@@ -498,13 +498,19 @@ b4_syncline([@oline@], [@ofile@])[
|
|||||||
message += name_[ilooka_];
|
message += name_[ilooka_];
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x)
|
/* Start YYX at -YYN if negative to avoid negative indexes in
|
||||||
|
YYCHECK. */
|
||||||
|
int xbegin = n_ < 0 ? -n_ : 0;
|
||||||
|
/* Stay within bounds of both yycheck and yytname. */
|
||||||
|
int checklim = last_ - n_;
|
||||||
|
int xend = checklim < ntokens_ ? checklim : ntokens_;
|
||||||
|
for (int x = xbegin; x < xend; ++x)
|
||||||
if (check_[x + n_] == x && x != terror_)
|
if (check_[x + n_] == x && x != terror_)
|
||||||
++count;
|
++count;
|
||||||
if (count < 5)
|
if (count < 5)
|
||||||
{
|
{
|
||||||
count = 0;
|
count = 0;
|
||||||
for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x)
|
for (int x = xbegin; x < xend; ++x)
|
||||||
if (check_[x + n_] == x && x != terror_)
|
if (check_[x + n_] == x && x != terror_)
|
||||||
{
|
{
|
||||||
message += (!count++) ? ", expecting " : " or ";
|
message += (!count++) ? ", expecting " : " or ";
|
||||||
|
|||||||
25
data/yacc.c
25
data/yacc.c
@@ -1038,27 +1038,25 @@ yyerrlab:
|
|||||||
{
|
{
|
||||||
YYSIZE_T yysize = 0;
|
YYSIZE_T yysize = 0;
|
||||||
int yytype = YYTRANSLATE (yychar);
|
int yytype = YYTRANSLATE (yychar);
|
||||||
|
const char* yyprefix;
|
||||||
char *yymsg;
|
char *yymsg;
|
||||||
int yyx;
|
int yyx;
|
||||||
|
|
||||||
/* Start YYX at -YYN if negative to avoid negative indexes in
|
/* Start YYX at -YYN if negative to avoid negative indexes in
|
||||||
YYCHECK. */
|
YYCHECK. */
|
||||||
int yyxbase = yyn < 0 ? -yyn : 0;
|
int yyxbegin = yyn < 0 ? -yyn : 0;
|
||||||
|
|
||||||
/* Stay within bounds of both yycheck and yytname. */
|
/* Stay within bounds of both yycheck and yytname. */
|
||||||
int yychecklim = YYLAST - yyn;
|
int yychecklim = YYLAST - yyn;
|
||||||
int yynsyms = sizeof (yytname) / sizeof (yytname[0]);
|
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
|
||||||
int yyxlim = yychecklim < yynsyms ? yychecklim : yynsyms;
|
|
||||||
int yycount = 0;
|
int yycount = 0;
|
||||||
|
|
||||||
for (yyx = yyxbase; yyx < yyxlim; yyx++)
|
yyprefix = ", expecting ";
|
||||||
|
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
|
||||||
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
|
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
|
||||||
{
|
{
|
||||||
yysize += (! yycount
|
yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]);
|
||||||
? sizeof (", expecting ") - 1
|
yycount += 1;
|
||||||
: sizeof (" or ") - 1);
|
|
||||||
yysize += yystrlen (yytname[yyx]);
|
|
||||||
yycount++;
|
|
||||||
if (yycount == 5)
|
if (yycount == 5)
|
||||||
{
|
{
|
||||||
yysize = 0;
|
yysize = 0;
|
||||||
@@ -1075,14 +1073,13 @@ yyerrlab:
|
|||||||
|
|
||||||
if (yycount < 5)
|
if (yycount < 5)
|
||||||
{
|
{
|
||||||
yycount = 0;
|
yyprefix = ", expecting ";
|
||||||
for (yyx = yyxbase; yyx < yyxlim; yyx++)
|
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
|
||||||
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
|
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
|
||||||
{
|
{
|
||||||
const char *yyq = ! yycount ? ", expecting " : " or ";
|
yyp = yystpcpy (yyp, yyprefix);
|
||||||
yyp = yystpcpy (yyp, yyq);
|
|
||||||
yyp = yystpcpy (yyp, yytname[yyx]);
|
yyp = yystpcpy (yyp, yytname[yyx]);
|
||||||
yycount++;
|
yyprefix = " or ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
yyerror (]b4_yyerror_args[yymsg);
|
yyerror (]b4_yyerror_args[yymsg);
|
||||||
|
|||||||
Reference in New Issue
Block a user