0% found this document useful (0 votes)
51 views

Ds Lab Programs

The document contains 3 Lex programs: 1. A program that counts the number of 'a' characters in a given string. 2. A program that counts the number of vowels and consonants in a given string. 3. A program that determines whether a given sentence is simple or compound based on the presence of conjunctions like "and", "or", "but".

Uploaded by

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

Ds Lab Programs

The document contains 3 Lex programs: 1. A program that counts the number of 'a' characters in a given string. 2. A program that counts the number of vowels and consonants in a given string. 3. A program that determines whether a given sentence is simple or compound based on the presence of conjunctions like "and", "or", "but".

Uploaded by

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

1 LEX PROGRAM TO COUNT NUMBER OF A'S IN THE GIVEN STRING

%{
#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);
}

2 LEX PROGRAM TO COUNT THE NUMBER OF VOWELS AND CONSONANTS IN


A GIVEN STRING

%{
#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);
}

3 PROGRAM TO RECOGNIZE WHETHER A GIVEN SENTENCE IS SIMPLE OR


COMPOUND.

%{
#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");
}
}

You might also like