Ds Lab Programs
Ds Lab Programs
%{
#include<stdio.h>
int ac=0;
%}
%%
[a] {ac++;}
%%
main()
{
printf(“Enter the string.. at end press ^d\n”);
yylex();
printf(“No of a’s=%d\n”, ac);
}
%{
#include<stdio.h>
int vc=0,cc=0;
%}
%%
[aeiouAEIOU] {vc++;}
[a-zA-Z] {cc++;}
. ;
%%
main()
{
printf("enter the sentence");
yylex();
printf("number of vowels= %d",vc);
printf("\nnumber of consonants=%d",cc);
}
%{
#include<stdio.h>
int flag=0;
%}
%%
" and "|" or "|" but "|" because "|" although " {flag=1;}
. ;
%%
main()
{
printf("enter a sentence\n");
yylex();
if(flag==1)
{
printf("\n compound sentence");
}
else
{
printf("\n simple sentence");
}
}