简体   繁体   English

Flex我很困惑

[英]flex i am confused

input to lexer 输入到词法分析器

abc gef4 44jdjd ghghg
x
ererete
xyzzz
55k
hello wold
33

my rules 我的规则

rule1 [0-9]+[a-zA-Z]+
rule2 [x-z]
rule3 .*

{rule1} { printf("%s \\n", yytext); {rule1} {printf(“%s \\ n”,yytext); } }

{rule2} { printf("%s \\n", yytext); {rule2} {printf(“%s \\ n”,yytext); } }

{rule3} { // prints nothing } {rule3} {//不输出任何内容}

output :- 输出:-

x  



55k   

I cannot understand the output ? 我不明白输出吗? Can someone please help me. 有人可以帮帮我吗。

The first character of the input neither matches rule1 nor rule2. 输入的第一个字符与rule1或rule2都不匹配。 Instead rule3 eats input up to the end of line. 相反,rule3会吃到行尾的输入。 The same happens on line 3, 4, 6, and 7. You probably want a less greedy rule3, ie one that doesn't consume the spaces: 在第3、4、6和7行上也会发生同样的情况。您可能希望减少贪婪的Rule3,即不占用空格的规则:

[^ \t\n]*           /* Do nothing */

Then 44jdjd is being found by rule1. 然后,rule1将找到44jdjd。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM