ADVERTISEMENT
ADVERTISEMENT

Home » Compiler Design

LEX code to replace all the ‘if’ keyword to capital ‘if’ from the given C/C++ file

In this article, we going to learn how to create LEX program to replace the entire if keyword to capital IF from given C/C++ file?
Submitted by Ashish Varshney, on March 28, 2018

For achieve to this task we create some rules in rule section in the code.

%{
#include<stdio.h>
%}

%%

"if" fprintf(yyout,"IF");
.|\n fprintf(yyout,"%s",yytext);

%%

int yywrap()
{
return 1;
}

int main(void)
{
yyin=fopen("input8.c","r");
yyout=fopen("output8.c","w");
yylex();
return 0;
}

Input

LEX code to replace all the ‘if’ keyword to capital ‘if’ from the given C/C++ file - Incput

Output

LEX code to replace all the ‘if’ keyword to capital ‘if’ from the given C/C++ file - Output

ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.