CSE 066 07731 - Com - Ass
CSE 066 07731 - Com - Ass
int tokencount = 0;
int variable = 0;
int variabletype = 0;
int operator = 0;
int digit = 0;
%}
%%
^[a-zA-Z\_][a-zA-Z0-9\_]+ {printf("%s is a
variable\n",yytext);tokencount++;variable++;}
[<>\-\+\?\*\/!\^\=,\(\);] {printf("%s is a
operator\n",yytext);tokencount++;operator++;}
%%
int main(){
FILE *file;
file = fopen("code1.c", "r") ;
if (!file) {
printf("couldnot open file");
exit (1);
}
else {
yyin = file;
}
yylex();
printf("Number of tokens is : %d\n",tokencount);
printf("Number of variables is : %d\n",variable);
printf("Number of variable types is : %d\n",variabletype);
printf("Number of digits is : %d\n",digit);
printf("Number of operators is : %d\n",operator);
}
Output