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.
我真的不熟悉lex/flex。我正在尝试调试一些遗留的flex代码。我想要看到一个特定规则匹配的文本。
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
如。如果johndoe@xyz.com是输入,我需要打印匹配的字符串,即johndoe。
I tried printing yytext
, but it shows me only the first character.
我试过打印yytext,但它只显示了第一个字符。
1 个解决方案
#1
2
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).
如果您正在尝试调试,并且使用flex,那么您可能希望在将flex输入转换为c时使用-d选项,这将构建一个调试扫描器,它将自动报告所有规则匹配(以及其他事件)。
For more details, see the flex manual
有关详细信息,请参见flex手册。
If you really want to insert printf
statements, this should work fine:
如果你真的想插入printf语句,这应该没问题:
printf("The matched text is <%s>\n", yytext);
#1
2
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).
如果您正在尝试调试,并且使用flex,那么您可能希望在将flex输入转换为c时使用-d选项,这将构建一个调试扫描器,它将自动报告所有规则匹配(以及其他事件)。
For more details, see the flex manual
有关详细信息,请参见flex手册。
If you really want to insert printf
statements, this should work fine:
如果你真的想插入printf语句,这应该没问题:
printf("The matched text is <%s>\n", yytext);