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
.
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 :
can u please help me,
using any topic, mini project based on lex and yacc concept
nice logic
how can we put the result of this in another file
how can we put the result of this in another file
@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