From 27cb5b590124894edc3e4bee11737972e56d2dbe Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 18 Aug 2008 21:31:06 +0200 Subject: [PATCH] yychar cannot be empty in yyerrlab. * TODO (yychar == yyempty_): New. * data/lalr1.cc: Remove the handling of this case. This eases forthcoming changes related to yychar and yytranslate. --- ChangeLog | 7 +++++++ TODO | 16 ++++++++++++++++ data/lalr1.cc | 25 +++++++++++++------------ 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 17023e24..e8e8ac2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-11-11 Akim Demaille + + yychar cannot be empty in yyerrlab. + * TODO (yychar == yyempty_): New. + * data/lalr1.cc: Remove the handling of this case. + This eases forthcoming changes related to yychar and yytranslate. + 2008-11-11 Akim Demaille Bench: syntactic sugar for %define/#define. diff --git a/TODO b/TODO index 7b473094..918ca350 100644 --- a/TODO +++ b/TODO @@ -54,6 +54,22 @@ what it should look like. For instance what follows crashes. return yyparse (); } +** yychar == yyempty_ +The code in yyerrlab reads: + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + +There are only two yychar that can be <= YYEOF: YYEMPTY and YYEOF. +But I can't produce the situation where yychar is YYEMPTY here, is it +really possible? The test suite does not exercise this case. + +This shows that it would be interesting to manage to install skeleton +coverage analysis to the test suite. * Header guards diff --git a/data/lalr1.cc b/data/lalr1.cc index 4915caa2..8c5b3345 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -1281,18 +1281,19 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[; if (yyerrstatus_ == 3) { /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - if (yychar <= yyeof_) - { - /* Return failure if at end of input. */ - if (yychar == yyeof_) - YYABORT; - } - else - { - yy_destroy_ ("Error: discarding", yyla); - yychar = yyempty_; + error, discard it. */ + + /* Return failure if at end of input. */ + if (yychar == yyeof_) + YYABORT; + else + {]b4_assert_if([ + // Previous version of this code was ready to handle + // yychar == yyempty_ (actually yychar <= yyeof_). Can it + // really be triggered? + assert (yychar != yyempty_);])[ + yy_destroy_ ("Error: discarding", yyla); + yychar = yyempty_; } } -- 2.47.2