mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-17 08:13:02 +00:00
Java: Fix syntax error handling without error token.
* data/lalr1.java (YYParser::parse): Here. * tests/java.at: Add test case.
This commit is contained in:
committed by
Akim Demaille
parent
bbaf618c3e
commit
e34e97bcd7
@@ -642,7 +642,7 @@ m4_popdef([b4_at_dollar])])dnl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Pop the current state because it cannot handle the error token. */
|
/* Pop the current state because it cannot handle the error token. */
|
||||||
if (yystack.height == 1)
|
if (yystack.height == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
]b4_locations_if([yyerrloc = yystack.locationAt (0);])[
|
]b4_locations_if([yyerrloc = yystack.locationAt (0);])[
|
||||||
|
|||||||
@@ -749,3 +749,69 @@ AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Position']], [1], [ignore])
|
|||||||
AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore])
|
AT_CHECK([[$EGREP -v ' */?\*' YYParser.java | grep 'Location']], [1], [ignore])
|
||||||
|
|
||||||
AT_CLEANUP
|
AT_CLEANUP
|
||||||
|
|
||||||
|
|
||||||
|
# ----------------------------------------------- #
|
||||||
|
# Java syntax error handling without error token. #
|
||||||
|
# ----------------------------------------------- #
|
||||||
|
|
||||||
|
AT_SETUP([Java syntax error handling without error token])
|
||||||
|
|
||||||
|
AT_DATA([[YYParser.y]], [[%language "Java"
|
||||||
|
|
||||||
|
%lex-param { String s }
|
||||||
|
|
||||||
|
%code imports {
|
||||||
|
import java.io.IOException;
|
||||||
|
}
|
||||||
|
|
||||||
|
%code lexer {
|
||||||
|
String Input;
|
||||||
|
int Position;
|
||||||
|
|
||||||
|
public YYLexer (String s)
|
||||||
|
{
|
||||||
|
Input = s;
|
||||||
|
Position = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void yyerror (String s)
|
||||||
|
{
|
||||||
|
System.err.println (s);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getLVal ()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int yylex () throws IOException
|
||||||
|
{
|
||||||
|
if (Position >= Input.length ())
|
||||||
|
return EOF;
|
||||||
|
else
|
||||||
|
return Input.charAt (Position++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%code {
|
||||||
|
public static void main (String args []) throws IOException
|
||||||
|
{
|
||||||
|
YYParser p = new YYParser (args [0]);
|
||||||
|
p.parse ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%%
|
||||||
|
input:
|
||||||
|
'a' 'a'
|
||||||
|
;
|
||||||
|
]])
|
||||||
|
AT_BISON_CHECK([[YYParser.y]])
|
||||||
|
AT_JAVA_COMPILE([[YYParser.java]])
|
||||||
|
AT_JAVA_PARSER_CHECK([[YYParser aa]], [[0]], [[]], [[]])
|
||||||
|
AT_JAVA_PARSER_CHECK([[YYParser ab]], [[0]], [[]], [[syntax error
|
||||||
|
]])
|
||||||
|
AT_JAVA_PARSER_CHECK([[YYParser ba]], [[0]], [[]], [[syntax error
|
||||||
|
]])
|
||||||
|
|
||||||
|
AT_CLEANUP
|
||||||
|
|||||||
Reference in New Issue
Block a user