tags:

views:

31

answers:

2

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?

A: 

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);
laalto
When I try that I get the error "`fun_declaration' has no declared type."
Phenom
A: 

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.

Chris Dodd