First set of tests: use the `calc' example from the documentation.

* src/bison.s1 (yyparse): Condition the code using `yytname' which
is defined only when YYDEBUG is.
* m4/atconfig.m4 (AT_CONFIG): Adjust to Autoconf 2.13.
* src/files.c (tryopen, tryclose): Formatting changes.
Move to the top and be static.
* src/reader.c (read_signed_integer): Likewise.
* tests/calc.m4: New file.
* Makefile.am, suite.m4: Adjust.
* m4/atconfig.m4: Set BISON_SIMPLE and BISON_HAIRY.
This commit is contained in:
Akim Demaille
2000-09-18 13:18:26 +00:00
parent e79137accc
commit 0d533154e4
17 changed files with 615 additions and 393 deletions

View File

@@ -151,7 +151,7 @@ int yynerrs;
#endif /* not YYPURE */
#if YYDEBUG != 0
#if YYDEBUG
int yydebug; /* nonzero means print parse trace */
/* [The following comment makes no sense to me. Could someone
@@ -470,16 +470,20 @@ yynewstate:
{
yychar1 = YYTRANSLATE(yychar);
#if YYDEBUG
/* We have to keep this `#if YYDEBUG', since we use variables
which are defined only if `YYDEBUG' is set. */
if (yydebug)
{
fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
/* Give the individual parser a way to print the precise meaning
of a token, for further debugging info. */
/* Give the individual parser a way to print the precise
meaning of a token, for further debugging info. */
# ifdef YYPRINT
YYPRINT (stderr, yychar, yylval);
# endif
fprintf (stderr, ")\n");
}
#endif
}
yyn += yychar1;
@@ -509,9 +513,10 @@ yynewstate:
YYACCEPT;
/* Shift the lookahead token. */
#if YYDEBUG
if (yydebug)
fprintf (stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
#endif
/* Discard the token being shifted unless it is eof. */
if (yychar != YYEOF)
@@ -678,11 +683,11 @@ yyerrlab1: /* here on error raised explicitly by an action */
/* 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
yychar = YYEMPTY;
}

View File

@@ -151,7 +151,7 @@ int yynerrs;
#endif /* not YYPURE */
#if YYDEBUG != 0
#if YYDEBUG
int yydebug; /* nonzero means print parse trace */
/* [The following comment makes no sense to me. Could someone
@@ -470,16 +470,20 @@ yynewstate:
{
yychar1 = YYTRANSLATE(yychar);
#if YYDEBUG
/* We have to keep this `#if YYDEBUG', since we use variables
which are defined only if `YYDEBUG' is set. */
if (yydebug)
{
fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
/* Give the individual parser a way to print the precise meaning
of a token, for further debugging info. */
/* Give the individual parser a way to print the precise
meaning of a token, for further debugging info. */
# ifdef YYPRINT
YYPRINT (stderr, yychar, yylval);
# endif
fprintf (stderr, ")\n");
}
#endif
}
yyn += yychar1;
@@ -509,9 +513,10 @@ yynewstate:
YYACCEPT;
/* Shift the lookahead token. */
#if YYDEBUG
if (yydebug)
fprintf (stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
#endif
/* Discard the token being shifted unless it is eof. */
if (yychar != YYEOF)
@@ -678,11 +683,11 @@ yyerrlab1: /* here on error raised explicitly by an action */
/* 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
yychar = YYEMPTY;
}

View File

@@ -361,8 +361,10 @@ openfiles (void)
/* open the output files needed only for the semantic parser.
This is done when %semantic_parser is seen in the declarations section. */
/*--------------------------------------------------------------------.
| Open the output files needed only for the semantic parser. This |
| is done when %semantic_parser is seen in the declarations section. |
`--------------------------------------------------------------------*/
void
open_extra_files (void)

View File

@@ -117,7 +117,6 @@ static void record_rule_line PARAMS((void));
static void packsymbols PARAMS((void));
static void output_token_defines PARAMS((FILE *));
static void packgram PARAMS((void));
static int read_signed_integer PARAMS((FILE *));
#if 0
static int get_type PARAMS((void));
@@ -146,6 +145,10 @@ static bucket *undeftoken;
/* Nonzero if any action or guard uses the @n construct. */
static int yylsp_needed;
/*===================\
| Low level lexing. |
\===================*/
static void
skip_to_char (int target)
@@ -157,15 +160,45 @@ skip_to_char (int target)
complain (_(" Skipping to next %c"), target);
do
c = skip_white_space();
c = skip_white_space ();
while (c != target && c != EOF);
if (c != EOF)
ungetc(c, finput);
ungetc (c, finput);
}
/* Dump the string from FIN to FOUT. MATCH is the delimiter of
the string (either ' or "). */
/*---------------------------------------------------------.
| Read a signed integer from STREAM and return its value. |
`---------------------------------------------------------*/
static inline int
read_signed_integer (FILE *stream)
{
register int c = getc (stream);
register int sign = 1;
register int n = 0;
if (c == '-')
{
c = getc (stream);
sign = -1;
}
while (isdigit (c))
{
n = 10 * n + (c - '0');
c = getc (stream);
}
ungetc (c, stream);
return sign * n;
}
/*-------------------------------------------------------------------.
| Dump the string from FINPUT to FOUTPUT. MATCH is the delimiter of |
| the string (either ' or "). |
`-------------------------------------------------------------------*/
static inline void
copy_string (FILE *fin, FILE *fout, int match)
@@ -350,7 +383,7 @@ reader (void)
/* Write closing delimiters for actions and guards. */
output_trailers ();
if (yylsp_needed)
fprintf ("#define YYLSP_NEEDED\n\n", ftable);
fputs ("#define YYLSP_NEEDED\n\n", ftable);
/* Assign the symbols their symbol numbers. Write #defines for the
token symbols into FDEFINES if requested. */
packsymbols ();
@@ -1950,29 +1983,3 @@ packgram (void)
ritem[itemno] = 0;
}
/* Read a signed integer from STREAM and return its value. */
static int
read_signed_integer (FILE *stream)
{
register int c = getc(stream);
register int sign = 1;
register int n;
if (c == '-')
{
c = getc(stream);
sign = -1;
}
n = 0;
while (isdigit(c))
{
n = 10*n + (c - '0');
c = getc(stream);
}
ungetc(c, stream);
return n * sign;
}