Wednesday, September 9, 2020

Write a Lex program to print out all numbers from the given file.

 Print out all numbers from the given file in Lex Program.


Create first file  Num.l or Num.lex , and Create Second file num.txt

Num.l


%{ #include <stdio.h> %} %% [0-9]+ { printf("%s\n", yytext); } .|\n ; %% int yywrap(void){} int main(int argc, char*argv[]) { yyin=fopen("num.txt","r"); yylex(); return 0; }


INPUT :-

num.txt


1 2 3 4 5 6 7 8 9 0


OUTPUT



sunny@sunny-PC:~/Desktop$ flex num.l sunny@sunny-PC:~/Desktop$ gcc lex.yy.c sunny@sunny-PC:~/Desktop$ ./a.out 1 2 3 4 5 6 7 8 9 0



No comments:

Post a Comment

Please do not any spam link in Comment Box