I’m having some trouble using pointers to structs in bison’s union definition, as I need memory positions of these elements but all of them seem to point to the same union position. Not sure If I’m using the right way. My code looks like:
main.h:
typedef struct _control *control;
struct _control { ... };
typedef struct _symbol *symbol;
struct _symbol { ... };
...
#include "parser.h"
parser.y
%{
#include "main.h"
%}
%union {
control ctrl;
symbol s_head;
symbol s_tail;
}
...
%%
...
%%
int main (int argc, char** argv) {
...
yylval.ctrl = malloc(sizeof(struct _control));
yylval.s_head = malloc(sizeof(struct _symbol));
yylval.s_tail = malloc(sizeof(struct _symbol));
// This will give me the same memory position
printf("%ld %ld %ld %ld\n",
yylval, yylval.ctrl,
yylval.s_head, yylval.s_tail);
...
}
Not sure if that’s the right way of doing it, but I just got my union elements mapped once I ‘converted’ them into a struct.
main.h
parser.y
Well, this just works.