Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yacc - field has incomplete type

Tags:

c

yacc

bison

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.

like image 938
ArIck Avatar asked Oct 03 '11 19:10

ArIck


2 Answers

It would help if my #includes were in the right order...

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

like image 65
ArIck Avatar answered Oct 22 '22 04:10

ArIck


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

include "y.tab.h"

include "FP.h"

then, I rewrote it like this:

include "FP.h"

include "y.tab.h"

It works. Thank you very much. @ArIck

like image 39
flyrain Avatar answered Oct 22 '22 04:10

flyrain