Work around Java's ``code too large'' problem for parser tables.

* data/java.m4 (b4_typed_parser_table, b4_integral_parser_table): New.
* data/lalr1.java (yypact_, yydefact_, yypgoto_, yydefgoto_,
yytable_, yycheck_, yystos_, yytoken_number_, yyr1_, yyr2_, yyrhs_
yyprhs_, yyrline_, yytranslate_table_): Use b4_integral_parser_table.
(yytname_): Use b4_typed_parser_table.
* doc/bison.texinfo (Java Bison Interface): Add note on Java's
``code too large'' error.
This commit is contained in:
Di-an Jan
2008-11-10 14:34:36 +01:00
committed by Paolo Bonzini
parent 1979121c96
commit 09ccae9b18
4 changed files with 52 additions and 67 deletions

View File

@@ -1,3 +1,15 @@
2008-11-10 Di-an Jan <dianj@freeshell.org>
Workaround Java's ``code too large'' problem for parser tables
in most cases, by using one function per initialization.
* data/java.m4 (b4_typed_parser_table, b4_integral_parser_table): New.
* data/lalr1.java (yypact_, yydefact_, yypgoto_, yydefgoto_,
yytable_, yycheck_, yystos_, yytoken_number_, yyr1_, yyr2_, yyrhs_
yyprhs_, yyrline_, yytranslate_table_): Use b4_integral_parser_table.
(yytname_): Use b4_typed_parser_table.
* doc/bison.texinfo (Java Bison Interface): Add note on Java's
``code too large'' error.
2008-11-10 Di-an Jan <dianj@freeshell.org>
* NEWS: Document them.

View File

@@ -117,6 +117,25 @@ m4_define([b4_int_type_for],
m4_define([b4_null], [null])
# b4_typed_parser_table(TYPE, NAME, DATA)
# ---------------------------------------
m4_define([b4_typed_parser_table],
[[private static final ]$1[ $2[] = $2init();
private static final ]$1[[] $2init()
{
return new ]$1[[]
{
]$3[
};
}]])
# b4_integral_parser_table(NAME, DATA)
#-------------------------------------
m4_define([b4_integral_parser_table],
[b4_typed_parser_table([b4_int_type_for([$2])], [$1], [$2])])
## ------------------------- ##
## Assigning token numbers. ##
## ------------------------- ##

View File

@@ -762,104 +762,55 @@ m4_popdef([b4_at_dollar])])dnl
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
private static final ]b4_int_type_for([b4_pact])[ yypact_ninf_ = ]b4_pact_ninf[;
private static final ]b4_int_type_for([b4_pact])[ yypact_[] =
{
]b4_pact[
};
]b4_integral_parser_table([yypact_], [b4_pact])[
/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
doesn't specify something else to do. Zero means the default is an
error. */
private static final ]b4_int_type_for([b4_defact])[ yydefact_[] =
{
]b4_defact[
};
]b4_integral_parser_table([yydefact_], [b4_defact])[
/* YYPGOTO[NTERM-NUM]. */
private static final ]b4_int_type_for([b4_pgoto])[ yypgoto_[] =
{
]b4_pgoto[
};
]b4_integral_parser_table([yypgoto_], [b4_pgoto])[
/* YYDEFGOTO[NTERM-NUM]. */
private static final ]b4_int_type_for([b4_defgoto])[
yydefgoto_[] =
{
]b4_defgoto[
};
]b4_integral_parser_table([yydefgoto_], [b4_defgoto])[
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
positive, shift that token. If negative, reduce the rule which
number is the opposite. If zero, do what YYDEFACT says. */
private static final ]b4_int_type_for([b4_table])[ yytable_ninf_ = ]b4_table_ninf[;
private static final ]b4_int_type_for([b4_table])[
yytable_[] =
{
]b4_table[
};
]b4_integral_parser_table([yytable_], [b4_table])[
/* YYCHECK. */
private static final ]b4_int_type_for([b4_check])[
yycheck_[] =
{
]b4_check[
};
]b4_integral_parser_table([yycheck_], [b4_check])[
/* STOS_[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */
private static final ]b4_int_type_for([b4_stos])[
yystos_[] =
{
]b4_stos[
};
]b4_integral_parser_table([yystos_], [b4_stos])[
/* TOKEN_NUMBER_[YYLEX-NUM] -- Internal symbol number corresponding
to YYLEX-NUM. */
private static final ]b4_int_type_for([b4_toknum])[
yytoken_number_[] =
{
]b4_toknum[
};
]b4_integral_parser_table([yytoken_number_], [b4_toknum])[
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
private static final ]b4_int_type_for([b4_r1])[
yyr1_[] =
{
]b4_r1[
};
]b4_integral_parser_table([yyr1_], [b4_r1])[
/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
private static final ]b4_int_type_for([b4_r2])[
yyr2_[] =
{
]b4_r2[
};
]b4_integral_parser_table([yyr2_], [b4_r2])[
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at \a yyntokens_, nonterminals. */
private static final String yytname_[] =
{
]b4_tname[
};
]b4_typed_parser_table([String], [yytname_], [b4_tname])[
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
private static final ]b4_int_type_for([b4_rhs])[ yyrhs_[] =
{
]b4_rhs[
};
]b4_integral_parser_table([yyrhs_], [b4_rhs])[
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
YYRHS. */
private static final ]b4_int_type_for([b4_prhs])[ yyprhs_[] =
{
]b4_prhs[
};
]b4_integral_parser_table([yyprhs_], [b4_prhs])[
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
private static final ]b4_int_type_for([b4_rline])[ yyrline_[] =
{
]b4_rline[
};
]b4_integral_parser_table([yyrline_], [b4_rline])[
// Report on the debug stream that the rule yyrule is going to be reduced.
private void yy_reduce_print (int yyrule, YYStack yystack)
@@ -882,10 +833,7 @@ m4_popdef([b4_at_dollar])])dnl
}
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
private static final ]b4_int_type_for([b4_translate])[ yytranslate_table_[] =
{
]b4_translate[
};
]b4_integral_parser_table([yytranslate_table_], [b4_translate])[
private static final ]b4_int_type_for([b4_translate])[ yytranslate_ (int t)
{

View File

@@ -8854,6 +8854,12 @@ if needed. Also, in the future the
@code{%token-table} directive might enable a public interface to
access the token names and codes.
Getting a ``code too large'' error from the Java compiler means the code
hit the 64KB bytecode per method limination of the Java class file.
Try reducing the amount of code in actions and static initializers;
otherwise, report a bug so that the parser skeleton will be improved.
@node Java Semantic Values
@subsection Java Semantic Values
@c - No %union, specify type in %type/%token.