开发者

Error: expected specifier-qualifier-list before ‘TR’

I have a problem defining my structure inside the union on Bison

I made a structure

typedef enum {Binary_Op,Uni_Op,Variable, Const} Tag_Type;

typedef struct tree
{
    Tag_Type Tag;
    union
    {
开发者_运维百科        struct
        {
            char op;
            struct tree *left, *right;
        }bin_op;

        struct
        {
            char op;
            struct tree *arg; /* negative or positive */
        }uni_op;

        char var;
        int const_val;
    }u;

}TREE_REC, *TR;




%}

%union
{

    int y_int;
    TR y_tree;
}

%type <y_tree> expr term factor assign
%token <y_int> CONST
%token <y_int> VAR



%%

but inside the union TR has an error. I don't understand why!! any help?


You need to define struct tree and TR in a header file that you #include before you #include "y.tab.h". The error message is telling you that you're trying to use TR before the compiler has seen a definition for it.


I'm a bit confused with your typedef struct tree {...} TREE_REC, *TR. I would have rather written :

typedef struct tree {...} TREE_REC; //Alias on struct tree 
typedef TREE_REC * TR; //Definition of the pointer to a struct tree

The , in your typedef is disturbing me.

Can you test my solution, or just clarify the syntax of your typedef?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜