Hi,

given the attached grammar, the generated parser throws
java.lang.ArrayIndexOutOfBoundsException if the first token
leads to a syntax error:

| [tim@passepartout ~/src/bison-2.5]$ src/bison --version
| bison (GNU Bison) 2.5
| Written by Robert Corbett and Richard Stallman.

| Copyright (C) 2011 Free Software Foundation, Inc.
| This is free software; see the source for copying conditions.  There is NO
| warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
| [tim@passepartout ~/src/bison-2.5]$ BISON_PKGDATADIR=data src/bison 
java-test.y
| [tim@passepartout ~/src/bison-2.5]$ gcj -o java-test --main=YYParser 
java-test.java
| java-test.java:247: warning: The field YYParser.YYRETURN is never read locally
|         private static final int YYRETURN = 8;
|                                  ^^^^^^^^
| java-test.java:380: warning: The local variable yyresult is never read
|         int yyresult;
|             ^^^^^^^^
| java-test.java:745: warning: The field YYParser.yytoken_number_ is never read 
locally
|         yytoken_number_[] =
|         ^^^^^^^^^^^^^^^
| java-test.java:849: warning: The field YYParser.yynnts_ is never read locally
|         private static final int yynnts_ = 2;
|                                  ^^^^^^^
| java-test.java:853: warning: The field YYParser.yyerrcode_ is never read 
locally
|         private static final int yyerrcode_ = 256;
|                                  ^^^^^^^^^^
| 5 problems (5 warnings)
| [tim@passepartout ~/src/bison-2.5]$ ./java-test --
| [tim@passepartout ~/src/bison-2.5]$ ./java-test -+
| syntax error
| [tim@passepartout ~/src/bison-2.5]$ ./java-test +-
| syntax error
| Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
|    at YYParser$YYStack.stateAt(java-test)
|    at YYParser.parse(java-test)
|    at YYParser.main(java-test)
| [tim@passepartout ~/src/bison-2.5]$

This bug also shows up in HEAD.

  There is a test for syntax errors on the first token in
tests/java.at, but apparently only in combination with an
"error" token.  I hope fixing it is easier than isolating
it was :-).

Tim

Attachment: java-test.y
Description: Binary data

Reply via email to