[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Java parser throws ArrayIndexOutOfBoundsException if first token lea
From: |
Tim Landscheidt |
Subject: |
Re: Java parser throws ArrayIndexOutOfBoundsException if first token leads to syntax error |
Date: |
Thu, 23 Feb 2012 17:48:54 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
Akim Demaille <address@hidden> wrote:
>>> [...]
>>> 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 :-).
>> Nope. Anyway, attached is the fix. The test case is a bit
>> non-hackily lengthy, but I did not want to interlace it in
>> the existing suite and subtly break half of them in the
>> process.
> Thanks for this!
> [...]
While the assignment form is somewhere over the ocean, I re-
indented and -wrote the test case a bit to bring it more in
line with the other code and added TABs to the commit mes-
sage. Is this "ready-to-commit"?
Also on this topic: Are there useful Emacs tidbits and/or
git hooks to format and check commit messages?
Tim
>From d710c2ae6cbb100186b179eba67aad003402bb07 Mon Sep 17 00:00:00 2001
From: Tim Landscheidt <address@hidden>
Date: Sun, 12 Feb 2012 01:29:41 +0000
Subject: [PATCH] Java: Fix syntax error handling without error token.
* data/lalr1.java (YYParser::parse): Here.
* tests/java.at: Add test case.
---
data/lalr1.java | 2 +-
tests/java.at | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+), 1 deletions(-)
diff --git a/data/lalr1.java b/data/lalr1.java
index 57ff993..a40d6c2 100644
--- a/data/lalr1.java
+++ b/data/lalr1.java
@@ -686,7 +686,7 @@ m4_popdef([b4_at_dollar])])dnl
}
/* Pop the current state because it cannot handle the error token.
*/
- if (yystack.height == 1)
+ if (yystack.height == 0)
return false;
]b4_locations_if([yyerrloc = yystack.locationAt (0);])[
diff --git a/tests/java.at b/tests/java.at
index b3e79e9..1c38b7b 100644
--- a/tests/java.at
+++ b/tests/java.at
@@ -781,3 +781,65 @@ AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep
'Position']], [1], [ignore])
AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore])
AT_CLEANUP
+
+
+# ----------------------------------------------- #
+# Java syntax error handling without error token. #
+# ----------------------------------------------- #
+
+AT_SETUP([Java syntax error handling without error token])
+
+AT_DATA([[YYParser.y]], [[%language "Java"
+
+%code imports {
+ import java.io.IOException;
+}
+
+%code lexer {
+ public void yyerror (String s)
+ {
+ System.err.println (s);
+ }
+
+ public Object getLVal ()
+ {
+ return null;
+ }
+
+ public int yylex () throws IOException
+ {
+ int b = System.in.read ();
+ if (b == -1)
+ return EOF;
+ else
+ return b;
+ }
+}
+
+%code {
+ public static void main (String args []) throws IOException
+ {
+ YYParser p = new YYParser ();
+ p.parse ();
+ }
+}
+%%
+input:
+ '-' '-' '\n'
+;
+]])
+AT_DATA([[input1.txt]], [[--
+]])
+AT_DATA([[input2.txt]], [[-+
+]])
+AT_DATA([[input3.txt]], [[+-
+]])
+AT_BISON_CHECK([[YYParser.y]])
+AT_JAVA_COMPILE([[YYParser.java]])
+AT_JAVA_PARSER_CHECK([[YYParser < input1.txt]], [[0]], [[]], [[]])
+AT_JAVA_PARSER_CHECK([[YYParser < input2.txt]], [[0]], [[]], [[syntax error
+]])
+AT_JAVA_PARSER_CHECK([[YYParser < input3.txt]], [[0]], [[]], [[syntax error
+]])
+
+AT_CLEANUP
--
1.6.2.5