Professional Documents
Culture Documents
Lab6 CD
Lab6 CD
%{
/*** Auxiliary declarations section ***/
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
%}
E: E '+' T {printf("E->E+T\n");}
|T {printf("E->T\n");}
;
T: T '*' F {printf("T->T*F\n");}
|F {printf("T->F\n");}
;
F: '(' E ')' {printf("F->(F)\n");}
| DIGIT {printf("F->num\n");}
;
%%
yylex(){
char c;
c = getchar();
if(isdigit(c)){
pos++;
return
DIGIT;
}
else if(c == ' '){
yylex(); /*This is to ignore whitespaces in the input*/
}
else {
return c;
}
}
main()
{
yyparse();
return 1;
}