Merge remote-tracking branch 'origin/maint'

* origin/maint:
  tests: do not output m4 set up.
  tests: use the generic yyerror function.
  tests: use assert instead of plain abort.
  tests: improve the generic yylex implementation.
  tests: generalize the compilation macros.
  tests: fix confusion between api.prefix and name-prefix.
  maint: gitignores.
  yacc: work around the ylwrap limitation.

Conflicts:
	NEWS
	tests/local.at
This commit is contained in:
Akim Demaille
2012-06-26 16:43:22 +02:00
16 changed files with 269 additions and 232 deletions

View File

@@ -174,11 +174,12 @@ AT_CLEANUP
## Printers and Destructors. ##
## -------------------------- ##
# _AT_CHECK_PRINTER_AND_DESTRUCTOR($1, $2, $3, $4, BISON-DIRECTIVE, UNION-FLAG)
# -----------------------------------------------------------------------------
# _AT_CHECK_PRINTER_AND_DESTRUCTOR($1, $2, $3, $4,
# BISON-DIRECTIVE, UNION-FLAG)
# -------------------------------------------------------------
m4_define([_AT_CHECK_PRINTER_AND_DESTRUCTOR],
[# Make sure complex $n work.
m4_if([$1$2$3], $[1]$[2]$[3], [],
m4_if([$1$2$3$4], $[1]$[2]$[3]$[4], [],
[m4_fatal([$0: Invalid arguments: $@])])dnl
# Be sure to pass all the %directives to this macro to have correct
@@ -193,13 +194,16 @@ AT_DATA_GRAMMAR([[input.y]],
#define YYINITDEPTH 10
#define YYMAXDEPTH 10
]AT_LALR1_CC_IF(
[#define RANGE(Location) (Location).begin.line, (Location).end.line],
[#define RANGE(Location) (Location).first_line, (Location).last_line])
[}
#define RANGE(Location) ]AT_LALR1_CC_IF([(Location).begin.line, (Location).end.line],
[(Location).first_line, (Location).last_line])[
$5]
m4_ifval([$6], [%union
/* Display the symbol type Symbol. */
#define V(Symbol, Value, Location, Sep) \
fprintf (stderr, #Symbol " (%d@%d-%d)" Sep, Value, RANGE(Location))
}
$5
]m4_ifval([$6], [%union
{
int ival;
}])
@@ -221,28 +225,28 @@ AT_LALR1_CC_IF([typedef yy::location YYLTYPE;])[
input line thing 'x' 'y'
%destructor
{ printf ("Freeing nterm input (%d@%d-%d)\n", $$, RANGE (@$)); }
{ fprintf (stderr, "Freeing nterm input (%d@%d-%d)\n", $$, RANGE (@$)); }
input
%destructor
{ printf ("Freeing nterm line (%d@%d-%d)\n", $$, RANGE (@$)); }
{ fprintf (stderr, "Freeing nterm line (%d@%d-%d)\n", $$, RANGE (@$)); }
line
%destructor
{ printf ("Freeing nterm thing (%d@%d-%d)\n", $$, RANGE (@$)); }
{ fprintf (stderr, "Freeing nterm thing (%d@%d-%d)\n", $$, RANGE (@$)); }
thing
%destructor
{ printf ("Freeing token 'x' (%d@%d-%d)\n", $$, RANGE (@$)); }
{ fprintf (stderr, "Freeing token 'x' (%d@%d-%d)\n", $$, RANGE (@$)); }
'x'
%destructor
{ printf ("Freeing token 'y' (%d@%d-%d)\n", $$, RANGE (@$)); }
{ fprintf (stderr, "Freeing token 'y' (%d@%d-%d)\n", $$, RANGE (@$)); }
'y'
%token END 0
%destructor
{ printf ("Freeing token END (%d@%d-%d)\n", $$, RANGE (@$)); }
{ fprintf (stderr, "Freeing token END (%d@%d-%d)\n", $$, RANGE (@$)); }
END
%%
@@ -257,14 +261,15 @@ input:
/* Nothing. */
{
$$ = 0;
printf ("input (%d@%d-%d): /* Nothing */\n", $$, RANGE (@$));
V(input, $$, @$, ": /* Nothing */\n");
}
| line input /* Right recursive to load the stack so that popping at
END can be exercised. */
{
$$ = 2;
printf ("input (%d@%d-%d): line (%d@%d-%d) input (%d@%d-%d)\n",
$$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2));
V(input, $$, @$, ": ");
V(line, $1, @1, " ");
V(input, $2, @2, "\n");
}
;
@@ -272,28 +277,36 @@ line:
thing thing thing ';'
{
$$ = $1;
printf ("line (%d@%d-%d): thing (%d@%d-%d) thing (%d@%d-%d) thing (%d@%d-%d) ';' (%d@%d-%d)\n",
$$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2),
$3, RANGE (@3), $4, RANGE (@4));
V(line, $$, @$, ": ");
V(thing, $1, @1, " ");
V(thing, $2, @2, " ");
V(thing, $3, @3, " ");
V(;, $4, @4, "\n");
}
| '(' thing thing ')'
{
$$ = $1;
printf ("line (%d@%d-%d): '(' (%d@%d-%d) thing (%d@%d-%d) thing (%d@%d-%d) ')' (%d@%d-%d)\n",
$$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2),
$3, RANGE (@3), $4, RANGE (@4));
V(line, $$, @$, ": ");
V('(', $1, @1, " ");
V(thing, $2, @2, " ");
V(thing, $3, @3, " ");
V(')', $4, @4, "\n");
}
| '(' thing ')'
{
$$ = $1;
printf ("line (%d@%d-%d): '(' (%d@%d-%d) thing (%d@%d-%d) ')' (%d@%d-%d)\n",
$$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2), $3, RANGE (@3));
V(line, $$, @$, ": ");
V('(', $1, @1, " ");
V(thing, $2, @2, " ");
V(')', $3, @3, "\n");
}
| '(' error ')'
{
$$ = -1;
printf ("line (%d@%d-%d): '(' (%d@%d-%d) error (@%d-%d) ')' (%d@%d-%d)\n",
$$, RANGE (@$), $1, RANGE (@1), RANGE (@2), $3, RANGE (@3));
V(line, $$, @$, ": ");
V('(', $1, @1, " ");
fprintf (stderr, "error (@%d-%d) ", RANGE(@2));
V(')', $3, @3, "\n");
}
;
@@ -301,14 +314,16 @@ thing:
'x'
{
$$ = $1;
printf ("thing (%d@%d-%d): 'x' (%d@%d-%d)\n",
$$, RANGE (@$), $1, RANGE (@1));
V(thing, $$, @$, ": ");
V('x', $1, @1, "\n");
}
;
%%
/* Alias to ARGV[1]. */
const char *source = YY_NULL;
]AT_YYERROR_DEFINE[
static
]AT_YYLEX_PROTOTYPE[
{
@@ -316,33 +331,18 @@ static
int c = ]AT_VAL[]m4_ifval([$6], [.ival])[ = counter++;
/* As in BASIC, line numbers go from 10 to 10. */
]AT_LALR1_CC_IF(
[ AT_LOC.begin.line = AT_LOC.begin.column = 10 * c;
AT_LOC.end.line = AT_LOC.end.column = AT_LOC.begin.line + 9;
],
[ AT_LOC.first_line = AT_LOC.first_column = 10 * c;
AT_LOC.last_line = AT_LOC.last_column = AT_LOC.first_line + 9;
])[
if (! (0 <= c && c <= strlen (source)))
abort ();
]AT_LOC_FIRST_LINE[ = ]AT_LOC_FIRST_COLUMN[ = 10 * c;
]AT_LOC_LAST_LINE[ = ]AT_LOC_LAST_COLUMN[ = ]AT_LOC_FIRST_LINE[ + 9;
assert (0 <= c && c <= strlen (source));
if (source[c])
printf ("sending: '%c'", source[c]);
fprintf (stderr, "sending: '%c'", source[c]);
else
printf ("sending: END");
printf (" (%d@%d-%d)\n", c, RANGE (]AT_LOC[));
fprintf (stderr, "sending: END");
fprintf (stderr, " (%d@%d-%d)\n", c, RANGE (]AT_LOC[));
return source[c];
}
]AT_LALR1_CC_IF(
[/* A C++ error reporting function. */
void
yy::parser::error (const location& l, const std::string& m)
{
printf ("%d-%d: %s\n", RANGE (l), m.c_str());
}
static bool yydebug;
[static bool yydebug;
int
yyparse ()
{
@@ -350,12 +350,7 @@ yyparse ()
parser.set_debug_level (yydebug);
return parser.parse ();
}
],
[static void
yyerror (const char *msg)
{
printf ("%d-%d: %s\n", RANGE (yylloc), msg);
}])[
])[
int
main (int argc, const char *argv[])
@@ -367,9 +362,9 @@ main (int argc, const char *argv[])
status = yyparse ();
switch (status)
{
case 0: printf ("Successful parse.\n"); break;
case 1: printf ("Parsing FAILED.\n"); break;
default: printf ("Parsing FAILED (status %d).\n", status); break;
case 0: fprintf (stderr, "Successful parse.\n"); break;
case 1: fprintf (stderr, "Parsing FAILED.\n"); break;
default: fprintf (stderr, "Parsing FAILED (status %d).\n", status); break;
}
return status;
}
@@ -383,7 +378,7 @@ AT_FULL_COMPILE([input])
# I.e., epsilon-reductions, as in "(x)" which ends by reducing
# an empty "line" nterm.
# FIXME: This location is not satisfying. Depend on the lookahead?
AT_PARSER_CHECK([./input '(x)'], 0,
AT_PARSER_CHECK([./input '(x)'], 0, [],
[[sending: '(' (0@0-9)
sending: 'x' (1@10-19)
thing (1@10-19): 'x' (1@10-19)
@@ -402,10 +397,10 @@ Successful parse.
# ---------------------------------
# '(y)' is an error, but can be recovered from. But what's the location
# of the error itself ('y'), and of the resulting reduction ('(error)').
AT_PARSER_CHECK([./input '(y)'], 0,
AT_PARSER_CHECK([./input '(y)'], 0, [],
[[sending: '(' (0@0-9)
sending: 'y' (1@10-19)
10-19: syntax error, unexpected 'y', expecting 'x'
10.10-19.18: syntax error, unexpected 'y', expecting 'x'
Freeing token 'y' (1@10-19)
sending: ')' (2@20-29)
line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29)
@@ -432,14 +427,14 @@ Successful parse.
# '(', 'x', ')',
# '(', 'x', ')',
# 'y'
AT_PARSER_CHECK([./input '(xxxxx)(x)(x)y'], 1,
AT_PARSER_CHECK([./input '(xxxxx)(x)(x)y'], 1, [],
[[sending: '(' (0@0-9)
sending: 'x' (1@10-19)
thing (1@10-19): 'x' (1@10-19)
sending: 'x' (2@20-29)
thing (2@20-29): 'x' (2@20-29)
sending: 'x' (3@30-39)
30-39: syntax error, unexpected 'x', expecting ')'
30.30-39.38: syntax error, unexpected 'x', expecting ')'
Freeing nterm thing (2@20-29)
Freeing nterm thing (1@10-19)
Freeing token 'x' (3@30-39)
@@ -464,7 +459,7 @@ input (0@129-129): /* Nothing */
input (2@100-129): line (10@100-129) input (0@129-129)
input (2@70-129): line (7@70-99) input (2@100-129)
input (2@0-129): line (-1@0-69) input (2@70-129)
130-139: syntax error, unexpected 'y', expecting END
130.130-139.138: syntax error, unexpected 'y', expecting END
Freeing nterm input (2@0-129)
Freeing token 'y' (13@130-139)
Parsing FAILED.
@@ -480,7 +475,7 @@ Parsing FAILED.
# '(', 'x', ')',
# '(', 'x', ')',
# 'x'
AT_PARSER_CHECK([./input '(x)(x)x'], 1,
AT_PARSER_CHECK([./input '(x)(x)x'], 1, [],
[[sending: '(' (0@0-9)
sending: 'x' (1@10-19)
thing (1@10-19): 'x' (1@10-19)
@@ -494,7 +489,7 @@ line (3@30-59): '(' (3@30-39) thing (4@40-49) ')' (5@50-59)
sending: 'x' (6@60-69)
thing (6@60-69): 'x' (6@60-69)
sending: END (7@70-79)
70-79: syntax error, unexpected END, expecting 'x'
70.70-79.78: syntax error, unexpected END, expecting 'x'
Freeing nterm thing (6@60-69)
Freeing nterm line (3@30-59)
Freeing nterm line (0@0-29)
@@ -508,7 +503,7 @@ Parsing FAILED.
# Upon stack overflow, all symbols on the stack should be destroyed.
# Only check for yacc.c.
AT_YACC_IF([
AT_PARSER_CHECK([./input '(x)(x)(x)(x)(x)(x)(x)'], 2,
AT_PARSER_CHECK([./input '(x)(x)(x)(x)(x)(x)(x)'], 2, [],
[[sending: '(' (0@0-9)
sending: 'x' (1@10-19)
thing (1@10-19): 'x' (1@10-19)
@@ -543,7 +538,7 @@ sending: '(' (18@180-189)
sending: 'x' (19@190-199)
thing (19@190-199): 'x' (19@190-199)
sending: ')' (20@200-209)
200-209: memory exhausted
200.200-209.208: memory exhausted
Freeing nterm thing (19@190-199)
Freeing nterm line (15@150-179)
Freeing nterm line (12@120-149)
@@ -1202,7 +1197,7 @@ AT_DATA_GRAMMAR([[input.y]],
%debug
]$1[ {
printf ("%d\n", @$.first_line);
fprintf (stderr, "%d\n", @$.first_line);
} ]m4_if($1, [%initial-action], [], [[start]])[
%%

View File

@@ -45,7 +45,7 @@ m4_define([_AT_DATA_CALC_Y],
[m4_fatal([$0: Invalid arguments: $@])])dnl
m4_pushdef([AT_CALC_MAIN],
[#include <stdlib.h> /* abort */
[#include <assert.h>
#if HAVE_UNISTD_H
# include <unistd.h>
#else
@@ -98,10 +98,8 @@ main (int argc, const char **argv)
status = ]AT_NAME_PREFIX[parse (]AT_PARAM_IF([[&result, &count]])[);
if (fclose (input))
perror ("fclose");
if (global_result != result)
abort ();
if (global_count != count)
abort ();
assert (global_result == result);
assert (global_count == count);
return status;
}
]])

View File

@@ -56,6 +56,7 @@ AT_DATA_GRAMMAR([input.y],
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define YYERROR_VERBOSE 1
]AT_YYERROR_DEFINE[
@@ -66,8 +67,7 @@ static int
yylex (void)
{
static size_t toknum;
if (! (toknum <= strlen (input)))
abort ();
assert (toknum <= strlen (input));
return input[toknum++];
}

View File

@@ -122,12 +122,12 @@ declarator : ID
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <assert.h>
int
main (int argc, char **argv)
{
if (argc != 2)
abort ();
assert (argc == 2);
if (!freopen (argv[1], "r", stdin))
return 3;
return yyparse ();
@@ -152,8 +152,7 @@ main (int argc, char **argv)
while (1)
{
if (feof (stdin))
abort ();
assert (!feof (stdin));
c = getchar ();
switch (c)
{
@@ -182,8 +181,7 @@ main (int argc, char **argv)
{
buffer[i++] = c;
colNum += 1;
if (i == sizeof buffer - 1)
abort ();
assert (i != sizeof buffer - 1);
c = getchar ();
}
while (isalnum (c) || c == '_');

View File

@@ -32,6 +32,7 @@ AT_DATA_GRAMMAR([glr-regr1.y],
%{
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#define YYSTYPE int
static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1);
@@ -80,8 +81,7 @@ yylex (void)
for (;;)
{
int ch;
if (feof (stdin))
abort ();
assert (!feof (stdin));
ch = getchar ();
if (ch == EOF)
return 0;
@@ -128,6 +128,7 @@ AT_DATA_GRAMMAR([glr-regr2a.y],
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
@@ -177,8 +178,7 @@ yylex (void)
{
char buf[50];
char *s;
if (feof (stdin))
abort ();
assert (!feof (stdin));
switch (fscanf (input, " %1[a-z,]", buf))
{
case 1:
@@ -190,8 +190,7 @@ yylex (void)
}
if (fscanf (input, "%49s", buf) != 1)
return 0;
if (sizeof buf - 1 <= strlen (buf))
abort ();
assert (strlen (buf) < sizeof buf - 1);
s = (char *) malloc (strlen (buf) + 1);
strcpy (s, buf);
yylval = s;
@@ -242,6 +241,7 @@ AT_DATA_GRAMMAR([glr-regr3.y],
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
static int MergeRule (int x0, int x1);
]AT_YYERROR_DECLARE[
@@ -302,8 +302,7 @@ int T[] = { T1, T2, T3, T4 };
int yylex (void)
{
char inp[3];
if (feof (stdin))
abort ();
assert (!feof (stdin));
if (fscanf (input, "%2s", inp) == EOF)
return 0;
switch (inp[0])
@@ -935,6 +934,7 @@ AT_DATA_GRAMMAR([glr-regr12.y],
%{
# include <stdlib.h>
# include <assert.h>
static int merge (YYSTYPE, YYSTYPE);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
@@ -1003,8 +1003,7 @@ yylex (void)
{
static int const input[] = { PARENT_RHS_AFTER, 0 };
static size_t toknum;
if (! (toknum < sizeof input / sizeof *input))
abort ();
assert (toknum < sizeof input / sizeof *input);
if (input[toknum] == PARENT_RHS_AFTER)
parent_rhs_after_value = 1;
return input[toknum++];
@@ -1064,6 +1063,7 @@ AT_DATA_GRAMMAR([glr-regr13.y],
%{
#include <stdio.h>
#include <assert.h>
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
static void print_lookahead (char const *);
@@ -1122,8 +1122,7 @@ yylex (void)
{
static char const input[] = "ab";
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
assert (toknum < sizeof input);
yylloc.first_line = yylloc.last_line = 1;
yylloc.first_column = yylloc.last_column = toknum + 1;
yylval.value = input[toknum] + 'A' - 'a';
@@ -1212,6 +1211,7 @@ AT_DATA_GRAMMAR([glr-regr14.y],
%{
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
static void print_lookahead (char const *);
@@ -1328,8 +1328,7 @@ yylex (void)
{
static char const input[] = "abcdddd";
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
assert (toknum < sizeof input);
yylloc.first_line = yylloc.last_line = 1;
yylloc.first_column = yylloc.last_column = toknum + 1;
yylval.value = input[toknum] + 'A' - 'a';
@@ -1492,6 +1491,7 @@ AT_DATA_GRAMMAR([glr-regr16.y],
%{
# include <stdlib.h>
# include <assert.h>
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
static int lookahead_value = 0;
@@ -1512,8 +1512,7 @@ yylex (void)
{
static char const input[] = "ab";
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
assert (toknum < sizeof input);
if (input[toknum] == 'b')
lookahead_value = 1;
return input[toknum++];
@@ -1551,7 +1550,8 @@ AT_CLEANUP
AT_SETUP([Uninitialized location when reporting ambiguity])
AT_BISON_OPTION_PUSHDEFS
AT_BISON_OPTION_PUSHDEFS([%glr-parser %locations %define api.pure])
AT_DATA_GRAMMAR([glr-regr17.y],
[[
%glr-parser
@@ -1562,8 +1562,8 @@ AT_DATA_GRAMMAR([glr-regr17.y],
%union { int dummy; }
%{
static void yyerror (YYLTYPE *, char const *);
static int yylex (YYSTYPE *, YYLTYPE *);
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
%}
%initial-action {
@@ -1593,21 +1593,15 @@ empty1: ;
empty2: ;
%%
# include <assert.h>
static void
yyerror (YYLTYPE *locp, char const *msg)
{
fprintf (stderr, "%d.%d-%d.%d: %s.\n", locp->first_line,
locp->first_column, locp->last_line, locp->last_column, msg);
}
]AT_YYERROR_DEFINE[
static int
yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
{
static char const input[] = "ab";
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
assert (toknum < sizeof input);
lvalp->dummy = 0;
llocp->first_line = llocp->last_line = 2;
llocp->first_column = toknum + 1;
@@ -1629,7 +1623,7 @@ AT_BISON_CHECK([[-o glr-regr17.c glr-regr17.y]], 0, [],
AT_COMPILE([glr-regr17])
AT_PARSER_CHECK([[./glr-regr17]], 0, [],
[1.1-2.3: syntax is ambiguous.
[1.1-2.2: syntax is ambiguous
])
AT_CLEANUP

View File

@@ -111,8 +111,8 @@ main (void)
# Link and execute, just to make sure everything is fine (and in
# particular, that MY_LLOC is indeed defined somewhere).
AT_COMPILE([caller.o], [-c caller.c])
AT_COMPILE([input.o], [-c input.c])
AT_COMPILE([caller.o])
AT_COMPILE([input.o])
AT_COMPILE([caller], [caller.o input.o])
AT_PARSER_CHECK([./caller])

View File

@@ -533,6 +533,7 @@ char apostrophe = '\'';
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
%}
/* %{ and %} can be here too. */
@@ -600,8 +601,7 @@ yylex (void)
#output "; /* "
*/
static size_t toknum;
if (! (toknum < sizeof input))
abort ();
assert (toknum < sizeof input);
yylval = value_as_yystype (input[toknum]);
return input[toknum++];
}
@@ -624,8 +624,8 @@ main (void)
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-d -v -o input.c input.y])
AT_COMPILE([input.o], [-c input.c])
AT_COMPILE([main.o], [-c main.c])
AT_COMPILE([input.o])
AT_COMPILE([main.o])
AT_COMPILE([input], [input.o main.o])
AT_PARSER_CHECK([./input], 0,
[[[@<:@],
@@ -745,7 +745,7 @@ input.y:18.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash
AT_BISON_CHECK([-o input.c input.y])
# Make sure we don't export silly token identifiers with periods or dashes.
AT_COMPILE([input.o], [-c input.c])
AT_COMPILE([input.o])
# Periods are genuine letters, they can start identifiers.

View File

@@ -90,7 +90,8 @@ m4_popdef([AT_LOC_LAST_COLUMN])])
# AT_BISON_OPTION_PUSHDEFS([BISON-OPTIONS])
# -----------------------------------------
m4_define([AT_BISON_OPTION_PUSHDEFS],
[_AT_BISON_OPTION_PUSHDEFS($[1], $[2], [$1])])
[m4_divert_text([KILL],
[_AT_BISON_OPTION_PUSHDEFS($[1], $[2], [$1])])])
# _AT_BISON_OPTION_PUSHDEFS($1, $2, [BISON-OPTIONS])
@@ -137,16 +138,16 @@ m4_pushdef([AT_PURE_AND_LOC_IF],
m4_pushdef([AT_GLR_OR_PARAM_IF],
[m4_bmatch([$3], [%glr-parser\|%parse-param], [$1], [$2])])
m4_pushdef([AT_NAME_PREFIX],
[m4_bmatch([$3], [%name-prefix ".*"],
[m4_bregexp([$3], [%name-prefix "\([^""]*\)"], [\1])],
[yy])])
m4_pushdef([AT_API_PREFIX],
[m4_bmatch([$3], [\(%define api\.prefix\|%name-prefix\) ".*"],
[m4_bregexp([$3], [\(%define api\.prefix\|%name-prefix\) "\([^""]*\)"], [\2])],
[yy])])
m4_pushdef([AT_TOKEN_PREFIX],
[m4_bmatch([$3], [%define api.tokens.prefix ".*"],
[m4_bregexp([$3], [%define api.tokens.prefix "\(.*\)"], [\1])])])
m4_pushdef([AT_API_prefix],
[m4_bmatch([$3], [%define api\.prefix ".*"],
[m4_bregexp([$3], [%define api\.prefix "\([^""]*\)"], [\1])],
[yy])])
# yyerror receives the location if %location & %pure & (%glr or %parse-param).
m4_pushdef([AT_YYERROR_ARG_LOC_IF],
[AT_GLR_OR_PARAM_IF([AT_PURE_AND_LOC_IF([$1], [$2])],
@@ -165,19 +166,27 @@ m4_pushdef([AT_PURE_LEX_IF],
[AT_PURE_IF([$1],
[AT_SKEL_CC_IF([$1], [$2])])])
m4_pushdef([AT_YYSTYPE],
[AT_SKEL_CC_IF([AT_NAME_PREFIX[::parser::semantic_type]],
[[YYSTYPE]])])
m4_pushdef([AT_YYLTYPE],
[AT_SKEL_CC_IF([AT_NAME_PREFIX[::parser::location_type]],
[[YYLTYPE]])])
AT_PURE_LEX_IF(
[m4_pushdef([AT_LOC], [(*llocp)])
m4_pushdef([AT_VAL], [(*lvalp)])
m4_pushdef([AT_YYLEX_FORMALS],
[YYSTYPE *lvalp[]AT_LOCATION_IF([, YYLTYPE *llocp])])
[AT_YYSTYPE *lvalp[]AT_LOCATION_IF([, AT_YYLTYPE *llocp])])
m4_pushdef([AT_YYLEX_ARGS],
[lvalp[]AT_LOCATION_IF([, llocp])])
m4_pushdef([AT_USE_LEX_ARGS],
[(void) lvalp;AT_LOCATION_IF([(void) llocp])])
m4_pushdef([AT_YYLEX_PRE_FORMALS],
[AT_YYLEX_FORMALS, ])
[AT_YYLEX_FORMALS, ])
m4_pushdef([AT_YYLEX_PRE_ARGS],
[AT_YYLEX_ARGS, ])
[AT_YYLEX_ARGS, ])
],
[m4_pushdef([AT_LOC], [[(]AT_NAME_PREFIX[lloc)]])
m4_pushdef([AT_VAL], [[(]AT_NAME_PREFIX[lval)]])
@@ -204,17 +213,20 @@ AT_GLR_IF([AT_KEYWORDS([glr])])
# AT_BISON_OPTION_POPDEFS
# -----------------------
m4_define([AT_BISON_OPTION_POPDEFS],
[m4_divert_text([KILL],
[m4_popdef([AT_YYLEX_PRE_ARGS])
m4_popdef([AT_YYLEX_PRE_FORMALS])
m4_popdef([AT_USE_LEX_ARGS])
m4_popdef([AT_YYLEX_ARGS])
m4_popdef([AT_YYLEX_FORMALS])
m4_popdef([AT_YYLTYPE])
m4_popdef([AT_YYSTYPE])
m4_popdef([AT_VAL])
m4_popdef([AT_LOC])
m4_popdef([AT_PURE_LEX_IF])
m4_popdef([AT_YYERROR_SEES_LOC_IF])
m4_popdef([AT_YYERROR_ARG_LOC_IF])
m4_popdef([AT_API_PREFIX])
m4_popdef([AT_API_prefix])
m4_popdef([AT_NAME_PREFIX])
m4_popdef([AT_GLR_OR_PARAM_IF])
m4_popdef([AT_PURE_AND_LOC_IF])
@@ -230,7 +242,7 @@ m4_popdef([AT_SKEL_JAVA_IF])
m4_popdef([AT_GLR_CC_IF])
m4_popdef([AT_LALR1_CC_IF])
m4_popdef([AT_DEFINES_IF])
AT_LOC_POPDEF
AT_LOC_POPDEF])dnl
])# AT_BISON_OPTION_POPDEFS
@@ -287,7 +299,7 @@ $2])
# AT_YYLEX_DEFINE(INPUT-STRING, [ACTION])
# ---------------------------------------
m4_define([AT_YYLEX_PROTOTYPE],
[int AT_API_PREFIX[]lex (]AT_YYLEX_FORMALS[)[]dnl
[int AT_NAME_PREFIX[]lex (]AT_YYLEX_FORMALS[)[]dnl
])
m4_define([AT_YYLEX_DECLARE_EXTERN],
@@ -299,19 +311,19 @@ m4_define([AT_YYLEX_DECLARE],
])
m4_define([AT_YYLEX_DEFINE],
[[#include <stdlib.h> /* abort */
[[#include <assert.h>
static
]AT_YYLEX_PROTOTYPE[
{
static char const input[] = "$1";
static size_t toknum = 0;
int res;
if (! (toknum < sizeof input))
abort ();
]AT_USE_LEX_ARGS[;
assert (toknum < sizeof input);
res = input[toknum++];
]$2;[]AT_LOCATION_IF([[
]AT_API_PREFIX[lloc.first_line = ]AT_API_PREFIX[lloc.last_line = 1;
]AT_API_PREFIX[lloc.first_column = ]AT_API_PREFIX[lloc.last_column = toknum;]])[
]$2[;]AT_LOCATION_IF([[
]AT_LOC_FIRST_LINE[ = ]AT_LOC_LAST_LINE[ = 1;
]AT_LOC_FIRST_COLUMN[ = ]AT_LOC_LAST_COLUMN[ = toknum;]])[
return res;
}]dnl
])
@@ -329,7 +341,7 @@ m4_define([AT_YYERROR_FORMALS],
m4_define([AT_YYERROR_PROTOTYPE],
[m4_case(AT_LANG,
[c], [[void ]AT_API_PREFIX[error (]AT_YYERROR_FORMALS[)]])[]dnl
[c], [[void ]AT_NAME_PREFIX[error (]AT_YYERROR_FORMALS[)]])[]dnl
])
m4_define([AT_YYERROR_DECLARE_EXTERN],
@@ -540,21 +552,37 @@ m4_define([AT_QUELL_VALGRIND],
# AT_COMPILE(OUTPUT, [SOURCES = OUTPUT.c])
# ----------------------------------------
# Compile SOURCES into OUTPUT. If OUTPUT does not contain '.',
# assume that we are linking too; this is a hack.
# Compile SOURCES into OUTPUT.
#
# If OUTPUT does not contain '.', assume that we are linking too,
# otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
# with trailing .o removed, and ".c" appended.
m4_define([AT_COMPILE],
[AT_CHECK([$CC $CFLAGS $CPPFLAGS m4_bmatch([$1], [[.]], [], [$LDFLAGS ])-o $1 m4_default([$2], [$1.c])[]m4_bmatch([$1], [[.]], [], [ $LIBS])],
[AT_CHECK(m4_join([ ],
[$CC $CFLAGS $CPPFLAGS],
[m4_bmatch([$1], [[.]], [-c], [$LDFLAGS])],
[-o $1],
[m4_default([$2], [m4_bpatsubst([$1], [\.o$]).c])],
[m4_bmatch([$1], [[.]], [], [$LIBS])]),
0, [ignore], [ignore])])
# AT_COMPILE_CXX(OUTPUT, [SOURCES = OUTPUT.cc])
# --------------------------------------------
# Compile SOURCES into OUTPUT. If OUTPUT does not contain '.',
# assume that we are linking too; this is a hack.
# If the C++ compiler does not work, ignore the test.
# ---------------------------------------------
# Compile SOURCES into OUTPUT. If the C++ compiler does not work,
# ignore the test.
#
# If OUTPUT does not contain '.', assume that we are linking too,
# otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
# with trailing .o removed, and ".cc" appended.
m4_define([AT_COMPILE_CXX],
[AT_KEYWORDS(c++)
AT_CHECK([$BISON_CXX_WORKS], 0, ignore, ignore)
AT_CHECK([$CXX $CXXFLAGS $CPPFLAGS m4_bmatch([$1], [[.]], [], [$LDFLAGS ])-o $1 m4_default([$2], [$1.cc])[]m4_bmatch([$1], [[.]], [], [ $LIBS])],
AT_CHECK(m4_join([ ],
[$CXX $CXXFLAGS $CPPFLAGS],
[m4_bmatch([$1], [[.]], [-c], [$LDFLAGS])],
[-o $1],
[m4_default([$2], [m4_bpatsubst([$1], [\.o$]).cc])],
[m4_bmatch([$1], [[.]], [], [$LIBS])]),
0, [ignore], [ignore])])
# AT_JAVA_COMPILE(SOURCES)
@@ -569,6 +597,11 @@ AT_CHECK([[$SHELL ../../../javacomp.sh ]$1],
# AT_LANG_COMPILE(OUTPUT, [SOURCES = OUTPUT.c]
# --------------------------------------------
# Compile SOURCES into OUTPUT. Skip if compiler does not work.
#
# If OUTPUT does not contain '.', assume that we are linking too,
# otherwise pass "-c"; this is a hack. The default SOURCES is OUTPUT
# with trailing .o removed, and ".c"/".cc" appended.
m4_define([AT_LANG_COMPILE],
[m4_case(AT_LANG,
[c], [AT_COMPILE([$1], [$2])],

View File

@@ -162,10 +162,8 @@ int main (int argc, const char **argv)
}
status = yyparse ();
fclose (input);
if (global_result != result)
abort ();
if (global_count != count)
abort ();
assert (global_result == result);
assert (global_count == count);
return status;
}
]])

View File

@@ -41,7 +41,7 @@ program: 'x';
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c input.y])
AT_COMPILE([input.o], [-c input.c])
AT_COMPILE([input.o])
AT_COMPILE([input.o], [-DYYDEBUG -c input.c])
AT_CLEANUP
@@ -71,7 +71,7 @@ program: { $$ = ""; };
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c input.y])
AT_COMPILE([input.o], [-c input.c])
AT_COMPILE([input.o])
AT_CLEANUP
@@ -111,7 +111,7 @@ exp: MY_TOKEN;
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-y -o input.c input.y])
AT_COMPILE([input.o], [-c input.c])
AT_COMPILE([input.o])
AT_CLEANUP
@@ -156,7 +156,7 @@ exp: MY_TOKEN;
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c input.y])
AT_COMPILE([input.o], [-c input.c])
AT_COMPILE([input.o])
AT_CLEANUP
@@ -527,7 +527,7 @@ exp:
AT_BISON_OPTION_POPDEFS
AT_BISON_CHECK([-o input.c input.y])
AT_COMPILE([input.o], [-c input.c])
AT_COMPILE([input.o])
AT_CLEANUP
@@ -901,6 +901,7 @@ yyparse ()
}
])
#include <assert.h>
static int
yylex (AT_LALR1_CC_IF([int *lval], [void]))
[{
@@ -910,8 +911,7 @@ yylex (AT_LALR1_CC_IF([int *lval], [void]))
};
static size_t toknum;
]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
if (! (toknum < sizeof tokens / sizeof *tokens))
abort ();
assert (toknum < sizeof tokens / sizeof *tokens);
return tokens[toknum++];
}]
@@ -986,6 +986,7 @@ yyparse ()
}
])[
#include <assert.h>
static int
yylex (]AT_LALR1_CC_IF([int *lval], [void])[)
{
@@ -995,8 +996,7 @@ yylex (]AT_LALR1_CC_IF([int *lval], [void])[)
};
static size_t toknum;
]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
if (! (toknum < sizeof tokens / sizeof *tokens))
abort ();
assert (toknum < sizeof tokens / sizeof *tokens);
return tokens[toknum++];
}

View File

@@ -56,6 +56,7 @@ print <<EOF;
%{
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#define MAX $max
]AT_YYLEX_DECLARE[
]AT_YYERROR_DECLARE[
@@ -77,8 +78,8 @@ for my $size (1 .. $max)
print <<EOF;
%%
input:
exp { if (\@S|@1 != 0) abort (); \$\$ = \@S|@1; }
| input exp { if (\@S|@2 != \@S|@1 + 1) abort (); \$\$ = \@S|@2; }
exp { assert (\@S|@1 == 0); \$\$ = \@S|@1; }
| input exp { assert (\@S|@2 == \@S|@1 + 1); \$\$ = \@S|@2; }
;
exp:
@@ -192,6 +193,7 @@ print
print <<\EOF;
%%
#include <assert.h>
]AT_YYERROR_DEFINE[
static int
yylex (void)
@@ -199,8 +201,7 @@ yylex (void)
static int counter = 1;
if (counter <= MAX)
return counter++;
if (counter++ != MAX + 1)
abort ();
assert (counter++ == MAX + 1);
return 0;
}
@@ -328,8 +329,7 @@ yylex (void)
static int counter = 1;
if (counter > MAX)
{
if (counter++ != MAX + 1)
abort ();
assert (counter++ == MAX + 1);
return 0;
}
if (return_token)
@@ -401,11 +401,11 @@ AT_DATA([input.y],
exp: WAIT_FOR_EOF exp | ;
%%
]AT_YYERROR_DEFINE[
#include <assert.h>
static int
yylex (void)
{
if (yylval < 0)
abort ();
assert (0 <= yylval);
if (yylval--)
return WAIT_FOR_EOF;
else
@@ -417,13 +417,12 @@ main (int argc, const char **argv)
{
char *endp;
YYSTYPE yylval_init;
if (argc != 2)
abort ();
assert (argc == 2);
yylval_init = strtol (argv[1], &endp, 10);
if (! (argv[1] != endp
&& 0 <= yylval_init && yylval_init <= INT_MAX
&& errno != ERANGE))
abort ();
assert (argv[1] != endp);
assert (0 <= yylval_init);
assert (yylval_init <= INT_MAX);
assert (errno != ERANGE);
yydebug = 1;
{
int count;
@@ -438,8 +437,7 @@ main (int argc, const char **argv)
[[ new_status = yypull_parse (ps);
]],
[[ new_status = yyparse ();
]])[ if (count > 0 && new_status != status)
abort ();
]])[ assert (0 <= count || new_status == status);
status = new_status;
}
]m4_bmatch([$2], [%push-],