Flex:无法识别的规则`(?s:.)`

Flex: unrecognized rule `(?s:.)`

在我的 flex 程序中,我无法使用任何这些正则表达式。使用其中任何一个都会产生 unrecognized rule 错误。

%{
#include<stdio.h>
%}

%option nodefault
%option noyywrap
%option outfile="scanner.c"

%%

(?i:a) printf("rule1");

(?s:.) printf("rule2");

(?x:a b) printf("rule3");

(?#foo) printf("rule4");

[a-z]{-}[aeiou] printf("rule5");

%%

所有这些在 this 文档中都有明确定义。我很困惑,我是否使用了错误的 flex 变体!我正在使用 windows 机器和 GnuWin32 flex v2.5.4.

这是正在生成的错误:

$flex misc/test_lexer.l
"misc/test_lexer.l", line 11: unrecognized rule
"misc/test_lexer.l", line 11: unrecognized rule
"misc/test_lexer.l", line 11: unrecognized rule
"misc/test_lexer.l", line 11: unrecognized rule
"misc/test_lexer.l", line 11: unrecognized rule
"misc/test_lexer.l", line 11: unrecognized rule
"misc/test_lexer.l", line 13: unrecognized rule
"misc/test_lexer.l", line 13: unrecognized rule
"misc/test_lexer.l", line 13: unrecognized rule
"misc/test_lexer.l", line 13: unrecognized rule
"misc/test_lexer.l", line 13: unrecognized rule
"misc/test_lexer.l", line 13: unrecognized rule
"misc/test_lexer.l", line 15: unrecognized rule
"misc/test_lexer.l", line 15: unrecognized rule
"misc/test_lexer.l", line 15: unrecognized rule
"misc/test_lexer.l", line 15: unrecognized rule
"misc/test_lexer.l", line 15: unrecognized rule
"misc/test_lexer.l", line 17: unrecognized rule
"misc/test_lexer.l", line 17: unrecognized rule
"misc/test_lexer.l", line 17: unrecognized rule
"misc/test_lexer.l", line 17: unrecognized rule
"misc/test_lexer.l", line 17: unrecognized rule
"misc/test_lexer.l", line 17: unrecognized rule
"misc/test_lexer.l", line 17: unrecognized rule
"misc/test_lexer.l", line 19: unrecognized rule
"misc/test_lexer.l", line 19: unrecognized rule
"misc/test_lexer.l", line 19: unrecognized rule
"misc/test_lexer.l", line 19: unrecognized rule
"misc/test_lexer.l", line 19: unrecognized rule
"misc/test_lexer.l", line 19: unrecognized rule
"misc/test_lexer.l", line 19: unrecognized rule
"misc/test_lexer.l", line 19: unrecognized rule
"misc/test_lexer.l", line 19: unrecognized rule
"misc/test_lexer.l", line 19: unrecognized rule

如果您想使用这些结构,您需要更新您的 flex 安装。

25 年前发布的 Flex 2.5.4 没有实现 {-} 也没有实现任何 (?:...) 语法。

您引用的手册(也不是当前版本)指定:

This edition of The flex Manual documents flex version 2.6.3. It was last updated on 13 January 2017.

Flex v2.5.4 确实实现了 / 尾随上下文运算符,它在这个问题的原始版本中。但请注意 / 不能在括号内使用,并且由于 flex 通常在宏扩展周围添加括号,因此 / 也不能在宏扩展中使用。