Enter your email address & Win:

System Software Lab Programs ( Lex and Yaac Programs ) 3.l

// June 10th, 2009 // Educational, Engineering, Unix and System Software Lab // Written by sandeephegde

-->

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]);
}


If you enjoyed this post, make sure you subscribe to my RSS feed!

Related posts:

  1. System Software Lab Programs ( Lex and Yaac Programs )1b
  2. System Software Lab Programs ( Lex and Yaac Programs )exa
  3. System Software Lab Programs ( Lex and Yaac Programs )2a.l
  4. System Software Lab Programs ( UNIX Programs ) – 3b
  5. System Software Lab Programs ( Lex and Yaac Programs ) 5a
blog comments powered by Disqus
Get Adobe Flash playerPlugin by wpburn.com wordpress themes