mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-13 22:33:03 +00:00
* data/m4sugar/m4sugar.m4 (m4_map): Recognize when the list of
arguments is really empty, not only equal to `[]'. * src/symtab.h, src/symtab.c (symbol_t): `destructor' is a new member. (symbol_destructor_set): New. * src/output.c (symbol_destructors_output): New. * src/reader.h (brace_code_t, current_braced_code): New. * src/scan-gram.l (BRACED_CODE): Use it to branch on... (handle_dollar): Rename as... (handle_action_dollar): this. (handle_destructor_dollar): New. * src/parse-gram.y (PERCENT_DESTRUCTOR): New. (grammar_declaration): Use it. * data/bison.simple (yystos): Is always defined. (yydestructor): New. * tests/actions.at (Destructors): New. * tests/calc.at (_AT_CHECK_CALC_ERROR): Don't rely on egrep.
This commit is contained in:
132
tests/actions.at
132
tests/actions.at
@@ -88,8 +88,6 @@ AT_CLEANUP
|
||||
|
||||
AT_SETUP([Exotic Dollars])
|
||||
|
||||
# Make sure complex $n work.
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%{
|
||||
# include <stdio.h>
|
||||
@@ -152,3 +150,133 @@ AT_CHECK([./input], 0,
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
|
||||
## ------------- ##
|
||||
## Destructors. ##
|
||||
## ------------- ##
|
||||
|
||||
AT_SETUP([Destructors])
|
||||
|
||||
# Make sure complex $n work.
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%{
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define YYERROR_VERBOSE 1
|
||||
#define YYDEBUG 1
|
||||
/* #define YYPRINT yyprint */
|
||||
|
||||
static int yylex (void);
|
||||
static void yyerror (const char *msg);
|
||||
static void yyprint (FILE *out, int toknum, int tokval);
|
||||
%}
|
||||
|
||||
%union
|
||||
{
|
||||
int ival;
|
||||
}
|
||||
%type <ival> thing 'x'
|
||||
%destructor { printf ("Freeing thing %d\n", $$); } thing
|
||||
%destructor { printf ("Freeing 'x' %d\n", $$); } 'x'
|
||||
|
||||
%%
|
||||
input:
|
||||
/* Nothing. */
|
||||
| input line
|
||||
;
|
||||
|
||||
line:
|
||||
thing thing thing ';'
|
||||
{ printf ("input: thing(%d) thing(%d) thing(%d) ';'\n", $1, $2, $3); }
|
||||
| thing thing ';'
|
||||
{ printf ("input: thing(%d) thing(%d) ';'\n", $1, $2); }
|
||||
| thing ';'
|
||||
{ printf ("input: thing(%d) ';'\n", $1); }
|
||||
| error ';'
|
||||
{ printf ("input: error ';'\n"); }
|
||||
;
|
||||
|
||||
thing:
|
||||
'x' { printf ("thing: 'x' (%d)\n", $1); $$ = $1; }
|
||||
;
|
||||
%%
|
||||
static int
|
||||
yylex (void)
|
||||
{
|
||||
static const int input[] =
|
||||
{
|
||||
'x', 'x', 'x', 'x', 'x', 'x', ';',
|
||||
'x', 'x', ';',
|
||||
'x', ';',
|
||||
'x', 'y', ';'
|
||||
};
|
||||
static int counter = 0;
|
||||
|
||||
if (counter < (sizeof(input) / sizeof (input[0])))
|
||||
{
|
||||
yylval.ival = counter;
|
||||
return input[counter++];
|
||||
}
|
||||
else
|
||||
return EOF;
|
||||
}
|
||||
|
||||
static void
|
||||
yyerror (const char *msg)
|
||||
{
|
||||
fprintf (stdout, "%s\n", msg);
|
||||
}
|
||||
|
||||
static void
|
||||
yyprint (FILE *out, int toknum, int tokval)
|
||||
{
|
||||
if (0 < toknum && toknum < 256)
|
||||
fprintf (out, " = %d", tokval);
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
yydebug = !!getenv ("YYDEBUG");
|
||||
if (yyparse ())
|
||||
{
|
||||
fprintf (stdout, "Parsing FAILED.\n");
|
||||
exit (1);
|
||||
}
|
||||
fprintf (stdout, "Successful parse.\n");
|
||||
return 0;
|
||||
}
|
||||
]])
|
||||
|
||||
AT_CHECK([bison input.y -d -v -o input.c])
|
||||
AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore])
|
||||
AT_CHECK([./input], 0,
|
||||
[[thing: 'x' (0)
|
||||
thing: 'x' (1)
|
||||
thing: 'x' (2)
|
||||
parse error, unexpected 'x', expecting ';'
|
||||
Freeing thing 2
|
||||
Freeing thing 1
|
||||
Freeing thing 0
|
||||
Freeing 'x' 3
|
||||
Freeing 'x' 4
|
||||
Freeing 'x' 5
|
||||
input: error ';'
|
||||
thing: 'x' (7)
|
||||
thing: 'x' (8)
|
||||
input: thing(7) thing(8) ';'
|
||||
thing: 'x' (10)
|
||||
input: thing(10) ';'
|
||||
thing: 'x' (12)
|
||||
parse error, unexpected $undefined., expecting 'x' or ';'
|
||||
Freeing thing 12
|
||||
input: error ';'
|
||||
Successful parse.
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
@@ -354,7 +354,16 @@ m4_bmatch([$1], [--debug],
|
||||
# Normalize the observed and expected error messages, depending upon the
|
||||
# options.
|
||||
# 1. Remove the traces from observed.
|
||||
egrep -v '^((Start|Enter|Read|Reduc|Shift)ing|state|Error:|Next|Discarding) ' stderr >at-stderr
|
||||
sed '/^Starting/d
|
||||
/^Entering/d
|
||||
/^Reading/d
|
||||
/^Reducing/d
|
||||
/^Shifting/d
|
||||
/^state/d
|
||||
/^Error:/d
|
||||
/^Next/d
|
||||
/^Discarding/d
|
||||
/^yydestructor:/d' stderr >at-stderr
|
||||
mv at-stderr stderr
|
||||
# 2. Create the reference error message.
|
||||
AT_DATA([[expout]],
|
||||
@@ -406,18 +415,18 @@ _AT_CHECK_CALC([$1],
|
||||
(2^2)^3 = 64], [486])
|
||||
|
||||
# Some parse errors.
|
||||
_AT_CHECK_CALC_ERROR([$1], [0 0], [11],
|
||||
_AT_CHECK_CALC_ERROR([$1], [0 0], [12],
|
||||
[1.3-1.4: parse error, unexpected "number"])
|
||||
_AT_CHECK_CALC_ERROR([$1], [1//2], [15],
|
||||
_AT_CHECK_CALC_ERROR([$1], [1//2], [17],
|
||||
[1.3-1.4: parse error, unexpected '/', expecting "number" or '-' or '('])
|
||||
_AT_CHECK_CALC_ERROR([$1], [error], [4],
|
||||
[1.1-1.2: parse error, unexpected $undefined., expecting "number" or '-' or '\n' or '('])
|
||||
_AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3], [22],
|
||||
_AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3], [25],
|
||||
[1.7-1.8: parse error, unexpected '='])
|
||||
_AT_CHECK_CALC_ERROR([$1],
|
||||
[
|
||||
+1],
|
||||
[14],
|
||||
[15],
|
||||
[2.1-2.2: parse error, unexpected '+'])
|
||||
# Exercise error messages with EOF: work on an empty file.
|
||||
_AT_CHECK_CALC_ERROR([$1],
|
||||
@@ -430,7 +439,7 @@ _AT_CHECK_CALC_ERROR([$1],
|
||||
# associated to `error'.
|
||||
_AT_CHECK_CALC_ERROR([$1],
|
||||
[(1 ++ 2) + (0 0) = 1],
|
||||
[82],
|
||||
[91],
|
||||
[1.5-1.6: parse error, unexpected '+', expecting "number" or '-' or '('
|
||||
1.15-1.16: parse error, unexpected "number"
|
||||
calc: error: 0 != 1])
|
||||
|
||||
Reference in New Issue
Block a user