Question

So, I'm having problems with my parser.y with a compiler that I'm building. The error is saying I don't have a member inside of a union or structure, which it is. Here is the error code I've received:

parser.y:123: error: request for member ‘funcName’ in something not a structure or union

Then with the code that is inside my parser.y file:

%union {
    int val;
    char *funcName;
}

%token <funcName> ID

And here is where I'm trying to use the union in my parser.y file:

f_def: FUNCTION ID '(' arg_list ')' ':' type '{' stat_list '}' 
{create_function_info_item(&headFunctionInfo, func_arg_list_count(), $2.funcName);}
Was it helpful?

Solution

The tokens have the type of whichever union member you assigned to them with the %token declaration - not the union type itself. So $2 has type char* and you don't need the .funcName - it already holds the value of the funcName member.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top