0% found this document useful (0 votes)
2 views2 pages

CSE 066 07731 - Com - Ass

The document is a lexer program written in C that counts various tokens in a source code file. It identifies variables, variable types, digits, and operators, printing their counts after processing the file. The program reads from 'code1.c' and outputs the total number of each token type found.

Uploaded by

jopesi2876
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

CSE 066 07731 - Com - Ass

The document is a lexer program written in C that counts various tokens in a source code file. It identifies variables, variable types, digits, and operators, printing their counts after processing the file. The program reads from 'code1.c' and outputs the total number of each token type found.

Uploaded by

jopesi2876
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

%{

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++;}

^(char)[ ]|^(int)[ ]|^(float)[ ]|^(double)[ ]|^(void)[ ] {printf("%s is a


variableType\n",yytext);tokencount++;variabletype++;}

[0-9] {printf("%s is a digit\n",yytext);tokencount++;digit++;}

[<>\-\+\?\*\/!\^\=,\(\);] {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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy