summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
71da9ee)
the latter demonstrates a flaw in the handling of non debugging
parsers introduced by myself on 2000-03-16: `#define yydebug 0'
was used in order to simplify:
#if YYDEBUG
if (yydebug)
{
...
}
#endif
into
if (yydebug)
{
...
}
unfortunately this leads to a CPP conflict when
`--name-prefix=foo' is used since it produces `#define yydebug
foodebug'.
* src/bison.s1 [!YYDEBUG]: Do not define yydebug.
(YYDPRINTF): New macro.
Spread its use.
* tests/calc.m4 (AT_CHECK_CALC): Do require a title, build it from
the bison options.
Also test `--verbose', `--defines' and `--name-prefix'.
+2000-10-02 Akim Demaille <akim@epita.fr>
+
+ Test also `--verbose', `--defines' and `--name-prefix'. Testing
+ the latter demonstrates a flaw in the handling of non debugging
+ parsers introduced by myself on 2000-03-16: `#define yydebug 0'
+ was used in order to simplify:
+
+ #if YYDEBUG
+ if (yydebug)
+ {
+ ...
+ }
+ #endif
+
+ into
+
+ if (yydebug)
+ {
+ ...
+ }
+
+ unfortunately this leads to a CPP conflict when
+ `--name-prefix=foo' is used since it produces `#define yydebug
+ foodebug'.
+
+ * src/bison.s1 [!YYDEBUG]: Do not define yydebug.
+ (YYDPRINTF): New macro.
+ Spread its use.
+ * tests/calc.m4 (AT_CHECK_CALC): Do require a title, build it from
+ the bison options.
+ Also test `--verbose', `--defines' and `--name-prefix'.
+
+
2000-10-02 Akim Demaille <akim@epita.fr>
Improve the readability of the produced parsers.
2000-10-02 Akim Demaille <akim@epita.fr>
Improve the readability of the produced parsers.
int yynerrs;
#endif /* !YYPURE */
int yynerrs;
#endif /* !YYPURE */
+/* Enable debugging if requested. */
-int yydebug; /* nonzero means print parse trace */
-
- /* [The following comment makes no sense to me. Could someone
- clarify it? --akim] Since this is uninitialized, it does not
- stop multiple parsers from coexisting. */
-#else
- /* To avoid crippling this file with `#if YYDEBUG', define `yydebug'
- as `0', so that the `if (yydebug)' be removed as dead code. */
-# define yydebug 0
-#endif
-
-/* YYINITDEPTH indicates the initial size of the parser's stacks */
-
+# define YYDPRINTF(Args) \
+do { \
+ if (yydebug) \
+ fprintf Args; \
+} while (0)
+/* Nonzero means print parse trace. [The following comment makes no
+ sense to me. Could someone clarify it? --akim] Since this is
+ uninitialized, it does not stop multiple parsers from coexisting.
+ */
+int yydebug;
+#else /* !YYDEBUG */
+# define YYDPRINTF(Args)
+#endif /* !YYDEBUG */
+
+/* YYINITDEPTH -- initial size of the parser's stacks. */
#ifndef YYINITDEPTH
# define YYINITDEPTH 200
#endif
#ifndef YYINITDEPTH
# define YYINITDEPTH 200
#endif
-/* YYMAXDEPTH is the maximum size the stacks can grow to
- (effective only if the built-in stack extension method is used). */
-
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+ if the built-in stack extension method is used). */
#if YYMAXDEPTH == 0
# undef YYMAXDEPTH
#endif
#if YYMAXDEPTH == 0
# undef YYMAXDEPTH
#endif
of type size_t, but it can handle unsigned int. */
#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
of type size_t, but it can handle unsigned int. */
#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
-# define __yy_memcpy(To,From,Count) __builtin_memcpy (To,From,Count)
+# define __yy_memcpy(To, From, Count) __builtin_memcpy (To, From, Count)
#else /* not GNU C or C++ */
# ifndef __cplusplus
#else /* not GNU C or C++ */
# ifndef __cplusplus
- if (yydebug)
- fprintf (stderr, "Starting parse\n");
+ YYDPRINTF ((stderr, "Starting parse\n"));
yystate = 0;
yyerrstatus = 0;
yystate = 0;
yyerrstatus = 0;
yylsp = yyls + size - 1;
#endif
yylsp = yyls + size - 1;
#endif
- if (yydebug)
- fprintf (stderr, "Stack size increased to %d\n", yystacksize);
+ YYDPRINTF ((stderr, "Stack size increased to %d\n", yystacksize));
if (yyssp >= yyss + yystacksize - 1)
YYABORT;
}
if (yyssp >= yyss + yystacksize - 1)
YYABORT;
}
- if (yydebug)
- fprintf (stderr, "Entering state %d\n", yystate);
+ YYDPRINTF ((stderr, "Entering state %d\n", yystate));
- if (yydebug)
- fprintf (stderr, "Reading a token: ");
+ YYDPRINTF ((stderr, "Reading a token: "));
yychar1 = 0;
yychar = YYEOF; /* Don't call YYLEX any more */
yychar1 = 0;
yychar = YYEOF; /* Don't call YYLEX any more */
- if (yydebug)
- fprintf (stderr, "Now at end of input.\n");
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
YYACCEPT;
/* Shift the lookahead token. */
YYACCEPT;
/* Shift the lookahead token. */
-#if YYDEBUG
- if (yydebug)
- fprintf (stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
-#endif
+ YYDPRINTF ((stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]));
/* Discard the token being shifted unless it is eof. */
if (yychar != YYEOF)
/* Discard the token being shifted unless it is eof. */
if (yychar != YYEOF)
if (yydebug)
{
short *ssp1 = yyss - 1;
if (yydebug)
{
short *ssp1 = yyss - 1;
fprintf (stderr, " %d", *++ssp1);
fprintf (stderr, "\n");
}
fprintf (stderr, " %d", *++ssp1);
fprintf (stderr, "\n");
}
*++yyvsp = yyval;
#ifdef YYLSP_NEEDED
*++yyvsp = yyval;
#ifdef YYLSP_NEEDED
/* return failure if at end of input */
if (yychar == YYEOF)
YYABORT;
/* return failure if at end of input */
if (yychar == YYEOF)
YYABORT;
-#if YYDEBUG
- if (yydebug)
- fprintf (stderr, "Discarding token %d (%s).\n",
- yychar, yytname[yychar1]);
-#endif
+ YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
+ yychar, yytname[yychar1]));
if (yydebug)
{
short *ssp1 = yyss - 1;
if (yydebug)
{
short *ssp1 = yyss - 1;
fprintf (stderr, " %d", *++ssp1);
fprintf (stderr, "\n");
}
fprintf (stderr, " %d", *++ssp1);
fprintf (stderr, "\n");
}
/*--------------.
| yyerrhandle. |
/*--------------.
| yyerrhandle. |
if (yyn == YYFINAL)
YYACCEPT;
if (yyn == YYFINAL)
YYACCEPT;
- if (yydebug)
- fprintf (stderr, "Shifting error token, ");
+ YYDPRINTF ((stderr, "Shifting error token, "));
*++yyvsp = yylval;
#ifdef YYLSP_NEEDED
*++yyvsp = yylval;
#ifdef YYLSP_NEEDED
int yynerrs;
#endif /* !YYPURE */
int yynerrs;
#endif /* !YYPURE */
+/* Enable debugging if requested. */
-int yydebug; /* nonzero means print parse trace */
-
- /* [The following comment makes no sense to me. Could someone
- clarify it? --akim] Since this is uninitialized, it does not
- stop multiple parsers from coexisting. */
-#else
- /* To avoid crippling this file with `#if YYDEBUG', define `yydebug'
- as `0', so that the `if (yydebug)' be removed as dead code. */
-# define yydebug 0
-#endif
-
-/* YYINITDEPTH indicates the initial size of the parser's stacks */
-
+# define YYDPRINTF(Args) \
+do { \
+ if (yydebug) \
+ fprintf Args; \
+} while (0)
+/* Nonzero means print parse trace. [The following comment makes no
+ sense to me. Could someone clarify it? --akim] Since this is
+ uninitialized, it does not stop multiple parsers from coexisting.
+ */
+int yydebug;
+#else /* !YYDEBUG */
+# define YYDPRINTF(Args)
+#endif /* !YYDEBUG */
+
+/* YYINITDEPTH -- initial size of the parser's stacks. */
#ifndef YYINITDEPTH
# define YYINITDEPTH 200
#endif
#ifndef YYINITDEPTH
# define YYINITDEPTH 200
#endif
-/* YYMAXDEPTH is the maximum size the stacks can grow to
- (effective only if the built-in stack extension method is used). */
-
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+ if the built-in stack extension method is used). */
#if YYMAXDEPTH == 0
# undef YYMAXDEPTH
#endif
#if YYMAXDEPTH == 0
# undef YYMAXDEPTH
#endif
of type size_t, but it can handle unsigned int. */
#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
of type size_t, but it can handle unsigned int. */
#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
-# define __yy_memcpy(To,From,Count) __builtin_memcpy (To,From,Count)
+# define __yy_memcpy(To, From, Count) __builtin_memcpy (To, From, Count)
#else /* not GNU C or C++ */
# ifndef __cplusplus
#else /* not GNU C or C++ */
# ifndef __cplusplus
- if (yydebug)
- fprintf (stderr, "Starting parse\n");
+ YYDPRINTF ((stderr, "Starting parse\n"));
yystate = 0;
yyerrstatus = 0;
yystate = 0;
yyerrstatus = 0;
yylsp = yyls + size - 1;
#endif
yylsp = yyls + size - 1;
#endif
- if (yydebug)
- fprintf (stderr, "Stack size increased to %d\n", yystacksize);
+ YYDPRINTF ((stderr, "Stack size increased to %d\n", yystacksize));
if (yyssp >= yyss + yystacksize - 1)
YYABORT;
}
if (yyssp >= yyss + yystacksize - 1)
YYABORT;
}
- if (yydebug)
- fprintf (stderr, "Entering state %d\n", yystate);
+ YYDPRINTF ((stderr, "Entering state %d\n", yystate));
- if (yydebug)
- fprintf (stderr, "Reading a token: ");
+ YYDPRINTF ((stderr, "Reading a token: "));
yychar1 = 0;
yychar = YYEOF; /* Don't call YYLEX any more */
yychar1 = 0;
yychar = YYEOF; /* Don't call YYLEX any more */
- if (yydebug)
- fprintf (stderr, "Now at end of input.\n");
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
YYACCEPT;
/* Shift the lookahead token. */
YYACCEPT;
/* Shift the lookahead token. */
-#if YYDEBUG
- if (yydebug)
- fprintf (stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
-#endif
+ YYDPRINTF ((stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]));
/* Discard the token being shifted unless it is eof. */
if (yychar != YYEOF)
/* Discard the token being shifted unless it is eof. */
if (yychar != YYEOF)
if (yydebug)
{
short *ssp1 = yyss - 1;
if (yydebug)
{
short *ssp1 = yyss - 1;
fprintf (stderr, " %d", *++ssp1);
fprintf (stderr, "\n");
}
fprintf (stderr, " %d", *++ssp1);
fprintf (stderr, "\n");
}
*++yyvsp = yyval;
#ifdef YYLSP_NEEDED
*++yyvsp = yyval;
#ifdef YYLSP_NEEDED
/* return failure if at end of input */
if (yychar == YYEOF)
YYABORT;
/* return failure if at end of input */
if (yychar == YYEOF)
YYABORT;
-#if YYDEBUG
- if (yydebug)
- fprintf (stderr, "Discarding token %d (%s).\n",
- yychar, yytname[yychar1]);
-#endif
+ YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
+ yychar, yytname[yychar1]));
if (yydebug)
{
short *ssp1 = yyss - 1;
if (yydebug)
{
short *ssp1 = yyss - 1;
fprintf (stderr, " %d", *++ssp1);
fprintf (stderr, "\n");
}
fprintf (stderr, " %d", *++ssp1);
fprintf (stderr, "\n");
}
/*--------------.
| yyerrhandle. |
/*--------------.
| yyerrhandle. |
if (yyn == YYFINAL)
YYACCEPT;
if (yyn == YYFINAL)
YYACCEPT;
- if (yydebug)
- fprintf (stderr, "Shifting error token, ");
+ YYDPRINTF ((stderr, "Shifting error token, "));
*++yyvsp = yylval;
#ifdef YYLSP_NEEDED
*++yyvsp = yylval;
#ifdef YYLSP_NEEDED
static int power (int base, int exponent);
static int read_signed_integer (FILE *stream);
static void yyerror (const char *s);
static int power (int base, int exponent);
static int read_signed_integer (FILE *stream);
static void yyerror (const char *s);
+static int yylex (void);
extern void perror (const char *s);
%}
extern void perror (const char *s);
%}
| blanks and tabs, returns 0 for EOF. |
`---------------------------------------------------------------*/
| blanks and tabs, returns 0 for EOF. |
`---------------------------------------------------------------*/
+static int
+yylex (void)
[AT_CHECK([echo "$1" | calc], 0, [$2], [$3])])
[AT_CHECK([echo "$1" | calc], 0, [$2], [$3])])
-# AT_CHECK_CALC(TITLE, [BISON-OPTIONS], [PARSER-EXPECTED-STDERR])
-# ---------------------------------------------------------------
-# Start a testing chunk named TITLE which compiles `calc' grammar with
+# AT_CHECK_CALC([BISON-OPTIONS], [PARSER-EXPECTED-STDERR])
+# --------------------------------------------------------
+# Start a testing chunk which compiles `calc' grammar with
# BISON-OPTIONS, and performs several tests over the parser.
AT_DEFINE([AT_CHECK_CALC],
[# We use integers to avoid dependencies upon the precision of doubles.
# BISON-OPTIONS, and performs several tests over the parser.
AT_DEFINE([AT_CHECK_CALC],
[# We use integers to avoid dependencies upon the precision of doubles.
+AT_SETUP([Calculator $1])
AT_DATA_CALC_Y
# Specify the output files to avoid problems on different file systems.
AT_DATA_CALC_Y
# Specify the output files to avoid problems on different file systems.
-AT_CHECK([bison calc.y -o calc.c $2], 0, [], [])
+AT_CHECK([bison calc.y -o calc.c $1], 0, [], [])
AT_CHECK([$CC $CFLAGS calc.c -o calc], 0, [], [])
# Test the priorities.
AT_CHECK([$CC $CFLAGS calc.c -o calc], 0, [], [])
# Test the priorities.
-_AT_CHECK_CALC([1 + 2 * 3], [7], [$3])
-_AT_CHECK_CALC([1 + 2 * -3], [-5], [$3])
+_AT_CHECK_CALC([1 + 2 * 3], [7], [$2])
+_AT_CHECK_CALC([1 + 2 * -3], [-5], [$2])
-_AT_CHECK_CALC([-1^2], [-1], [$3])
-_AT_CHECK_CALC([(-1)^2], [1], [$3])
+_AT_CHECK_CALC([-1^2], [-1], [$2])
+_AT_CHECK_CALC([(-1)^2], [1], [$2])
-_AT_CHECK_CALC([---1], [-1], [$3])
+_AT_CHECK_CALC([---1], [-1], [$2])
-_AT_CHECK_CALC([1 - 2 - 3], [-4], [$3])
-_AT_CHECK_CALC([1 - (2 - 3)], [2], [$3])
+_AT_CHECK_CALC([1 - 2 - 3], [-4], [$2])
+_AT_CHECK_CALC([1 - (2 - 3)], [2], [$2])
-_AT_CHECK_CALC([2^2^3], [256], [$3])
-_AT_CHECK_CALC([(2^2)^3], [64], [$3])
+_AT_CHECK_CALC([2^2^3], [256], [$2])
+_AT_CHECK_CALC([(2^2)^3], [64], [$2])
+AT_CLEANUP(calc calc.c calc.h calc.output)
-AT_CHECK_CALC([Simple calculator])
-
-AT_CHECK_CALC([Simple Yacc compatible calculator],
- [--yacc])
-
-AT_CHECK_CALC([Simple calculator whose tokens are numbered from 3],
- [--raw])
+AT_CHECK_CALC()
+# This one is very suspicious. The test fails, but it might be normal.
+AT_CHECK_CALC([--raw])
-AT_CHECK_CALC([Simple debugging calculator],
- [--debug], ignore)
+AT_CHECK_CALC([--defines])
+AT_CHECK_CALC([--name-prefix=calc])
+AT_CHECK_CALC([--verbose])
+AT_CHECK_CALC([--yacc])
+AT_CHECK_CALC([--defines --name-prefix=calc --verbose --yacc])
-AT_CHECK_CALC([Simple Yacc compatible debugging calculator],
- [--debug --yacc], ignore)
+# When --debug, a lot of data is sent to STDERR, we can't test it.
+AT_CHECK_CALC([--debug], ignore)
+AT_CHECK_CALC([--debug --defines --name-prefix=calc --verbose --yacc], ignore)