Hi Ulf,
you need to use %16bit or %unicode instead of %8bit.
Java represents characters internally as unicode and 0xFF is apparently mapped
to 711 in the character encoding that is used.
Cheers,
Gerwin
Ulf Dittmer wrote:
> Hello-
>
> I'm trying to handle a file that contains the character hex FF, but that results in an exception:
> Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 711
> at JFlex_problem.yylex(JFlex_problem.java:503)
> at JFlex_problem.main(JFlex_problem.java:237)
>
> 711 is the value of the zzInput variable, which is used as an index into an array of length 256.
>
> I thought declaring the parser as "8bit" should be sufficient to handle just about everything; am I missing something? I'm appending a minimal jflex file that exhibits the problem below. I'd be grateful on any clues on how to handle that character.
>
> Thanks in advance,
> Ulf
>
>
>
> import java.io.*;
>
> %%
>
> %public
> %class JFlex_problem
> %8bit
> %int
> %apiprivate
>
> %{
> public JFlex_problem() { }
>
> public static void main (String args[]) throws Exception {
> if (args == null) {
> System.err.println("usage: java JFlex_problem file");
> System.exit(1);
> }
> JFlex_problem self = new JFlex_problem();
> self.zzReader = new FileReader(args[0]);
> while ( !self.zzAtEOF ) self.yylex();
> }
>
> %}
>
> %%
>
> <YYINITIAL> {
> . {
> System.out.println("read char: "+(int)yytext().charAt(0));
> }
> }
>
> .|\n {
> /* ignore every character that's not recognizably part of a command */
> System.out.println("ignoring char: "+(int)yytext().charAt(0));
> }
>
>
>
>
>
> ------------------------------------------------------------------------------
> Enter the BlackBerry Developer Challenge
> This is your chance to win up to $100,000 in prizes! For a limited time,
> vendors submitting new applications to BlackBerry App World(TM) will have
> the opportunity to enter the BlackBerry Developer Challenge. See full prize
> details at: http://p.sf.net/sfu/Challenge
> --
> jflex-users mailing list
> https://lists.sourceforge.net/lists/listinfo/jflex-users
|