You cannot do it this way: you have to define your %union
in such a way that all the symbols that have multiple "attributes" have a struct
to define all these "attributes". Something like
%union
{
struct
{
int type;
char *id;
} type_id;
}
%type <type_id> tIDENT
and use $1.type
or $1.id
etc.
Note however that I very much doubt that you're doing the right thing. Chances are high that you will need an AST (Abstract Syntax Tree). You should look for information about that.