%{ extern int lineno; %} %token PLUS SUB MULT DIV NUMBER LINE ERROR %left PLUS SUB %left MULT DIV %% S: E LINE { printf("Result= %d\n",$1);} ; E: E PLUS T { $$=$1+$3;} | E SUB T { $$=$1-$3;} |T {$$ = $1;} ; T: T MULT F { $$=$1*$3;} | T DIV F { $$=$1/$3; printf("Value=%d\n",$$);} |F {$$=$1;} ; F: NUMBER { $$=$1;} ; %% #include "lex.yy.c" int yyerror() { printf("Error at line no: %d\n",lineno); } int main() { printf("Enter the Expression: "); yyparse(); return 0; }