This post was published long ago, when I was a student and an amateur blogger. The links might be outdated and content may not be useful anymore. Please read this content keeping its age in mind.
Subject : System Software Laboratory
Branch : Information Science & Engineering
Semester : 6
University : VTU
………………………………………………………………………………………………………………………….
PART – A
………………………………………………………………………………………………………………………….
3) Program to recognize and count the number of identifiers in a given
input file.
%{
int id=0;
%}
ID [_a-zA-Z][a-zA-Z0-9]*
DECLN “int”|”float”|”char”|”short”|”double”|”long”|”unsigned”
%x DEFN
%%
{DECLN} {BEGIN DEFN;}
<DEFN>{ID}, id++;
<DEFN>{ID}; id++;
<>n ;
<>. ;
%%
main(int argc, char **argv)
{
if(argc==2)
{
yyin=fopen(argv[1],”r”);
yylex();
printf(“n Number of identifiers : %dn”,id);
}
else
printf(“n Usage :%s <file>n”,argv[0]);
}
Leave a ReplyCancel reply