LookAhead 在 JFlex 中不起作用
我正在尝试使用 JFlex 构建解析器,但遇到一个非常基本的问题。 我想要拥有这个令牌
[A-Za-z]+_N$ { System.out.println("Noun"); }
并让它将“car_N”识别为“名词”而不识别“car_NN”。 但它不起作用,如果我使用
[A-Za-z]+_N { System.out.println("Noun"); }
“car_N”得到识别,但“car_NN”也返回“car_N”,这不是我想要的。
我想知道这里有人知道如何提供帮助吗?
JFlex 和 Flex 前瞻符号“$”似乎不起作用
I am trying to use JFlex to build a parser but encounter a very basic issue.
I want to have this token
[A-Za-z]+_N$ { System.out.println("Noun"); }
and have it recognize "car_N" as a "Noun" and NOT recognize "car_NN".
but it does not work, if I use
[A-Za-z]+_N { System.out.println("Noun"); }
"car_N" get recognize but "car_NN" returns "car_N" as well, this is not what I want.
I wonder anyone here knows how to help?
JFlex and Flex lookahead symbol '$' does not seem to be working
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您误解了“$”的含义。作为前瞻,它仅在文本行的末尾匹配(硬换行)。因此它工作得很好。但它无法区分 car_N 和 car_NN,除了位于行最末端的 car_N 实例。也许你真的想要一个像这样的前瞻:
I think you're misunderstanding the meaning of '$'. As a lookahead, it matches only at the end of a line of text (hard-line break). As such it works perfectly fine. But it cannot differentiate between car_N and car_NN, except for instances of car_N that are at the very end of a line. Maybe you really want a lookahead something like: