Convert the substring abc to ABC lex program
The program will read a line of text and changes all occurrence of the substring "abc" with "ABC"
***************************************
%option noyywrap
%%
abc { printf("ABC"); }
.|\n { printf("%s", yytext); }
%%
int main() {
yylex();
return 0;
}
Execution
$flex abc.lex
$ gcc lex.yy.c
$ ./a.out
this is a testabc djd abc djd
this is a testABC djd ABC djd
djdjd ajdjd abc djdabc abdf abcj abdc abc
djdjd ajdjd ABC djdABC abdf ABCj abdc ABC
Comments
Post a Comment