X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/e0e2b93355c0f02cb0b2a669fd8863056e8ce90c..813f7d34824153ac3259fdd34fce5710d3b7606c:/tests/java.at diff --git a/tests/java.at b/tests/java.at index e16701df..f822ec6e 100644 --- a/tests/java.at +++ b/tests/java.at @@ -32,6 +32,7 @@ AT_BANNER([[Java Calculator.]]) m4_define([_AT_DATA_JAVA_CALC_Y], [m4_if([$1$2$3], $[1]$[2]$[3], [], [m4_fatal([$0: Invalid arguments: $@])])dnl +AT_BISON_OPTION_PUSHDEFS([%language "Java" $4]) AT_DATA([Calc.y], [[/* Infix notation calculator--calc */ %language "Java" @@ -122,20 +123,8 @@ AT_LOCATION_IF([[ public Position getEndPos() { return yypos; } - - public void yyerror (Calc.Location l, String s) - { - if (l == null) - System.err.println (s); - else - System.err.println (l + ": " + s); - } -]], [[ - public void yyerror (String s) - { - System.err.println (s); - } ]])[ + ]AT_YYERROR_DEFINE[ Integer yylval; @@ -211,11 +200,12 @@ class Position { } ]]) +AT_BISON_OPTION_POPDEFS ])# _AT_DATA_JAVA_CALC_Y # AT_DATA_CALC_Y([BISON-OPTIONS]) -# ------------------------------------------------- +# ------------------------------- # Produce `calc.y'. m4_define([AT_DATA_JAVA_CALC_Y], [_AT_DATA_JAVA_CALC_Y($[1], $[2], $[3], [$1]) @@ -224,7 +214,7 @@ m4_define([AT_DATA_JAVA_CALC_Y], # _AT_CHECK_JAVA_CALC_ERROR(BISON-OPTIONS, INPUT, # [VERBOSE-AND-LOCATED-ERROR-MESSAGE]) -# --------------------------------------------------------- +# -------------------------------------------------------------- # Run `calc' on INPUT, and expect a `syntax error' message. # # If INPUT starts with a slash, it is used as absolute input file name, @@ -749,3 +739,69 @@ 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" + +%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