开发者

yacc - field has incomplete type

开发者 https://www.devze.com 2023-04-10 02:33 出处:网络
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:

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: 开发者_StackOverflow中文版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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号