Sunday, 16 June 2019

Write a LEX program that reads c program from input file and writes same program to output file appending line number to every line other than comment.


               Code :

%{
#include<stdio.h>
int cnt=1;
%}
%%
\/\/.*  {fprintf(yyout,"");}
\/\*(.*\n)*.*\*\/ {fprintf(yyout,"");}
.* {fprintf(yyout,"%d %s",cnt,yytext);
                 cnt++;}
%%
main()
{
    yyin=fopen("input.txt","r");
    yyout=fopen("output.txt","w");
     yylex();
}
int yywrap()
{
return 1;
}

No comments:

Post a Comment

It's time To increase blogging capability. To have a chance to contribute in digital world. Any Interested People who want to make t...