0

Does anybody know how to handle '\0' in java JFlex?? I tried encoding as a regular expression to be matched like

\0 { /* DO nothing */ }

but it did not work. The documentation does not provide any information. The reason I need this is because I am handling some strings coming from a C/C++ source.

Regards.

leco
  • 1,989
  • 16
  • 30
  • Hmmm... not so sure about that. yylex is configured to return an int, and upon EOF, it returns -1; the NUL character I mentioned in here is different, as its code is 0 (see wiki entry: http://en.wikipedia.org/wiki/Null_character) – leco Nov 06 '13 at 14:19

2 Answers2

2

All of the following worked for me (using trunk JFlex, soon to be released as v1.5):

  • \0
  • "\0"
  • \u0000
  • "\u0000"

How do you know it did not work? It's possible there was an earlier rule in your grammar that matches the null character, in which case the \0 rule will never match (though if that's true, you should get a warning to this effect when you generate your scanner with JFlex).

Steve Rowe
  • 136
  • 4
-2

According to the manual it should be '\0'.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • This is according to the lex manual, right? Jflex, the java correspondent version of lex, does not mention it (where did you find that reference??). I have tried using '\0' (as stated in my original question), but that did not work. – leco Nov 08 '13 at 19:14
  • 1
    No, you used \0, no quotes. I've provided the link. – user207421 Nov 08 '13 at 23:50
  • The link concerns flex, not jflex (the first is for C/C++, the second for Java; moreover, jflex is not fully compatible with lex). The proposed solution does not work, as putting ' to surround a single character in jflex is the same as omitting, given the problem at hand. – leco Nov 09 '13 at 00:57