Professional Documents
Culture Documents
Name:Sakshi Aggarwal course:MCA-3 Student Id-20712081 Section:b
Name:Sakshi Aggarwal course:MCA-3 Student Id-20712081 Section:b
SOURCE CODE-
%{
int v=0,c=0;
%}
%%
[aeiouAEIOU]+ {v++;}
[a-zA-Z] {c++;}
"\n" {
printf("Number of vowels: %d\n", v);
printf("Number of consonants: %d\n", c);
v=0;
c=0;
}
%%
int main()
{
printf("Enter the string:\n");
yylex();
return 0;
}
intyywrap(){}
OUTPUT-
Name:Sakshi Aggarwal course:MCA-3
Student id-20712081 section:B
SOURCE CODE-
%{
#include<stdio.h>
%}
%%
think|ride|run|loudly|camly|quickly|jump|angrily|roast|say {
printf("%s is a verb.\n",yytext);
}
president|apple|lily|disneyland|minister|mother|father|dehradun|uk|india {
printf("%s is a noun.\n",yytext);
}
big|large|few|millions|eleven|enormous|many {
printf("%s is an adjective.\n",yytext);
}
%%
intyywrap(){ return 1;}
int main()
{
printf("Enter a word:");
yylex();
return 0;
}
Name:Sakshi Aggarwal course:MCA-3
SOURCE CODE-
%{
#include<stdio.h>
%}
%%
^[-][0-9]+ {printf("%s is a Negative Number.\n",yytext);}
[0-9]+ {printf("%s is a Positive Number.\n",yytext);}
%%
intyywrap(){}
int main()
{
printf("Enter a number:");
yylex();
return 0;
}
OUTPUT-
Name:Sakshi Aggarwal course:MCA-3
SOURCE CODE-
%{
#include<stdio.h>
int p=0,n=0;
%}
DIGIT [0-9]
%%
\+?{DIGIT}*\.{DIGIT}+ {p=p+1;}
-{DIGIT}*\.{DIGIT}+ {n=n+1;}
"\n" {
printf("\nPositive Number in fraction: %d\n",p);
printf("\nNegative Number in fraction: %d\n",n);
p=0;
n=0;
}
%%
intyywrap(){}
int main(){
yylex();
return 0;
}
OUTPUT-
Name:Sakshi Aggarwal course:MCA-3
SOURCE CODE-
%{
#include<stdio.h>
%}
%%
for|do|while|int|float|char|string|if|else|switch|long|short|signed|unsigned|try|catch {
printf("%s is a Keyword\n",yytext);
}
.* {printf("\nNot a valid keyword, Wrong Input!");}
%%
intyywrap(){ return 1;}
int main()
{
printf("Enter an input:");
yylex();
return 0;
}
OUTPUT-
Name:Sakshi Aggarwal course:MCA-3
SOURCE CODE-
%{
#include<stdio.h>
%}
%%
"hi" {printf("\nBye");}
([A-Za-z])* {printf("\nWrong Input");}
%%
int main(){
yylex();
return 0;
}
intyywrap(){}
OUTPUT-
Name:Sakshi Aggarwal course:MCA-3
SOURCE CODE-
%{
#include<stdio.h>
intnum;
%}
%%
[0-9]+ {
num=atoi(yytext);
if(num%2==0)
printf("\nNumber is Even");
else
printf("\nNumber is Odd");
}
%%
int main(){
printf("\nEnter a Number:");
yylex();
return 0;
}
intyywrap(){}
OUTPUT-
Name:Sakshi Aggarwal course:MCA-3
SOURCE CODE-
%{
#include<stdio.h>
int c=0;
%}
%%
[a-zA-Z]+ {
if (yyleng> c)
c=yyleng;
}
SOURCE CODE-
%{
#include<stdio.h>
%}
%%
[a-z] {printf("Character is in Lower Case");}
[A-Z] {printf("Character is in Upper Case");}
%%
int main()
{
printf("Enter the Character:\n");
yylex();
return 0;
}
intyywrap(){}
OUTPUT-
Name:Sakshi Aggarwal course:MCA-3
SOURCE CODE-
%{
#include<stdio.h>
int flag=0;
%}
%%
[aA][nN][dD]+ {flag=1;}
[bB][uU][tT]+ {flag=1;}
[oO][rR]+ {flag=1;}
"\n" {
if(flag==1){
printf("\nIt is a Compound Sentence\n");
flag=0;
}
else
printf("\nIt is a Simple Sentence\n");
}
%%
int main(){
printf("Enter a sentence:\n");
yylex();
return 0;
}
intyywrap(){}
OUTPUT-
Name:Sakshi Aggarwal course:MCA-3
SOURCE CODE-
%{
#include<stdio.h>
%}
%%
%%
intyywrap(){}
int main(){
printf("\nEnter a Word:\n");
yylex();
return 0;
OUTPUT-
Name:Sakshi Aggarwal course:MCA-3
SOURCE CODE-
%{
#include<stdio.h>
intlen=0;
%}
%%
[a-zA-Z0-9 ]+ {len=yyleng;}
%%
intyywrap(){}
int main(){
printf("\nEnter a string:\n");
yylex();
return 0;
OUTPUT-