
This lex program will read an input file and copy the content with line number to another file.
%{
#include<stdio.h>
#include<string.h>
char line[20];
int count=0,i=0;
FILE *out;
%}
%%
['\n'] { fprintf(out,"%d %s\n",++count,line);}
(.*) {
strcpy(line,yytext);
}%%
main()
{
yyin=fopen("in.c","r");
out=fopen("out.c","w");
yylex();
getch();
}
int yywrap()
{
return 1;
}
input
main()
{
int i=9, j=900,k=115;
printf("%d,i+j+k);
}
output file
1 main()
2 {
3 int i=9, j=900,k=115;
4 printf("%d,i+j+k);
5 }
6...