Friday, April 12, 2019

Lex program that takes input from user specified file and labels each input as Integer, Float, Exponential or Other

%{
#include<stdio.h>
%}
%%
  /*** Rules section ***/
[-0-9]* {
    printf("Integer Value");
  }
^[-|0-9][0-9]+(.)[0-9]+ {
  printf("Float Value");
  }
[-0-9]*(.)[0-9]+(E)[-0-9]+ {
  printf("Exponential Value");
}
.* {
    printf("Invalid value");
  }
%%
int main()
{
  FILE *fp;
  fp = fopen("test1.txt", "r");
  if (fp == NULL) { printf("File not found"); }
  yyin = fp;
  yylex();
  return 0;
}

ScreenShot:

No comments:

Post a Comment