Create Yacc and Lex specification files are used to generate a calculator which accepts,integer and float type arguments.

exp.l file

%option noyywrap
%{
#include<stdio.h>
#include "y.tab.h"
%}
%%
[0-9]+|[0-9]+\.[0-9]+ {yylval.dval=atof(yytext);return DIGIT;}
.|\n {return yytext[0];}
%%

exp.y file

%{
#include<stdio.h>
%}
%union
{
double dval;
}
%token <dval> DIGIT
%type <dval> expr
%type <dval> term
%type <dval> factor
%%
line: expr '\n' {printf("%lf\n",$1);};
expr: expr '+' term {$$=$1 + $3 ;} | expr '-' term {$$=$1 - $3 ;}| term;
term: term '*' factor {$$=$1 * $3 ;} | term '/' factor {$$=$1 / $3 ;} | factor;
factor: '(' expr ')' {$$=$2 ;} | '-'factor {$$= -$2;} | DIGIT;
%%

int main()
{
yyparse();
}
int yyerror(char *s)
{
printf("%s",s);
return 0;
}

Output: