java: lac: a stronger test for the exploratory stack

* tests/local.at (AT_YYLEX_DEFINE(java)): Fix overquoting issue.
Style changes.
* tests/regression.at (LAC: Exploratory stack): Run for lalr1.java too.
This commit is contained in:
Akim Demaille
2020-11-06 07:19:47 +01:00
parent fa8aca1ed4
commit d49da0101a
4 changed files with 35 additions and 18 deletions

3
TODO
View File

@@ -1,4 +1,7 @@
* Soon * Soon
** yyerrok in Java
And add tests in calc.at, to prepare work for D.
** YYERROR and yynerrs ** YYERROR and yynerrs
We are missing some cases. Write a test case, and check all the skeletons. We are missing some cases. Write a test case, and check all the skeletons.

View File

@@ -440,7 +440,7 @@ AT_DATA_GRAMMAR([input.y],
]$2[ ]$2[
]AT_JAVA_IF([[%code lexer { ]AT_JAVA_IF([[%code lexer {
]AT_YYLEX_DEFINE([$3], [[return new Integer(1)]])[ ]AT_YYLEX_DEFINE(["$3"], [[return new Integer(1)]])[
]AT_YYERROR_DEFINE[ ]AT_YYERROR_DEFINE[
}; };
%% %%

View File

@@ -1036,30 +1036,27 @@ m4_define([AT_YYLEX_DEFINE(java)],
| yylex. | | yylex. |
`--------*/ `--------*/
public String input = "]$1["; public String input = ]$1[;
public int index = 0; public int index = 0;
public int yylex () public int yylex() {
{ if (index < input.length())
if (index < input.length ()) return input.charAt(index++);
return input.charAt (index++);
else else
return 0; return 0;
} }
public Object getLVal () public Object getLVal() {
{ ]m4_ifval([$2], [$2], [return null])[;
]$2[;
} }
]]) ]])
m4_define([AT_MAIN_DEFINE(java)], m4_define([AT_MAIN_DEFINE(java)],
[[class input [[class input
{ {
public static void main (String[] args) throws IOException public static void main(String[] args) throws IOException {
{ ]AT_API_prefix[Parser p = new ]AT_API_prefix[Parser();
]AT_API_prefix[Parser p = new ]AT_API_prefix[Parser (); boolean success = p.parse();
boolean success = p.parse ();
if (!success) if (!success)
System.exit (1); System.exit(1);
} }
}]]) }]])

View File

@@ -1341,11 +1341,21 @@ m4_pushdef([AT_LAC_CHECK], [
AT_BISON_OPTION_PUSHDEFS([%debug $1]) AT_BISON_OPTION_PUSHDEFS([%debug $1])
AT_DATA_GRAMMAR([input.y], AT_DATA_GRAMMAR([input.y],
[AT_JAVA_IF([[%code imports {
import java.io.IOException;
}
%code lexer {
]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["bbbbc"])[
};
]],
[[%code { [[%code {
#include <stdio.h> /* printf */ #include <stdio.h> /* printf */
]AT_YYERROR_DECLARE[ ]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[ ]AT_YYLEX_DECLARE[
} }
]])[
%debug %debug
]$1[ ]$1[
%define parse.error verbose %define parse.error verbose
@@ -1359,13 +1369,15 @@ S: A B A A B A A A A B A A A A A A A B C C A A A A A A A A A A A A B ;
// ^ ^ ^ // ^ ^ ^
// LAC reallocs // LAC reallocs
A: 'a' | %empty { printf ("inconsistent default reduction\n"); } ; A: 'a' | %empty { ]AT_JAVA_IF([System.out.print], [printf])[ ("inconsistent default reduction\n"); } ;
B: 'b' ; B: 'b' ;
C: %empty { printf ("consistent default reduction\n"); } ; C: %empty { ]AT_JAVA_IF([System.out.print], [printf])[ ("consistent default reduction\n"); } ;
%% %%
]AT_YYERROR_DEFINE[ ]AT_JAVA_IF([], [[
]AT_YYLEX_DEFINE(["bbbbc"])[ ]AT_YYERROR_DEFINE[
]AT_YYLEX_DEFINE(["bbbbc"])[
]])[
]AT_MAIN_DEFINE[ ]AT_MAIN_DEFINE[
]]) ]])
@@ -1402,13 +1414,18 @@ AT_PERL_CHECK([[-0777 -ne 'print s/\bconsistent default reduction//g;' stdout.tx
AT_BISON_OPTION_POPDEFS AT_BISON_OPTION_POPDEFS
]) ])
# C.
AT_LAC_CHECK([[%define api.push-pull pull]]) AT_LAC_CHECK([[%define api.push-pull pull]])
AT_LAC_CHECK([[%define api.push-pull pull %define api.pure]]) AT_LAC_CHECK([[%define api.push-pull pull %define api.pure]])
AT_LAC_CHECK([[%define api.push-pull both]]) AT_LAC_CHECK([[%define api.push-pull both]])
AT_LAC_CHECK([[%define api.push-pull both %define api.pure]]) AT_LAC_CHECK([[%define api.push-pull both %define api.pure]])
# C++.
AT_LAC_CHECK([[%skeleton "lalr1.cc"]]) AT_LAC_CHECK([[%skeleton "lalr1.cc"]])
# Java.
AT_LAC_CHECK([[%skeleton "lalr1.java"]])
m4_popdef([AT_LAC_CHECK]) m4_popdef([AT_LAC_CHECK])
AT_CLEANUP AT_CLEANUP