Sunday, 16 June 2019

Write a LEX program to check a Date of format (DD/MM/YYYY).



Code:
%{
#include<stdio.h>
int valid=0;
%}
%%
([0-2][0-9]|3[0-1])\/(0[1-9]|1[0-2])\/([1-2][0-9][0-9][0-9]) {valid=1;}
%%
main()
{
yyin=fopen("input.txt","r");
yylex();
if(valid==1) printf("It is a valid date\n");
else printf("It is not a valid date\n");
}
int yywrap()
{
return 1;
}

1 comment:

  1. The code is not compatible because it accepts 31-02-2001

    ReplyDelete

It's time To increase blogging capability. To have a chance to contribute in digital world. Any Interested People who want to make t...