mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 08:43:03 +00:00
style: comment changes in the skeletons
* data/skeletons/lalr1.cc: Prepare for Java's LAC. * data/skeletons/lalr1.java: Style fixes.
This commit is contained in:
@@ -346,12 +346,14 @@ and [Google Java Style
|
|||||||
Guide](https://google.github.io/styleguide/javaguide.html). Unfortunately
|
Guide](https://google.github.io/styleguide/javaguide.html). Unfortunately
|
||||||
at some point some GNU Coding Style was installed in Java, but it's an
|
at some point some GNU Coding Style was installed in Java, but it's an
|
||||||
error. So we should for instance stop putting spaces in function calls.
|
error. So we should for instance stop putting spaces in function calls.
|
||||||
Because we are standardizing the code, it is currently inconsistent.
|
Because we are standardizing the code, it is currently inconsistent. Treat
|
||||||
|
acronyms as words: `YYLacStack`, not `YYLACStack`.
|
||||||
|
|
||||||
Use a 2-space indentation (Google) rather than 4 (Oracle).
|
Use a 2-space indentation (Google) rather than 4 (Oracle).
|
||||||
|
|
||||||
Don't use the "yy" prefix for public members: "getExpectedTokens", not
|
Don't use the `yy` prefix for public members: `getExpectedTokens`, not
|
||||||
"yyexpectedTokens" or "yygetExpectedTokens".
|
`yyexpectedTokens` or `yygetExpectedTokens`. Keep the `yy` prefix though
|
||||||
|
for private details.
|
||||||
|
|
||||||
## Commit Messages
|
## Commit Messages
|
||||||
Imitate the style we use. Use `git log` to get sources of inspiration.
|
Imitate the style we use. Use `git log` to get sources of inspiration.
|
||||||
|
|||||||
@@ -20,8 +20,7 @@ m4_include(b4_skeletonsdir/[c++.m4])
|
|||||||
# api.value.type=variant is valid.
|
# api.value.type=variant is valid.
|
||||||
m4_define([b4_value_type_setup_variant])
|
m4_define([b4_value_type_setup_variant])
|
||||||
|
|
||||||
# Check the value of %define parse.lac, where LAC stands for lookahead
|
# parse.lac
|
||||||
# correction.
|
|
||||||
b4_percent_define_default([[parse.lac]], [[none]])
|
b4_percent_define_default([[parse.lac]], [[none]])
|
||||||
b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]])
|
b4_percent_define_check_values([[[[parse.lac]], [[full]], [[none]]]])
|
||||||
b4_define_flag_if([lac])
|
b4_define_flag_if([lac])
|
||||||
@@ -851,8 +850,8 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
/// The return value of parse ().
|
/// The return value of parse ().
|
||||||
int yyresult;]b4_lac_if([[
|
int yyresult;]b4_lac_if([[
|
||||||
|
|
||||||
/// Discard the LAC context in case there still is one left from a
|
// Discard the LAC context in case there still is one left from a
|
||||||
/// previous invocation.
|
// previous invocation.
|
||||||
yy_lac_discard_ ("init");]])[
|
yy_lac_discard_ ("init");]])[
|
||||||
|
|
||||||
#if YY_EXCEPTIONS
|
#if YY_EXCEPTIONS
|
||||||
@@ -935,7 +934,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.kind ())
|
if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.kind ())
|
||||||
{]b4_lac_if([[
|
{]b4_lac_if([[
|
||||||
if (!yy_lac_establish_ (yyla.kind ()))
|
if (!yy_lac_establish_ (yyla.kind ()))
|
||||||
goto yyerrlab;]])[
|
goto yyerrlab;]])[
|
||||||
goto yydefault;
|
goto yydefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -946,7 +945,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
if (yy_table_value_is_error_ (yyn))
|
if (yy_table_value_is_error_ (yyn))
|
||||||
goto yyerrlab;]b4_lac_if([[
|
goto yyerrlab;]b4_lac_if([[
|
||||||
if (!yy_lac_establish_ (yyla.kind ()))
|
if (!yy_lac_establish_ (yyla.kind ()))
|
||||||
goto yyerrlab;
|
goto yyerrlab;
|
||||||
]])[
|
]])[
|
||||||
yyn = -yyn;
|
yyn = -yyn;
|
||||||
goto yyreduce;
|
goto yyreduce;
|
||||||
@@ -1442,7 +1441,9 @@ b4_dollar_popdef])[]dnl
|
|||||||
follows. If no initial context is currently established for the
|
follows. If no initial context is currently established for the
|
||||||
current lookahead, then check if that lookahead can eventually be
|
current lookahead, then check if that lookahead can eventually be
|
||||||
shifted if syntactic actions continue from the current context. */
|
shifted if syntactic actions continue from the current context. */
|
||||||
if (!yy_lac_established_)
|
if (yy_lac_established_)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
#if ]b4_api_PREFIX[DEBUG
|
#if ]b4_api_PREFIX[DEBUG
|
||||||
YYCDEBUG << "LAC: initial context established for "
|
YYCDEBUG << "LAC: initial context established for "
|
||||||
@@ -1451,12 +1452,11 @@ b4_dollar_popdef])[]dnl
|
|||||||
yy_lac_established_ = true;
|
yy_lac_established_ = true;
|
||||||
return yy_lac_check_ (yytoken);
|
return yy_lac_check_ (yytoken);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discard any previous initial lookahead context.
|
// Discard any previous initial lookahead context.
|
||||||
void
|
void
|
||||||
]b4_parser_class[::yy_lac_discard_ (const char* evt)
|
]b4_parser_class[::yy_lac_discard_ (const char* event)
|
||||||
{
|
{
|
||||||
/* Discard any previous initial lookahead context because of Event,
|
/* Discard any previous initial lookahead context because of Event,
|
||||||
which may be a lookahead change or an invalidation of the currently
|
which may be a lookahead change or an invalidation of the currently
|
||||||
@@ -1472,7 +1472,7 @@ b4_dollar_popdef])[]dnl
|
|||||||
if (yy_lac_established_)
|
if (yy_lac_established_)
|
||||||
{
|
{
|
||||||
YYCDEBUG << "LAC: initial context discarded due to "
|
YYCDEBUG << "LAC: initial context discarded due to "
|
||||||
<< evt << '\n';
|
<< event << '\n';
|
||||||
yy_lac_established_ = false;
|
yy_lac_established_ = false;
|
||||||
}
|
}
|
||||||
}]])b4_parse_error_bmatch([detailed\|verbose], [[
|
}]])b4_parse_error_bmatch([detailed\|verbose], [[
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ m4_define([b4_symbol_no_destructor_assert],
|
|||||||
[%destructor does not make sense in Java])])])
|
[%destructor does not make sense in Java])])])
|
||||||
b4_symbol_foreach([b4_symbol_no_destructor_assert])
|
b4_symbol_foreach([b4_symbol_no_destructor_assert])
|
||||||
|
|
||||||
# Setup some macros for api.push-pull.
|
## --------------- ##
|
||||||
|
## api.push-pull. ##
|
||||||
|
## --------------- ##
|
||||||
|
|
||||||
b4_percent_define_default([[api.push-pull]], [[pull]])
|
b4_percent_define_default([[api.push-pull]], [[pull]])
|
||||||
b4_percent_define_check_values([[[[api.push-pull]],
|
b4_percent_define_check_values([[[[api.push-pull]],
|
||||||
[[pull]], [[push]], [[both]]]])
|
[[pull]], [[push]], [[both]]]])
|
||||||
@@ -52,7 +55,8 @@ b4_use_push_for_pull_if([
|
|||||||
# Define a macro to encapsulate the parse state variables. This
|
# Define a macro to encapsulate the parse state variables. This
|
||||||
# allows them to be defined either in parse() when doing pull parsing,
|
# allows them to be defined either in parse() when doing pull parsing,
|
||||||
# or as class instance variable when doing push parsing.
|
# or as class instance variable when doing push parsing.
|
||||||
m4_define([b4_define_state],[[
|
m4_define([b4_define_state],
|
||||||
|
[[
|
||||||
/* Lookahead token kind. */
|
/* Lookahead token kind. */
|
||||||
int yychar = YYEMPTY_;
|
int yychar = YYEMPTY_;
|
||||||
/* Lookahead symbol kind. */
|
/* Lookahead symbol kind. */
|
||||||
@@ -76,6 +80,10 @@ m4_define([b4_define_state],[[
|
|||||||
]b4_yystype[ yylval = null;
|
]b4_yystype[ yylval = null;
|
||||||
]])[
|
]])[
|
||||||
|
|
||||||
|
## ------------- ##
|
||||||
|
## Parser File. ##
|
||||||
|
## ------------- ##
|
||||||
|
|
||||||
]b4_output_begin([b4_parser_file_name])[
|
]b4_output_begin([b4_parser_file_name])[
|
||||||
]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java],
|
]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java],
|
||||||
[2007-2015, 2018-2020])[
|
[2007-2015, 2018-2020])[
|
||||||
@@ -343,65 +351,63 @@ import java.text.MessageFormat;
|
|||||||
public int size = 16;
|
public int size = 16;
|
||||||
public int height = -1;
|
public int height = -1;
|
||||||
|
|
||||||
public final void push (int state, ]b4_yystype[ value]b4_locations_if([, ]b4_location_type[ loc])[) {
|
public final void push(int state, ]b4_yystype[ value]b4_locations_if([, ]b4_location_type[ loc])[) {
|
||||||
height++;
|
height++;
|
||||||
if (size == height)
|
if (size == height) {
|
||||||
{
|
int[] newStateStack = new int[size * 2];
|
||||||
int[] newStateStack = new int[size * 2];
|
System.arraycopy(stateStack, 0, newStateStack, 0, height);
|
||||||
System.arraycopy (stateStack, 0, newStateStack, 0, height);
|
stateStack = newStateStack;]b4_locations_if([[
|
||||||
stateStack = newStateStack;]b4_locations_if([[
|
]b4_location_type[[] newLocStack = new ]b4_location_type[[size * 2];
|
||||||
]b4_location_type[[] newLocStack = new ]b4_location_type[[size * 2];
|
System.arraycopy(locStack, 0, newLocStack, 0, height);
|
||||||
System.arraycopy (locStack, 0, newLocStack, 0, height);
|
locStack = newLocStack;]])
|
||||||
locStack = newLocStack;]])
|
|
||||||
|
|
||||||
b4_yystype[[] newValueStack = new ]b4_yystype[[size * 2];
|
b4_yystype[[] newValueStack = new ]b4_yystype[[size * 2];
|
||||||
System.arraycopy (valueStack, 0, newValueStack, 0, height);
|
System.arraycopy(valueStack, 0, newValueStack, 0, height);
|
||||||
valueStack = newValueStack;
|
valueStack = newValueStack;
|
||||||
|
|
||||||
size *= 2;
|
size *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
stateStack[height] = state;]b4_locations_if([[
|
stateStack[height] = state;]b4_locations_if([[
|
||||||
locStack[height] = loc;]])[
|
locStack[height] = loc;]])[
|
||||||
valueStack[height] = value;
|
valueStack[height] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void pop () {
|
public final void pop() {
|
||||||
pop (1);
|
pop(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void pop (int num) {
|
public final void pop(int num) {
|
||||||
// Avoid memory leaks... garbage collection is a white lie!
|
// Avoid memory leaks... garbage collection is a white lie!
|
||||||
if (0 < num) {
|
if (0 < num) {
|
||||||
java.util.Arrays.fill (valueStack, height - num + 1, height + 1, null);]b4_locations_if([[
|
java.util.Arrays.fill(valueStack, height - num + 1, height + 1, null);]b4_locations_if([[
|
||||||
java.util.Arrays.fill (locStack, height - num + 1, height + 1, null);]])[
|
java.util.Arrays.fill(locStack, height - num + 1, height + 1, null);]])[
|
||||||
}
|
}
|
||||||
height -= num;
|
height -= num;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int stateAt (int i) {
|
public final int stateAt(int i) {
|
||||||
return stateStack[height - i];
|
return stateStack[height - i];
|
||||||
}
|
}
|
||||||
]b4_locations_if([[
|
]b4_locations_if([[
|
||||||
|
|
||||||
public final ]b4_location_type[ locationAt (int i) {
|
public final ]b4_location_type[ locationAt(int i) {
|
||||||
return locStack[height - i];
|
return locStack[height - i];
|
||||||
}
|
}
|
||||||
]])[
|
]])[
|
||||||
public final ]b4_yystype[ valueAt (int i) {
|
public final ]b4_yystype[ valueAt(int i) {
|
||||||
return valueStack[height - i];
|
return valueStack[height - i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the state stack on the debug stream.
|
// Print the state stack on the debug stream.
|
||||||
public void print (java.io.PrintStream out) {
|
public void print(java.io.PrintStream out) {
|
||||||
out.print ("Stack now");
|
out.print ("Stack now");
|
||||||
|
|
||||||
for (int i = 0; i <= height; i++)
|
for (int i = 0; i <= height; i++) {
|
||||||
{
|
out.print(' ');
|
||||||
out.print (' ');
|
out.print(stateStack[i]);
|
||||||
out.print (stateStack[i]);
|
}
|
||||||
}
|
out.println();
|
||||||
out.println ();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -117,13 +117,13 @@
|
|||||||
// with TOK_ (e.g., TOK_EOF).
|
// with TOK_ (e.g., TOK_EOF).
|
||||||
%define api.token.prefix {TOK_}
|
%define api.token.prefix {TOK_}
|
||||||
|
|
||||||
// Customized syntax error messages (see yyreport_syntax_error).
|
// Customized syntax error messages (see yyreport_syntax_error)...
|
||||||
%define parse.error custom
|
%define parse.error custom
|
||||||
|
|
||||||
// with locations.
|
// ... with locations...
|
||||||
%locations
|
%locations
|
||||||
|
|
||||||
// and accurate list of expected tokens.
|
// ... and accurate list of expected tokens.
|
||||||
%define parse.lac full
|
%define parse.lac full
|
||||||
|
|
||||||
// Generate the parser description file (calc.output).
|
// Generate the parser description file (calc.output).
|
||||||
|
|||||||
Reference in New Issue
Block a user