Replace Sequences of White Spaces by a Single Blank Character - Lex Program - Compiler Design

Elimination of Multiple Spaces ,Tabs & Emptylines

Program:

%{
   
%}

space [ \t]
emptyline \n
%%

{space}+ printf(" ");
{emptyline}+ printf("\n");
. ECHO;

%%

main()
{

    yylex();
}
Output:

 // input: sum.c

#include<stdio.h>
main()
{


//program to add two numbers
int a,      b,c;
scanf("%d%d",&a,&b);
c=a+b;/* finding sum &
printing*/
printf("sum=%d",c);
}



nn@linuxmint ~ $ lex mw.l
nn@linuxmint ~ $ gcc lex.yy.c -ll
nn@linuxmint ~ $ ./a.out<sum.c
#include<stdio.h>
main()
{
//program to add two numbers
int a, b,c;
scanf("%d%d",&a,&b);
c=a+b;/* finding sum &
printing*/
printf("sum=%d",c);
}
nn@linuxmint ~ $

1 comment:

  1. Very nice blog, Thanks for sharing such great information. hope you keep sharing such kind of information find and replace software

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...