Flex似乎不支持正则表达式前瞻断言(快速lex分析器) [英] Flex seems do not support a regex lookahead assertion (the fast lex analyzer)

查看:101
本文介绍了Flex似乎不支持正则表达式前瞻断言(快速lex分析器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试如下在flex中使用regex来定义int类型时:

When I tried to use regex in flex as following to define an int type:

int    (?<!\w)(([1-9]\d*)|0)(?!\w)

我想使它无效:

int a = 123;
int b = 123f; //the '123' should not filtered as an int type

但是,我得到了:

bad character: <
bad character: !
bad character: \
...

此外,似乎正则表达式中的?被忽略了. 我很困惑. flex不支持前瞻性断言(?<=xxx)(?<!xxx)吗?

What's more, it seems that the ? in the regex was ignored. I got confused. Does flex not support the lookahead assertion (?<=xxx) or (?<!xxx) ?

我是flex的新手,我真的需要一些帮助

I am new in flex, I really need some help

推荐答案

是正确的. Flex不支持否定的超前断言.尽管它确实允许使用posix样式的字符类([[:alpha:]][[:digit:]][[:alnum:]]等),但它也不支持\w\d

That's correct. Flex does not support negative lookahead assertions. It also does not support \w or \d, although it does allow posix-style character classes ([[:alpha:]], [[:digit:]], [[:alnum:]], etc.)

Flex正则表达式与类似javascript或类似于perl/python的"regular"表达式完全不同.一方面,flex的正则表达式实际上是正则表达式.

Flex regular expressions are quite different from javascript-like or perl/python-like "regular" expressions. For one thing, flex's regular expressions are really regular.

flex允许使用的语法的完整列表在 flex手册中.手册的该部分中未描述的任何内容都不会由flex实施.

A complete list of the syntaxes flex allows is in the flex manual. Anything not described in that section of the manual is not implemented by flex.

使用flex的"lookbehind"几乎没有意义,因为flex总是匹配当前输入点上最长的令牌 .它不会在输入中搜索模式.

There is very little point using "lookbehind" with flex, because flex always matches the longest token at the current input point. It does not search the input for a pattern.

Flex 使用/运算符(不是我所知道的任何正则表达式库的一部分)实现有限形式的正向超前.不能立即跟在字母后面的数字:

Flex does implement a limited form of positive lookahead, using the / operator (which is not part of any regular expression library I know of.) You could use that to only match a sequence of digits not immediately followed by a letter:

[[:digit:]]+/[^[:alpha:]]

但是您将需要一些与数字序列和字母字符匹配的模式,因为flex不会搜索匹配的令牌.

But you'll then need some pattern which does match the sequence of digits followed by an alphabetic character, because flex does not search for a matching token.

这篇关于Flex似乎不支持正则表达式前瞻断言(快速lex分析器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆