I am making a calculator with the sum and subtraction operations
this is my code...
Calc.y
%{
#include
%}
%union{
double dval;
}
%token NUMERO
%token SUMA RESTA
%token ABRIR CERRAR
%token END
%left SUMA RESTA
%left NEG
%type Expresion
%start Input
%%
Input: Line
| Input Line
;
Line: END
| Expresion END
{
printf("Resultado: %f\n",$1);
}
;
Expresion: NUMERO { $$=$1; }
| Expresion SUMA Expresion { $$=$1+$3; }
| Expresion RESTA Expresion { $$=$1-$3; }
| RESTA Expresion %prec NEG { $$=-$2; }
| ABRIR Expresion CERRAR { $$=$2; }
;
%%
int yyerror(char *s) { printf("%s\n",s); }
int main(void) { yyparse(); }
And this is the error Calc.y:16.7-15: syntax error, unexpected identifier, expecting type