简体   繁体   English

LookAhead无法在JFlex中运行

[英]LookAhead not working in JFlex

I am trying to use JFlex to build a parser but encounter a very basic issue. 我试图使用JFlex来构建解析器但遇到一个非常基本的问题。 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". 并将它识别为“car_N”作为“名词”而不识别“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. “car_N”得到识别,但“car_NN”也返回“car_N”,这不是我想要的。

I wonder anyone here knows how to help? 我想知道这里有谁知道如何帮助?

JFlex and Flex lookahead symbol '$' does not seem to be working JFlex和Flex前瞻符号'$'似乎不起作用

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. 但是,除了在行尾的car_N实例外,它无法区分car_N和car_NN。 Maybe you really want a lookahead something like: 也许你真的想要一个前瞻性的东西:

[A-Za-z]+_N/[^A-Za-z]

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

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