cegtuprogramiz
Gujarat Technological University
Tuesday, 31 March 2020
Sunday, 16 June 2019
Write a LEX program to check whether input symbol is number or character.
Code :
%{
%}
%%
[0-9] {printf("Input is a number");}
[A-Za-z] {printf("Input is a character");}
%%
main()
{
yylex();
}
int yywrap()
{
return 1;
}
Write a LEX program to check whether input is multidigit number or string.
Code :
%{
%}
%%
[0-9][0-9]+ {printf("Input is a multi digit
number");}
[A-Za-z][A-Za-z]+ {printf("Input is a multi
character");}
%%
main()
{
yylex();
}
int yywrap()
{
return 1;
}
Write a LEX program to check whether inputted character is vowel or not.
Code :
%{
%}
%%
[aeiouAEIOU]
{printf("Input is a vowel");}
[A-Za-z(^aeiouAEIOU)]
{printf("Input is not a vowel");}
%%
main()
{
yylex();
}
int yywrap()
{
return 1;
}
Write a LEX program to count only those words that start with vowels.
Code :
%{
%}
%%
[aeiouAEIOU][A-Za-z]+ {printf("Word starting with
vowel");}
[A-Za-z(^aeiouAEIOU)][A-Za-z]+
{printf("Word not starting with vowel");}
%%
main()
{
yylex();
}
int yywrap()
{
return 1;
}
Write a LEX program to count number of vowels from all inputted symbols.
Code :
%{
int count_v;
%}
%%
[aeiouAEIOU]
{count_v++;}
%%
main()
{
yylex();
printf("Count of vowels=
%d\n",count_v);
}
int yywrap()
{
return 1;
}
Subscribe to:
Posts (Atom)
It's time To increase blogging capability. To have a chance to contribute in digital world. Any Interested People who want to make t...
-
#include <stdio.h> #include <string.h> int main () { char arithmetic[5]={'+','-','*',...
-
Code: %{ #include<stdio.h> int flag=0; %} %% [a-z . 0-9]+@[a-z]+".com"|".in" {flag=1;} %% int...
-
#include<stdio.h> #include<stdlib.h> #include<string.h> ...