Reputation: 65
Bison compiler returns me the error $0 of 'routine' has no declared type. I'm trying to print a message declaring a fonction, so I have to print the opening brace before printing the body of the function. I read the doc, and I found a solution coming from that page :Bison 3.0.4: Actions so I tried to apply it to my problem :
fun_decl :
type routine fun {end_fonction();};
routine :
{declare_fonction($0);};
I also specified a type for the non terminal 'type' :
%type <type_object> type
So I don't understand where does my mistake come from.
NB : When I simply associate an empty instruction on the non terminal routine, bison also returns a mistake : "rule useless in parser due to conflicts". Does it mean I can't have multiple empty rules ?
Upvotes: 1
Views: 970
Reputation: 310980
You haven't declared the type of routine
:
%type <type_object> routine
Upvotes: 0
Reputation: 65
I just found the solution to my problem, I had to specify the type of $0, to let Bison know the size to take in the stack. In my case :
routine :
{declare_fonction($<type_object>0);};
Upvotes: 1
Reputation: 241861
You can just use a mid-rule action:
fun_decl :
type {declare_fonction($1);} fun {end_fonction();};
This has the advantage that bison knows the type of $1
. It never tries to figure out the type of $0
because it is not possible in the general case.
As discussed in the manual, mid-rule actions can create shift-reduce conflicts. "Marker" (empty) non-terminals, like your routine
, can also create shift-reduce conflicts, and roughly under the same circumstances. But that will be a different question.
Upvotes: 2