* src/reader.c (grammar_current_rule_check): Also check that $$

is used.
Take the rule to check as argument, hence rename as...
(grammar_rule_check): this.
* src/reader.h, src/reader.c (grammar_rule_begin, grammar_rule_end):
Rename as...
(grammar_rule_begin, grammar_rule_end): these, for consistency.
(grammar_midrule_action, grammar_symbol_append): Now static.
* tests/torture.at (input): Don't rely on the default action
being always performed.
* tests/calc.at: "Set" $$ even when the action is "cut" with
YYERROR or other.
* tests/actions.at (Exotic Dollars): Instead of using unused
values, check that the warning is issued.
This commit is contained in:
Akim Demaille
2005-12-27 17:50:00 +00:00
parent f8e1c9e55b
commit 8f3596a633
11 changed files with 217 additions and 193 deletions

View File

@@ -30,13 +30,13 @@ AT_SETUP([Mid-rule actions])
# action.
AT_DATA_GRAMMAR([[input.y]],
[[%{
[[%error-verbose
%debug
%{
# include <stdio.h>
# include <stdlib.h>
static void yyerror (const char *msg);
static int yylex (void);
# define YYDEBUG 1
# define YYERROR_VERBOSE 1
%}
%%
exp: { putchar ('0'); }
@@ -91,13 +91,13 @@ AT_CLEANUP
AT_SETUP([Exotic Dollars])
AT_DATA_GRAMMAR([[input.y]],
[[%{
[[%error-verbose
%debug
%{
# include <stdio.h>
# include <stdlib.h>
static void yyerror (const char *msg);
static int yylex (void);
# define YYDEBUG 1
# define YYERROR_VERBOSE 1
# define USE(Var)
%}
@@ -107,13 +107,12 @@ AT_DATA_GRAMMAR([[input.y]],
};
%type <val> a_1 a_2 a_5
sum_of_the_five_previous_values
exp sum_of_the_five_previous_values
%%
exp: a_1 a_2 { $<val>$ = 3; } { $<val>$ = $<val>3 + 1; } a_5
sum_of_the_five_previous_values
{
USE (($1, $2, $5));
printf ("%d\n", $6);
}
;
@@ -147,7 +146,11 @@ main (void)
}
]])
AT_CHECK([bison -d -v -o input.c input.y])
AT_CHECK([bison -d -v -o input.c input.y], 0, [],
[input.y:30.6-34.5: warning: unused value: $1
input.y:30.6-34.5: warning: unused value: $2
input.y:30.6-34.5: warning: unused value: $5
])
AT_COMPILE([input])
AT_PARSER_CHECK([./input], 0,
[[15

View File

@@ -129,15 +129,15 @@ exp:
| exp '^' exp { $$ = power ($1, $3); }
| '(' exp ')' { $$ = $2; }
| '(' error ')' { $$ = 1111; }
| '!' { YYERROR; }
| '-' error { YYERROR; }
| '!' { $$ = 0; YYERROR; }
| '-' error { $$ = 0; YYERROR; }
;
%%
/* The input. */
/* The input. */
static FILE *input;
]AT_LALR1_CC_IF(
[/* A C++ error reporting function. */
[/* A C++ error reporting function. */
void
yy::parser::error (const location& l, const std::string& m)
{

View File

@@ -50,13 +50,12 @@ my $max = $ARGV[0] || 10;
print <<EOF;
]AT_DATA_GRAMMAR_PROLOGUE[
%error-verbose
%debug
%{
#include <stdio.h>
#include <stdlib.h>
#define YYERROR_VERBOSE 1
#define YYDEBUG 1
static int yylex (void);
static void yyerror (const char *msg);
%}
@@ -166,24 +165,25 @@ my $max = $ARGV[0] || 10;
print <<EOF;
]AT_DATA_GRAMMAR_PROLOGUE[
%error-verbose
%debug
%{
#include <stdio.h>
#include <stdlib.h>
#define YYERROR_VERBOSE 1
#define YYDEBUG 1
static int yylex (void);
static void yyerror (const char *msg);
%}
EOF
%token
EOF
for my $size (1 .. $max)
{
print "%token t$size $size \"$size\"\n";
print " t$size $size \"$size\"\n";
};
print <<EOF;
%%
EOF
@@ -258,7 +258,7 @@ AT_CLEANUP
# AT_DATA_LOOK_AHEAD_TOKENS_GRAMMAR(FILE-NAME, SIZE)
# -------------------------------------------
# --------------------------------------------------
# Create FILE-NAME, containing a self checking parser for a grammar
# requiring SIZE look-ahead tokens.
m4_define([AT_DATA_LOOK_AHEAD_TOKENS_GRAMMAR],
@@ -270,12 +270,12 @@ use Text::Wrap;
my $max = $ARGV[0] || 10;
print <<EOF;
%error-verbose
%debug
%{
#include <stdio.h>
#include <stdlib.h>
#define YYERROR_VERBOSE 1
#define YYDEBUG 1
# include <stdio.h>
# include <stdlib.h>
# include <assert.h>
static int yylex (void);
static void yyerror (const char *msg);
@@ -295,25 +295,26 @@ print
map { "n$_" } (1 .. $max)),
"\n";
print "%token\n";
for my $count (1 .. $max)
{
print "%token t$count $count \"$count\"\n";
print " t$count $count \"$count\"\n";
};
print <<EOF;
%%
input:
exp { if (\@S|@1 != 1) abort (); \$\$ = \@S|@1; }
| input exp { if (\@S|@2 != \@S|@1 + 1) abort (); \$\$ = \@S|@2; }
exp { assert (\@S|@1 == 1); \$\$ = \@S|@1; }
| input exp { assert (\@S|@2 == \@S|@1 + 1); \$\$ = \@S|@2; }
;
exp:
n1 "1" { if (\@S|@1 != 1) abort (); }
n1 "1" { assert (\@S|@1 == 1); \@S|@\@S|@ = \@S|@1; }
EOF
for my $count (2 .. $max)
{
print "| n$count \"$count\" { if (\@S|@1 != $count) abort (); }\n";
print "| n$count \"$count\" { assert (\@S|@1 == $count); \@S|@\@S|@ = \@S|@1; }\n";
};
print ";\n";