%{
#include<stdio.h>
#include "y.tab.h"
%}
%%
[a-zA-Z0-9]+ { return NUM; }
[\n] return 0;
. return yytext[0];
%%
int yywrap()
{
return 1;
}
PROGRAM-YACC
%{
#include<stdio.h>
int flag=0;
%}
%token NUM
%left '+''-'
%left '*''/''%'
%left '('')'
%%
ArithmeticExpression:E{ printf("\nResult=%d\n",$$);return 0;}
;
E:E'+'E
|E'-'E
|E'*'E
|E'/'E
|E'%'E
|'('E')'
|NUM
;
%%
void main()
{
printf("\nEnter an arithmetic expression:\n");
yyparse();
if (flag==0)
printf
("\nEntered arithmetic expression
is Valid\n\n"
);}
void yyerror()
{
printf("\nInvalid expression\n");
flag=1;
}
JXsKI2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGUgInkudGFiLmgiCiV9CiUlClthLXpBLVowLTldKyB7IHJldHVybiBOVU07IH0KW1xuXSByZXR1cm4gMDsKLiByZXR1cm4geXl0ZXh0WzBdOwolJQppbnQgeXl3cmFwKCkKewpyZXR1cm4gMTsKfQpQUk9HUkFNLVlBQ0MKJXsKI2luY2x1ZGU8c3RkaW8uaD4KaW50IGZsYWc9MDsKJX0KJXRva2VuIE5VTQolbGVmdCAnKycnLScKJWxlZnQgJyonJy8nJyUnCiVsZWZ0ICcoJycpJwolJQpBcml0aG1ldGljRXhwcmVzc2lvbjpFeyBwcmludGYoIlxuUmVzdWx0PSVkXG4iLCQkKTtyZXR1cm4gMDt9CjsKRTpFJysnRQp8RSctJ0UKfEUnKidFCnxFJy8nRQp8RSclJ0UKfCcoJ0UnKScKfE5VTQo7CiUlCnZvaWQgbWFpbigpCnsKcHJpbnRmKCJcbkVudGVyIGFuIGFyaXRobWV0aWMgZXhwcmVzc2lvbjpcbiIpOwp5eXBhcnNlKCk7CmlmIChmbGFnPT0wKQpwcmludGYoIlxuRW50ZXJlZCBhcml0aG1ldGljIGV4cHJlc3Npb24gaXMgVmFsaWRcblxuIik7Cn0Kdm9pZCB5eWVycm9yKCkKewpwcmludGYoIlxuSW52YWxpZCBleHByZXNzaW9uXG4iKTsKZmxhZz0xOwp9