style: update comments in the skeletons

* data/skeletons/c++.m4, data/skeletons/glr.c, data/skeletons/lalr1.d,
* data/skeletons/lalr1.java, data/skeletons/yacc.c:
Be more accurate about yychar and yytoken.
Don't name local variables as if they were members.
This commit is contained in:
Akim Demaille
2020-07-05 09:14:17 +02:00
parent 238692ad77
commit 49f1e5f428
6 changed files with 21 additions and 14 deletions

View File

@@ -594,11 +594,12 @@ m4_define([b4_yytranslate_define],
{
]b4_translate[
};
const int code_max_ = ]b4_code_max[;
// Last valid token kind.
const int code_max = ]b4_code_max[;
if (t <= 0)
return symbol_kind::]b4_symbol_prefix[YYEOF;
else if (t <= code_max_)
else if (t <= code_max)
return YY_CAST (symbol_kind_type, translate_table[t]);
else
return symbol_kind::]b4_symbol_prefix[YYUNDEF;]])[

View File

@@ -333,7 +333,7 @@ static YYLTYPE yyloc_default][]b4_yyloc_default;])[
accessed by $0, $-1, etc., in any rule. */
#define YYMAXLEFT ]b4_max_left_semantic_context[
/* YYMAXUTOK -- Last valid token number (for yychar). */
/* YYMAXUTOK -- Last valid token kind. */
#define YYMAXUTOK ]b4_code_max[
/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM

View File

@@ -428,8 +428,9 @@ b4_locations_if([, ref ]b4_location_type[ yylocationp])[)
*/
public bool parse ()
{
/// Lookahead and lookahead in internal form.
// Lookahead token kind.
int yychar = TokenKind.YYEMPTY;
// Lookahead symbol kind.
SymbolKind yytoken = ]b4_symbol(-2, kind)[;
/* State. */
@@ -841,11 +842,12 @@ m4_popdef([b4_at_dollar])])dnl
]b4_translate[
@};
immutable int code_max_ = ]b4_code_max[;
// Last valid token kind.
immutable int code_max = ]b4_code_max[;
if (t <= 0)
return ]b4_symbol(0, kind)[;
else if (t <= code_max_)
else if (t <= code_max)
{
import std.conv : to;
return to!SymbolKind (translate_table[t]);

View File

@@ -53,8 +53,9 @@ b4_use_push_for_pull_if([
# allows them to be defined either in parse() when doing pull parsing,
# or as class instance variable when doing push parsing.
m4_define([b4_define_state],[[
/* Lookahead and lookahead in internal form. */
/* Lookahead token kind. */
int yychar = YYEMPTY_;
/* Lookahead symbol kind. */
SymbolKind yytoken = null;
/* State. */
@@ -1078,17 +1079,18 @@ b4_dollar_popdef[]dnl
/* YYTRANSLATE_(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
as returned by yylex, with out-of-bounds checking. */
private static final SymbolKind yytranslate_ (int t)
private static final SymbolKind yytranslate_(int t)
]b4_api_token_raw_if(dnl
[[ {
return SymbolKind.get(t);
}
]],
[[ {
int code_max_ = ]b4_code_max[;
// Last valid token kind.
int code_max = ]b4_code_max[;
if (t <= 0)
return ]b4_symbol(0, kind)[;
else if (t <= code_max_)
else if (t <= code_max)
return SymbolKind.get(yytranslate_table_[t]);
else
return ]b4_symbol(2, kind)[;

View File

@@ -155,7 +155,7 @@ m4_define([b4_rhs_location],
# Declare the variables that are global, or local to YYPARSE if
# pure-parser.
m4_define([b4_declare_scanner_communication_variables], [[
/* The lookahead symbol. */
/* Lookahead token kind. */
int yychar;
]b4_pure_if([[
@@ -571,6 +571,7 @@ union yyalloc
/* YYNSTATES -- Number of states. */
#define YYNSTATES ]b4_states_number[
/* YYMAXUTOK -- Last valid token kind. */
#define YYMAXUTOK ]b4_code_max[
@@ -1544,7 +1545,7 @@ yyparse (]m4_ifset([b4_parse_param], [b4_formals(b4_parse_param)], [void])[)]])[
int yyn;
/* The return value of yyparse. */
int yyresult;
/* Lookahead token as an internal (translated) token number. */
/* Lookahead symbol kind. */
yysymbol_kind_t yytoken = ]b4_symbol(-2, kind)[;
/* The variables used to return semantic value and location from the
action routines. */