[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 09/10] d: handle eof in yytranslate
From: |
Akim Demaille |
Subject: |
[PATCH 09/10] d: handle eof in yytranslate |
Date: |
Sun, 1 Sep 2019 18:41:22 +0200 |
This changes the traces from
Reading a token:
Now at end of input.
to
Reading a token:
Next token is token $end (7FFEE56E6474)
which is ok. Actually it is even better, as it gives the location
when locations are enabled, and is clearer when rules explicitly use
the EOF token.
* data/skeletons/lalr1.d (yytranslate_): Handle eof here, as is done
in lalr1.cc.
---
data/skeletons/lalr1.d | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/data/skeletons/lalr1.d b/data/skeletons/lalr1.d
index fd19e852..672c8a14 100644
--- a/data/skeletons/lalr1.d
+++ b/data/skeletons/lalr1.d
@@ -500,17 +500,9 @@ m4_popdef([b4_at_dollar])])dnl
}
/* Convert token to internal form. */
- if (yychar <= YYTokenType.EOF)
- {
- yychar = yytoken = YYTokenType.EOF;]b4_parse_trace_if([[
- yycdebug ("Now at end of input.\n");]])[
- }
- else
- {
- yytoken = yytranslate_ (yychar);]b4_parse_trace_if([[
- yy_symbol_print ("Next token is",
- yytoken, yylval]b4_locations_if([, yylloc])[);]])[
- }
+ yytoken = yytranslate_ (yychar);]b4_parse_trace_if([[
+ yy_symbol_print ("Next token is",
+ yytoken, yylval]b4_locations_if([, yylloc])[);]])[
/* If the proper action on seeing token YYTOKEN is to reduce or to
detect an error, take that action. */
@@ -833,7 +825,9 @@ m4_popdef([b4_at_dollar])])dnl
]b4_translate[
@};
- if (0 <= t && t <= yyuser_token_number_max_)
+ if (t <= 0)
+ return YYTokenType.EOF;
+ else if (t <= yyuser_token_number_max_)
return translate_table[t];
else
return yyundef_token_;]])[
--
2.23.0
- RFC: Introduce api.token.raw, Akim Demaille, 2019/09/01
- [PATCH 01/10] style: tidy yacc.c, Akim Demaille, 2019/09/01
- [PATCH 02/10] api.token.raw: implement, Akim Demaille, 2019/09/01
- [PATCH 03/10] api.token.raw: check it, Akim Demaille, 2019/09/01
- [PATCH 04/10] api.token.raw: apply to the other skeletons, Akim Demaille, 2019/09/01
- [PATCH 05/10] api.token.raw: cannot be used with character literals, Akim Demaille, 2019/09/01
- [PATCH 06/10] api.token.raw: document it, Akim Demaille, 2019/09/01
- [PATCH 07/10] parser: use api.token.raw, Akim Demaille, 2019/09/01
- [PATCH 09/10] d: handle eof in yytranslate,
Akim Demaille <=
- [PATCH 10/10] java: handle eof in yytranslate, Akim Demaille, 2019/09/01
- [PATCH 08/10] regen, Akim Demaille, 2019/09/01
- Re: RFC: Introduce api.token.raw, Akim Demaille, 2019/09/14