d: put YYEMPTY in the TokenKind

* data/skeletons/d.m4, data/skeletons/lalr1.d (b4_token_enums): Rename
YYTokenType as TokenKind.
Define YYEMPTY.
* examples/d/calc.y, tests/calc.at, tests/scanner.at: Adjust.
This commit is contained in:
Akim Demaille
2020-04-13 08:45:46 +02:00
parent 3877b7210e
commit 71e3f6d4da
7 changed files with 39 additions and 39 deletions

View File

@@ -27,7 +27,7 @@ public interface Lexer
* to the next token and prepares to return the semantic value
* and beginning/ending positions of the token.
* @return the token identifier corresponding to the next token. */
YYTokenType yylex ();
TokenKind yylex ();
/**
* Entry point for error reporting. Emits an error
@@ -39,7 +39,7 @@ public interface Lexer
void yyerror (YYLocation loc, string s);
}
- semantic types are handled by D usions (same as for C/C++ parsers)
- semantic types are handled by D unions (same as for C/C++ parsers)
- the following (non-standard) %defines are supported:

View File

@@ -164,11 +164,9 @@ m4_define([b4_token_enum],
# Output the definition of the tokens as enums.
m4_define([b4_token_enums],
[/* Token kinds. */
public enum YYTokenType {
/** Token returned by the scanner to signal the end of its input. */
EOF = 0,
b4_symbol_foreach([b4_token_enum])
public enum TokenKind {
]b4_symbol_kind([-2])[ = -2,
b4_symbol_foreach([b4_token_enum])dnl
}
])

View File

@@ -429,7 +429,7 @@ b4_locations_if([, ref ]b4_location_type[ yylocationp])[)
public bool parse ()
{
/// Lookahead and lookahead in internal form.
int yychar = yyempty_;
int yychar = TokenKind.YYEMPTY;
SymbolKind yytoken = SymbolKind.]b4_symbol_prefix[YYEMPTY;
/* State. */
@@ -493,7 +493,7 @@ m4_popdef([b4_at_dollar])])dnl
}
/* Read a lookahead token. */
if (yychar == yyempty_)
if (yychar == TokenKind.YYEMPTY)
{]b4_parse_trace_if([[
yycdebugln ("Reading a token");]])[
yychar = yylex ();]b4_locations_if([[
@@ -532,7 +532,7 @@ m4_popdef([b4_at_dollar])])dnl
yy_symbol_print ("Shifting", yytoken, yylval]b4_locations_if([, yylloc])[);]])[
/* Discard the token being shifted. */
yychar = yyempty_;
yychar = TokenKind.YYEMPTY;
/* Count tokens shifted since error; after three, turn off error
* status. */
@@ -573,7 +573,7 @@ m4_popdef([b4_at_dollar])])dnl
if (yyerrstatus_ == 0)
{
++yynerrs_;
if (yychar == yyempty_)
if (yychar == TokenKind.YYEMPTY)
yytoken = SymbolKind.]b4_symbol_prefix[YYEMPTY;
yyerror (]b4_locations_if([yylloc, ])[yysyntax_error (yystate, yytoken));
}
@@ -584,14 +584,14 @@ m4_popdef([b4_at_dollar])])dnl
/* If just tried and failed to reuse lookahead token after an
* error, discard it. */
if (yychar <= YYTokenType.EOF)
if (yychar <= TokenKind.]b4_symbol(0, [id])[)
{
/* Return failure if at end of input. */
if (yychar == YYTokenType.EOF)
if (yychar == TokenKind.]b4_symbol(0, [id])[)
return false;
}
else
yychar = yyempty_;
yychar = TokenKind.YYEMPTY;
}
/* Else will try to reuse lookahead token after shifting the error
@@ -841,7 +841,6 @@ m4_popdef([b4_at_dollar])])dnl
private static immutable int yylast_ = ]b4_last[;
private static immutable int yynnts_ = ]b4_nterms_number[;
private static immutable int yyempty_ = -2;
private static immutable int yyfinal_ = ]b4_final_state_number[;
private static immutable int yyntokens_ = ]b4_tokens_number[;