You are on page 1of 1

multi-line comments:/*Lex program to take input from file and

remove multiple spaces, newline and tab


and write output in a separate file*/

% {
/*Definition section */
%
}

/* Rule: whenever space, tab or


newline is encounterd, remove it*/
% %
[ \n\t]+ {fprintf(yyout, "");}
. { fprintf(yyout, "%s", yytext); }
% %

int yywrap(){}

// driver code
int main()
{

/* yyin and yyout as pointer


of File type */
extern FILE *yyin, *yyout;

/* yyin points to the file input.txt


and opens it in read mode*/
yyin = fopen("Input.txt", "r");

/* yyout points to the file output.txt


and opens it in write mode*/

identifier:yyout
operator:=
identifier:fopen
separator:(
" identifier:Output
. identifier:txt
" separator:,
" identifier:w
" separator:)
separator:;

identifier:yylex
separator:(
separator:)
separator:;

identifier:return
posetive integer:0
separator:;

separator:}
Total tokens:19

You might also like