Friday, September 9

LEX Program to eliminate all whitespaces

Hi Guys,
This lex program is aimed to eliminate all whitespaces from an input file. As u think, this is not at all a difficult job. We have to simply detect single blank ' ' or tab '\t' or a newline '\n' and delete them in output. That's all..!!!!



%{
#include<stdio.h>
%}

%%
[\n\t ' '] {};
%%
main()
{
yyin=fopen("myfile.txt","r");
yylex();

}
int yywrap()
{
return 1;
}

____________________________________________________________________
Look @ the example:

Basic datatypes in C are:
int   char  float   double

output will be

BasicdatatypesinCare:intcharfloatdouble




.

5 comments :

Anonymous said... Best Blogger Tips [Reply to comment] Best Blogger Templates

can u please help me,
using any topic, mini project based on lex and yacc concept

Anonymous said... Best Blogger Tips [Reply to comment] Best Blogger Templates

nice logic

Unknown said... Best Blogger Tips [Reply to comment] Best Blogger Templates

how can we put the result of this in another file

Unknown said... Best Blogger Tips [Reply to comment] Best Blogger Templates

how can we put the result of this in another file

Anonymous said... Best Blogger Tips [Reply to comment] Best Blogger Templates

@Unknown

you have to use another pointer *yyout and using fprintf you can write this output into another file located by it.
syntax = fprintf(yyout, "%s", "anything you want to write);

Post a Comment