You are on page 1of 2

%{ #include<stdio.

h> %}

%token NAME NUMBER %% statement: NAME '=' expression | ; expression { printf("=%d\n",$1);}

expression:expression '+' expression { $$ = $1 + $3;} | expression '-' expression { $$ = $1 - $3;}

| expression '*' expression {$$=$1*$3;} | expression '/' expression {if ($3==0) printf("DIVIDE BY ZERO ERROR\n"); else $$=$1/$3; } | NUMBER {$$=$1;} ;

%%

extern FILE * yyin; main() { do { yyparse(); } while(!feof(yyin)); } int yywrap() { return 1; } yyerror(char *s) { printf("ERROR \n"); }

You might also like