[kaffe] Bug report (java.io.StreamTokenizer)
Ito Kazumitsu
ito.kazumitsu@hitachi-cable.co.jp
Mon Jun 30 03:06:01 2003
Hi,
In message "Re: [kaffe] Bug report (java.io.StreamTokenizer)"
on 03/06/30, Hermanni Hyyti=E4l=E4 <hemppah@cc.jyu.fi> writes:
> According to the JLS (first edition), the nextToken-method of
> java.io.StreamTokenizer class has the following lexical order:
>=20
> whitespace
> numeric character
> alphabetic character
> comment character
> string quote character
> comment //
> comment /*
I see. But this rule seems to have been ignored even by
Sun's implementation.
(1) Kaffe's java.io.StreamTokenizer.java has this comment:
/* Contrary to the description in JLS 1.ed,
C & C++ comments seem to be checked
before other comments. That actually
make sense, since the default comment
character is '/'.
*/
(2) Comment characters must be checked before alphabetic characters
and Sun's java.io.StreamTokenizer seems to do so. Otherwise,
NBIO you mentioned cannot run properly.
> Yet, however, I haven't tested if this parsing order changes the
> behaviour of Kaffe's java.io.StringTokenizer's behaviour (could someone
> test it ?-)).
I wrote a simple program to test with Sun's JDK and kaffe with and
without my patch.
import java.io.*;
public class StreamTokenizerTest {
public static void main(String[] args) throws Exception {
StreamTokenizer tok =3D new StreamTokenizer(System.in);
if (args[0].equals("NBIO")) {
tok =3D new StreamTokenizer(System.in);
tok.resetSyntax();
tok.wordChars((char)0, (char)255);
tok.whitespaceChars('\u0000', '\u0020');
tok.commentChar('#');
tok.eolIsSignificant(true);
}
System.out.println("TT_WORD =3D " + StreamTokenizer.TT_WORD);
System.out.println("TT_NUMBER =3D " + StreamTokenizer.TT_NUMBER);
System.out.println("TT_EOF =3D " + StreamTokenizer.TT_EOL);
System.out.println("TT_EOF =3D " + StreamTokenizer.TT_EOF);
while (true) {
int t =3D tok.nextToken();
System.out.println(tok.sval + ": " + t);
if (t =3D=3D StreamTokenizer.TT_EOF) break;
}
}
}
Sun's JDK:
bash$ echo "# comment" |java StreamTokenizerTest NBIO
TT_WORD =3D -3
TT_NUMBER =3D -2
TT_EOF =3D 10
TT_EOF =3D -1
null: 10
null: -1
Kaffe without my patch:
$ echo "# comment" |java StreamTokenizerTest NBIO
TT_WORD =3D -3
TT_NUMBER =3D -2
TT_EOF =3D 10
TT_EOF =3D -1
#: -3
comment: -3
comment: 10
null: -1
Kaffe with my patch gives the same result as Sun's.
$ echo "# comment" |java StreamTokenizerTest NBIO
TT_WORD =3D -3
TT_NUMBER =3D -2
TT_EOF =3D 10
TT_EOF =3D -1
null: 10
null: -1