Untitled

 avatar
unknown
plain_text
a year ago
624 B
16
Indexable
%{
#include<stdio.h>
int flag=0;
%}
%token NUMBER
%left '+''-'
%left '*''/''%'
%left '('')'
%%
arithmeticexpression :e{
printf("\n RESULT=%d\n",$$);
return 0;
};
e:e'+'e{$$=$1+$3;}
| e'-'e{$$=$1-$3;}
| e'*'e{$$=$1*$3;}
| e'/'e{$$=$1/$3;}
| e'%'e{$$=$1%$3;}
| '('e')'e{$$=$2;}
| NUMBER{$$=$1;};
%%
void main()
{
printf("\n Enter any arithmetic expression which can have operations addition,subtraction,multiplication,division,modulus and round brackets: \n");
yyparse();
if(flag==0)
printf("\n Entered arithmetic expression is valid\n");
}
void yyerror()
{
printf("\n Entered arithmetic expression is invalid\n");
flag=1;
}

Editor is loading...
Leave a Comment