I 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. Tim
>From 415333112ba8224264d75164628ca1a173ffb514 Mon Sep 17 00:00:00 2001 From: Tim Landscheidt <[email protected]> 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 | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 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..b8279d1 100644 --- a/tests/java.at +++ b/tests/java.at @@ -781,3 +781,70 @@ 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 + { + public static void main (String args []) throws IOException + { + YYParser p = new YYParser (new YYLexer (args [0])); + p.parse (); + } + } + +%% +input: + '-' '-' +; +%% +class YYLexer implements YYParser.Lexer + { + int pos = 0; + String s; + + public YYLexer (String ps) + { + s = ps; + } + + public void yyerror (String s) + { + System.err.println (s); + } + + public Object getLVal () + { + return null; + } + + public int yylex () + { + if (pos >= s.length ()) + return YYParser.Lexer.EOF; + else + return s.charAt (pos++); + } + } +]]) +AT_BISON_CHECK([[YYParser.y]]) +AT_JAVA_COMPILE([[YYParser.java]]) +AT_JAVA_PARSER_CHECK([[YYParser --]], [[0]], [[]], [[]]) +AT_JAVA_PARSER_CHECK([[YYParser -+]], [[0]], [[]], [[syntax error +]]) +AT_JAVA_PARSER_CHECK([[YYParser +-]], [[0]], [[]], [[syntax error +]]) + +AT_CLEANUP -- 1.6.2.5
