Hi,
Has anyone besides me noticed that $n with n zero or negative always
triggers a "$n ... has no declared type" error when a %union is used?
Cosider this grammar, which is a slightly modified example from the manual:
%union {
int val;
}
%token <val> NUM
%start foo
%%
foo
: expr bar '+' expr
| expr bar '-' expr
bar: /* empty */
{ previous_expr = $0; } /* <-- "test.y:16.27-28: $0 of `bar' has no
declared type" */
;
expr
: NUM;
%%
The error persists even if you insert "%type <val> expr". I know this can
be worked around by using "$<val>0", but I think this error shouldn't
appear at all.
In case anyone is interested, here's the piece of code that issues the
error.
File scan-gram.l:
...
static inline bool
handle_action_dollar (char *text, location loc)
{
const char *type_name = NULL;
...
/* Get the type name if explicit. */
if (*cp == '<')
{
type_name = ++cp;
while (*cp != '>')
++cp;
*cp = '\0';
++cp;
}
if (*cp == '$')
{
...
}
else
{
long int num = strtol (cp, NULL, 10);
if (1 - INT_MAX + rule_length <= num && num <= rule_length)
{
int n = num;
...
if (!type_name && 0 < n)
//!!!
//!!! Because n <= 0 in our case, type_name is never retrieved.
//!!!
type_name = symbol_list_n_type_name_get (current_rule, loc, n);
//!!!
//!!! Thus, unless the type name is referred to explicitly, zero
//!!! or negative semantic contexts can't coexist with %union's.
//!!!
if (!type_name && typed)
complain_at (loc, _("$%d of `%s' has no declared type"),
n, current_rule->sym->tag);
...
}
...
}
That was an extract from version 2.3 code, but this piece doesn't seem to
have changed much in version 2.4.1.
Best,
Sandy
_______________________________________________
help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison