Reputation: 418
yacc doesn't seem to like when my tokens are of a type that I defined.
At the top of my grammar (.y
) file in a %{ ... %}
block, I include a header file that defines the following structure:
typedef struct _spim_register {
spim_register_type type; /* This is a simple enumeration, already defined */
int number;
} spim_register;
Before my list of rules, I have:
%token AREG
...
%union {
struct _spim_register reg;
}
...
%type <reg> register AREG
I get
error: field ‘reg’ has incomplete type
at the line in the %union
clause while trying to compile the code produced by bison. In my %union
statement, trying to declare reg by writing spim_register reg;
gives the error:
unknown type name ‘spim_register’
It seems like there's something special about %union { ... }
, because I'm able to use the data structures from my header file in the actions for the rules.
Upvotes: 9
Views: 4867
Reputation: 583
I met the same problem. Because my *.l
file was like this:
#include "y.tab.h"
#include "FP.h"
I rewrote it like this:
#include "FP.h"
#include "y.tab.h"
It works.
Upvotes: 8