










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
term project for compiler construction
Typology: Assignments
1 / 18
This page cannot be seen from the preview
Don't miss anything!











Rolf Haworth wrote the calculator in early 1996. A fully featured scientific calculator with proper operator precedence is implemented, including trigonometric functions and logarithms.in this implementation we have used flex and yaac to implement this calculator using c language. Although it is not fully scientific but it will perform major scientific tasks which are required by a user
Calculator has a wide scope of applications, it is useful in many fields like science, technology, accounting, marketing, education, finances, , etc. Their accessibility depends on the user understanding basic mathematical concepts such as addition, subtraction, multiplication, division, etc. Scientific calculators require a more advanced level of understanding from the user for their scientific functions. This Calculator project has vide scope in the field of mathematics’ as in math students and also in daily life people require a calculator to perform math or calculation tasks hence this will be beneficial for those students and people
Where as cos ,sin ,tan and others are functions and to perform these functions math.h library has been used DFA
program →statement | program statement statement → exp | id = exp | clear id | list | quit | exit exp→ term | exp + term | exp - term term→ power | term * power | term / power power → factor | factor ** power
factor →id | number | ( exp ) | sqrt ( exp )
#include <math.h> #include "y.tab.h" %} %% [0-9]+.?|[0-9]*.[0-9]+ { yylval.p = atof(yytext); return num;} log {return LOG;} sin {return SIN;} cos {return COS;} tan {return TAN;} sqrt {return SQRT;} [\t]; \n return 0;
. return yytext[0]; %%
%union {double p;} %token
num %token SIN COS TAN LOG %left '+' '-' %left '' '/' %nonassoc uminu %type exp %% ss: expression '\n' { printf(" = %lf\n", $2); } ; expr: term { $$ = $1; } | expr '+' term { $$ = $1 + $3; } | expr '-' term { $$ = $1 - $3; } ; term: factor { $$ = $1; } | term '
| group { $$ = $1; } ; power: factor { $$ = $1; } | factor ** power { $$ **$1;} ; factor :id { $$ = $1; } | number | ( exp ) | sqrt ( exp ) ; group: '(' expression ')' { $$ = $2; } ; { if ($3==0) { printf("Divided By Zero"); } else $$ = $1 / $3; } |'-'exp { $$ = -$2;} |SIN'('exp')' { $$ = sin($3);} |COS'('exp')' { $$ = cos($3);} |TAN'('exp')' { $$ = tan($3);} |LOG'('exp')' { $$ = log($3);} |SQRT'('exp')' { $$ = sqrt($3);}
After completing this project now the understanding of first three phases of compiler which are also front end phases has increased and building this term project has improve the understanding level which will help us in next phases and also in future when we learn the next phases of compiler. hence