Friday, April 12, 2019

Demonstrate the use of lex predefined variables (yytext, yyleng, yyin) with the help of program Inputted from text file

%{
#include<stdio.h>
%}
%%
[a-z]* printf("matched string %s and length is %d",yytext,yyleng);
.* printf("%s invalid",yytext);
%%
int yywrap()
{
return 1;
}
main()
{
FILE *fp;
fp=fopen("text.txt","r");
if(fp==NULL)
{
  printf("file not found");
}
yyin=fp;
yylex();
fclose(fp);
}

ScreenShot:

No comments:

Post a Comment