我已经写了规则,但我不明白为什么欲望规则不匹配,因为文档是这样说的:
When the generated scanner is run, it analyzes its input looking for strings
which match any of its patterns. If it finds more than one match, it takes the
one matching the most text (for trailing context rules, this includes the length
of the trailing part, even though it will then be returned to the input). If it
finds two or more matches of the same length, the rule listed first in the flex
input file is chosen.
我也看到了这个答案,但没有帮助:是否可以为规则设置优先级以避免“最早”匹配模式?
...
ANY_CHAR .
...
%%
"gago" { BEGIN V_TYPE; }
<V_TYPE>"If" { printf("print If"); exit(1);}
<V_TYPE>"Then" { printf("print Then"); exit(1);}
<V_TYPE>"Endif" { printf("print Endif"); exit(1);}
<V_TYPE>"While" { printf("print While"); exit(1);}
<V_TYPE>"EndWhile" { printf("print EndWhile"); exit(1);}
<V_TYPE>{ANY_CHAR}* { printf("print Other"); exit(1);}
简单输入:
gago
EndWhile
期望的输出:
print EndWhile
实际输出:
print Other