Friday, April 12, 2019

lex program to validate IP addresses from user specified file


%{
#include<stdio.h>
%}

%%
^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$ printf("Vaild IP Address");
[A-Za-z0-9.]* printf("Invalid IP Address");
%%

int main()
{
  FILE *fp;
  fp = fopen("ipaddress.txt", "r");
  if (fp == NULL) { printf("File not found"); }
  yyin = fp;

 yylex();
 return 0;
}

ScreenShot:





No comments:

Post a Comment