System Software Lab Programs ( Lex and Yaac Programs ) 3.l
// June 10th, 2009 // Educational, Engineering, Unix and System Software Lab // Written by Sandeep Hegde
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 : %d\n”,id);
}
else
printf(“\n Usage :%s <file>\n”,argv[0]);
}



