tags:

views:

443

answers:

2

I am trying to include a struct as part of the union with Bison, but I get an error on the 'struct node args' in %union:

parser.y:17: error: field ‘args’ has incomplete type

The Code:

struct node {
    char * val;
    struct node * next;
};

%}

%union {
    char * string;
    struct node args;
}

%token <string> CD WORD PWD EXIT

%type <args> arg_list

Anyone know what I am doing wrong?

A: 

Do you have a %{ above struct node {?

wrang-wrang
Yup, that is just the relevant snippet.
Kyle Brandt
+3  A: 

It comes down to the lame y.tab.h output you get.

You need to fix this by ensuring that "struct node" is defined before you include y.tab.h anywhere.

To do this create a file node.h with the struct definition.

Then include node.h before y.tab.h in your parser.l file, parser.y file as well as any c files you have which include y.tab.h. This is a little annoying.

Alternatively you could change "struct node args" to "struct node* args" since you would not need to know the full type until you go to use it somewhere. Not sure if this would fit with your code.

Either one should work.

tim