AIM:
Q15. Write the Lex program to check valid URL or not:
Code:
%{
#include<stdio.h>
%}
%%
((http)|(ftp))s?:\/\/[a-zA-Z0-9]{2,}(\.[a-z]{2,})+(\/[a-zA-Z0-9+=?]*)*
{printf("\nURL Valid\n");}
.+ {printf("\nURL Invalid\n");}
%%
void main()
{
printf("\nEnter URL : ");
yylex();
printf("\n");
}
int yywrap()
{
return 1 ;
}
OUTPUT:
AIM:
Q16. Write the Lex program to check valid email or not:
Code:
%{
#include<stdio.h>
int flag = 0;
%}
%%
[a-z0-9_]+@[a-z]+".com"|".in" {flag = 1;}
%%
void main() {
yylex();
if (flag == 1)
printf("Accepted");
else
printf("Not Accepted");
}
OUTPUT:
AIM:
Q17. Write the Lex program to check valid password or
not:
Code:
%{
#include<stdio.h>
#include<string.h>
int a = 0, b=0, c=0, d=0, l=0;
%}
%%
[a-z] {a++;l++;}
[A-Z] {b++;l++;}
[0-9] {c++;l++;}
[$&+, :;=?@#|'<>.-^*()%!] {d++;l++;}
. ;
%%
int main()
{
yylex();
if(a>0 && b>0 && c>0 && d>0 && l>=8)
printf("VALID\n");
else
printf("INVALID\n");
return 0;
}
int yywrap(void)
{
return 1 ;}
OUTPUT: