+2006-10-05 Paul Eggert <eggert@cs.ucla.edu>
+
+ Fix test failure reported by Tom Lane in
+ <http://lists.gnu.org/archive/html/bug-bison/2006-10/msg00000.html>
+ and try to make such failures easier to catch in the future.
+ * data/glr.c (YYTRANSLATE): Don't check for nonpositive arg;
+ that's now the caller's responsibility.
+ (yyprocessOneStack, yyrecoverSyntaxError, yyparse):
+ Set yychar = YYEOF if it's negative.
+ * tests/actions.at (yylex): Abort if asked to read past EOF.
+ * tests/conflicts.at (yylex): Likewise.
+ * tests/cxx-type.at (yylex): Likewise.
+ * tests/glr-regression.at (yylex): Likewise.
+ * tests/input.at (yylex): Likewise.
+ * tests/regression.at (yylex): Likewise.
+ * tests/torture.at (yylex): Likewise.
+
2006-10-01 Paul Eggert <eggert@cs.ucla.edu>
Fix problems with translating English-language diagnostics.
#define YYMAXUTOK ]b4_user_token_number_max[
#define YYTRANSLATE(YYX) \
- ((YYX <= 0) ? YYEOF : \
- (unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
{
YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX;
+ }
+
+ if (yychar <= YYEOF)
+ {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else
+ {
yytoken = YYTRANSLATE (yychar);
YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
}
- else
- yytoken = YYTRANSLATE (yychar);
+
yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
while (*yyconflicts != 0)
}
YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX;
- yytoken = YYTRANSLATE (yychar);
- YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+ if (yychar <= YYEOF)
+ {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else
+ {
+ yytoken = YYTRANSLATE (yychar);
+ YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+ }
yyj = yypact[yystackp->yytops.yystates[0]->yylrState];
if (yyis_pact_ninf (yyj))
return;
{
YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX;
+ }
+
+ if (yychar <= YYEOF)
+ {
+ yychar = yytoken = YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else
+ {
yytoken = YYTRANSLATE (yychar);
YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
}
- else
- yytoken = YYTRANSLATE (yychar);
+
yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
if (*yyconflicts != 0)
break;
static int
yylex (void)
{
- static const char *input = "123456789";
- return *input++;
+ static char const input[] = "123456789";
+ static size_t toknum;
+ if (! (toknum < sizeof input))
+ abort ();
+ return input[toknum++];
}
static void
static int
yylex (void)
{
+ static int called;
+ if (called++)
+ abort ();
return EOF;
}
[[%start-header {
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <assert.h>
#define YYINITDEPTH 10
AT_LOC.last_line = AT_LOC.last_column = AT_LOC.first_line + 9;
])[
+ if (! (0 <= c && c <= strlen (source)))
+ abort ();
if (source[c])
printf ("sending: '%c'", source[c]);
else
static int
yylex (void)
{
- static const char *input = "abcd";
- static int column = 1;
- yylval = *input++;
+ static char const input[] = "abcd";
+ static size_t toknum;
+ if (! (toknum < sizeof input))
+ abort ();
+ yylval = input[toknum++];
yylloc.first_line = yylloc.last_line = 1;
- yylloc.first_column = yylloc.last_column = column++;
+ yylloc.first_column = yylloc.last_column = toknum;
return yylval;
}
static int
yylex (void)
{
- static const char *input = "abcdef";
- return *input++;
+ static char const input[] = "abcdef";
+ static size_t toknum;
+ if (! (toknum < sizeof input))
+ abort ();
+ return input[toknum++];
}
static void
static int
yylex (void)
{
+ static int called;
+ if (called++)
+ abort ();
yylval = 'E';
yylloc.first_line = yylloc.last_line = 1;
yylloc.first_column = yylloc.last_column = 1;
%{
# include <stdio.h>
+# include <stdlib.h>
static void yyerror (const char *msg);
static int yylex (void);
# define USE(SYM)
static int
yylex (void)
{
- static const char *input = "abd";
- yylval = *input++;
+ static char const input[] = "abd";
+ static size_t toknum;
+ if (! (toknum < sizeof input))
+ abort ();
+ yylval = input[toknum++];
return yylval;
}
%{
# include <stdio.h>
+# include <stdlib.h>
static void yyerror (const char *msg);
static int yylex (void);
# define USE(SYM)
static int
yylex (void)
{
+ static int called;
+ if (called++)
+ abort ();
return 0;
}
%{
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#define YYERROR_VERBOSE 1
static void
}
/* The current argument. */
-static const char *input = NULL;
+static const char *input;
static int
yylex (void)
{
- /* No token stands for end of file. */
- if (input && *input)
- return *input++;
- else
- return 0;
+ static size_t toknum;
+ if (! (toknum <= strlen (input)))
+ abort ();
+ return input[toknum++];
}
%}
int
main (int argc, const char *argv[])
{
- if (argc > 1)
- input = argv[1];
+ input = argc <= 1 ? "" : argv[1];
return yyparse ();
}
]])
while (1)
{
+ if (feof (stdin))
+ abort ();
c = getchar ();
switch (c)
{
%{
#include <stdio.h>
+#include <stdlib.h>
#define YYSTYPE int
static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1);
{
for (;;)
{
- int ch = getchar ();
+ int ch;
+ if (feof (stdin))
+ abort ();
+ ch = getchar ();
if (ch == EOF)
return 0;
else if (ch == 'B' || ch == 'P')
%%
-FILE *input = NULL;
+FILE *input;
int
yylex (void)
{
char buf[50];
char *s;
+ if (feof (stdin))
+ abort ();
switch (fscanf (input, " %1[a-z,]", buf)) {
case 1:
return buf[0];
%{
#include <stdio.h>
+#include <stdlib.h>
#include <stdarg.h>
static int MergeRule (int x0, int x1);
int yylex (void)
{
char inp[3];
+ if (feof (stdin))
+ abort ();
if (fscanf (input, "%2s", inp) == EOF)
return 0;
switch (inp[0])
static int
yylex (void)
{
- static char const *input = "a";
- return *input++;
+ static char const input[] = "a";
+ static size_t toknum;
+ if (! (toknum < sizeof input))
+ abort ();
+ return input[toknum++];
}
int
static int
yylex (void)
{
- static char const *input = "a";
- return *input++;
+ static char const input[] = "a";
+ static size_t toknum;
+ if (! (toknum < sizeof input))
+ abort ();
+ return input[toknum++];
}
static void
static int
yylex (void)
{
- static char const *input = "a";
- return *input++;
+ static char const input[] = "a";
+ static size_t toknum;
+ if (! (toknum < sizeof input))
+ abort ();
+ return input[toknum++];
}
static void
lexIndex += 1;
switch (lexIndex)
{
+ default:
+ abort ();
case 1:
yylloc.first_column = 1;
yylloc.last_column = 9;
yylloc.first_column = 13;
yylloc.last_column = 17;
return T_PORT;
- default:
+ case 3:
return 0;
}
}
AT_DATA_GRAMMAR([glr-regr10.y],
[[
%{
+# include <stdlib.h>
# include <stdio.h>
static void yyerror (char const *);
static int yylex (void);
static int
yylex (void)
{
+ static int called;
+ if (called++)
+ abort ();
return 0;
}
static int
yylex (void)
{
- static char const *input = "a";
- return *input++;
+ static char const input[] = "a";
+ static size_t toknum;
+ if (! (toknum < sizeof input))
+ abort ();
+ return input[toknum++];
}
int
yylex (void)
{
static int const input[] = { PARENT_RHS_AFTER, 0 };
- static const int *inputp = input;
- if (*inputp == PARENT_RHS_AFTER)
+ static size_t toknum;
+ if (! (toknum < sizeof input / sizeof *input))
+ abort ();
+ if (input[toknum] == PARENT_RHS_AFTER)
parent_rhs_after_value = 1;
- return *inputp++;
+ return input[toknum++];
}
int
static int
yylex (void)
{
- static char const *input = "ab";
- static int i = 0;
+ static char const input[] = "ab";
+ static size_t toknum;
+ if (! (toknum < sizeof input))
+ abort ();
yylloc.first_line = yylloc.last_line = 1;
- yylloc.first_column = yylloc.last_column = i + 1;
- yylval.value = input[i] + 'A' - 'a';
- return input[i++];
+ yylloc.first_column = yylloc.last_column = toknum + 1;
+ yylval.value = input[toknum] + 'A' - 'a';
+ return input[toknum++];
}
static void
%union { char value; }
%{
+ #include <stdlib.h>
#include <stdio.h>
static void yyerror (char const *);
static int yylex (void);
static int
yylex (void)
{
- static char const *input = "abcdddd";
- static int i = 0;
+ static char const input[] = "abcdddd";
+ static size_t toknum;
+ if (! (toknum < sizeof input))
+ abort ();
yylloc.first_line = yylloc.last_line = 1;
- yylloc.first_column = yylloc.last_column = i + 1;
- yylval.value = input[i] + 'A' - 'a';
- return input[i++];
+ yylloc.first_column = yylloc.last_column = toknum + 1;
+ yylval.value = input[toknum] + 'A' - 'a';
+ return input[toknum++];
}
static void
static int
yylex (void)
{
+ static int called;
+ if (called++)
+ abort ();
return 0;
}
static int
yylex (void)
{
- static char const *input = "ab";
- if (*input == 'b')
+ static char const input[] = "ab";
+ static size_t toknum;
+ if (! (toknum < sizeof input))
+ abort ();
+ if (input[toknum] == 'b')
lookahead_value = 1;
- return *input++;
+ return input[toknum++];
}
int
yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
{
static char const input[] = "ab";
- static char const *inputp = input;
+ static size_t toknum;
+ if (! (toknum < sizeof input))
+ abort ();
lvalp->dummy = 0;
llocp->first_line = llocp->last_line = 2;
- llocp->first_column = inputp - input + 1;
+ llocp->first_column = toknum + 1;
llocp->last_column = llocp->first_column + 1;
- return *inputp++;
+ return input[toknum++];
}
int
[[%glr-parser
%{
+ #include <stdlib.h>
static void yyerror (char const *);
static int yylex ();
%}
static int
yylex ()
{
+ static int called;
+ if (called++)
+ abort ();
return 0;
}
]])
AT_CHECK([[bison -o glr-regr18.c glr-regr18.y]], 1, [],
-[glr-regr18.y:27.18-24: result type clash on merge function `merge': <type2> != <type1>
-glr-regr18.y:26.18-24: previous declaration
-glr-regr18.y:28.13-19: result type clash on merge function `merge': <type3> != <type2>
+[glr-regr18.y:28.18-24: result type clash on merge function `merge': <type2> != <type1>
glr-regr18.y:27.18-24: previous declaration
+glr-regr18.y:29.13-19: result type clash on merge function `merge': <type3> != <type2>
+glr-regr18.y:28.18-24: previous declaration
])
AT_CLEANUP
static int
yylex (void)
{
- static const char *input = "@<:@\1\2$@{@oline@__@&t@oline__\
+ static char const input[] = "@<:@\1\2$@{@oline@__@&t@oline__\
#output "; /* "
*/
- yylval = value_as_yystype (*input);
- return *input++;
+ static size_t toknum;
+ if (! (toknum < sizeof input))
+ abort ();
+ yylval = value_as_yystype (input[toknum]);
+ return input[toknum++];
}
static void
# Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
AT_DATA_GRAMMAR([input.y],
[%{
+#include <stdlib.h>
#include <stdio.h>
void yyerror (const char *s);
int yylex (void);
int
yylex (void)
{
+ static int called;
+ if (called++)
+ abort ();
return SPECIAL;
}
[%{
static int yylex (AT_LALR1_CC_IF([int *], [void]));
AT_LALR1_CC_IF([],
-[#include <stdio.h>
+[#include <stdlib.h>
+#include <stdio.h>
static void yyerror (const char *);])
%}
$1
static int
yylex (AT_LALR1_CC_IF([int *lval], [void]))
[{
- static int toknum = 0;
- static int tokens[] =
+ static int const tokens[] =
{
':', -1
};
+ static size_t toknum;
]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
+ if (! (toknum < sizeof tokens / sizeof *tokens))
+ abort ();
return tokens[toknum++];
}]
static int
yylex (AT_LALR1_CC_IF([int *lval], [void]))
[{
- static int toknum = 0;
- static int tokens[] =
+ static int const tokens[] =
{
1000, '+', '+', -1
};
+ static size_t toknum;
]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
+ if (! (toknum < sizeof tokens / sizeof *tokens))
+ abort ();
return tokens[toknum++];
}]
yylex (void)
{
static int counter = 1;
- if (counter > $max)
- return 0;
- else
- return counter++;
+ if (counter <= $max)
+ return counter++;
+ if (counter++ != $max + 1)
+ abort ();
+ return 0;
}
static void
static int return_token = 1;
static int counter = 1;
if (counter > $max)
- return 0;
+ {
+ if (counter++ != $max + 1)
+ abort ();
+ return 0;
+ }
if (return_token)
{
return_token = 0;
static int
yylex (void)
{
+ if (yylval < 0)
+ abort ();
if (yylval--)
return WAIT_FOR_EOF;
else