2
votes

I have problem on Yacc/Bison. This is my code :

%{
#include <stdio.h>
%}

%union{
double val;

}

%start debut
%token <val> nombre
%left PLUS

%%
debut :
|  ADDITION {printf('%f \n',$1);}
;

ADDITION : nombre PLUS nombre {$$=$1+$3;}
;
%%

void yyerror(char *s){
    printf("%s \n",s);
}

int main(void){
    return yyparse();
}

I get this error type : $1 of 'debut' has no declared type

1

1 Answers

2
votes

$1 of debut is the first symbol of the debut production, ie. the ADDITION symbol. As the ADDITION symbol has no declared type, yacc cannot expand the $1 placeholder to anything meaningful.

To fix the problem, add %type <val> ADDITION to the list of definitions (the part before the first %%).