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

Popular posts from this blog

KTU Compiler Lab CSL411 - Dr Binu V P

lexical analyzer for a c program

13.Precedence and conflict resolution in yacc