Reputation: 55539
In my yacc file I have the following code:
fun_declaration : type_specifier ID '(' params ')'
{$2->type = "function";
$2->args = params; }
params : param_list | VOID ;
Do you see what I'm trying to do?
args is a string. I'm trying to put the function parameters into this string. How to do that?
Upvotes: 0
Views: 147
Reputation: 2960
You need to have 'params' return the string you want in $$, much like ID is returning a pointer to some struct with 'type' and 'args' fields. This means you'll need a %type declaration for it saying which element of the %union to use.
There are lots of books and online tutorials for how to use yacc like this.
Upvotes: 1
Reputation: 152867
Just refer to with $n
it as you would refer to any semantic value component in the rule. Something like this:
$2->args = strdup($4);
Upvotes: 0