(F) lex how to print a string with a match
I'm really not familiar with lex / flex. I am trying to debug some legacy flex codes. I want to see text that matches a certain rule.
eg.
[a-z]* {"some C code" "need to print the string that matched this rule"}
eg. if johndoe@xyz.com
is the input, I need to print the matched string i.e.johndoe
I tried typing yytext
, but it only shows me the first character.
source to share
If you are trying to debug and are using flex
, then you probably want to use the option -d
when you translate your flex input file to C
. This will create a debug scanner that will automatically report all rule matches (as well as other events).
See flex manual for details
If you really want to insert statements printf
, this should work fine:
printf("The matched text is <%s>\n", yytext);
source to share