Field yacc - has an incomplete type

yacc doesn't seem to like it when my tokens are of the type I defined.

At the top of my grammar file ( .y ) in the %{ ... %} 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 is of incomplete type

in the line in the %union clause when trying to compile the code generated by the bison. In my statement, %union , trying to declare reg by writing spim_register reg; , an error message is displayed:

 unknown type name 'spim_register' 

There seems to be something special in %union { ... } because I can use the data structures from my header file in the actions for the rules.

+7
source share
2 answers

This would help if my #includes were in the correct order ...

The answer was, as hinted by user786653, here . I needed to include a header file that defines my custom structure before , including the .tab.h file in the .l file.

+9
source

I met the same problem. Because my .l file looks like this:

include "y.tab.h"

enable "FP.h"

then I rewrote it as follows:

enable "FP.h"

include "y.tab.h"

It works. Many thanks. @ArIck

+5
source

All Articles