Includi struct in %union def con Bison/Yacc

Includi struct in %union def con Bison/Yacc


Sto cercando di includere uno struct come parte dell'unione con Bison, ma ottengo un errore su 'struct node args' in %union:


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

Il codice:


struct node {
char * val;
struct node * next;
};
%}
%union {
char * string;
struct node args;
}
%token <string> CD WORD PWD EXIT
%type <args> arg_list

Qualcuno sa cosa sbaglio?


Risposte:


Ancora meglio, usa la direttiva %code con l'opzione "richiede", ovvero:


%code requires {
struct node {
char * val;
struct node * next;
};
}
%union {
char * string;
struct node args;
}

Ciò includerà il codice nel blocco "richiede" nel file tab.h così come il file sorgente del parser.


Dalla documentazione:http://www.gnu.org/software/bison/manual/html_node/Decl-Summary.html#Decl-Summary