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
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: