I'm really not familiar with lex/flex. I'm trying to debug some legacy flex code. I want to see the text that was matched by a particular 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 printing yytext
, but it shows me only the first character.
If you're trying to debug, and you're using flex
, then you probably want to use the -d
option when you translate your flex input into C
. That will build a debugging scanner which will automatically report all rule matches (as well as other events).
For more details, see the flex manual
If you really want to insert printf
statements, this should work fine:
printf("The matched text is <%s>\n", yytext);