I need to treate a string in C where certain words, if present, have to be converted to uppercase. My first choice was to work it in LEX something like this:
%%
word1 {setToUppercase(yytext);RETURN WORD1;}
word2 {setToUppercase(yytext);RETURN WORD2;}
word3 {setToUppercase(yytext);RETURN WORD3;}
%%
The problem I see is that I don't get to detect if some of the chars are uppercase (f.e. Word1, wOrd1...). This could mean a one by one listing:
%%
word1 |
Word1 |
WOrd1
{setToUppercase(yytext);RETURN WORD1;}
%%
Is there a way of defining that this especific tokens are to be compared in a case insensitive mode? I have found that I can compile the lexer to be case insensitive, but this can affect other pars of my program.
If not, any workaround suggestion?
You could set case-insensitivity in the .l
file:
%option caseless
You could call flex -i
.
Or you could state individual rules to be case-insensitive:
(?i:word)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With