From: Akim Demaille Date: Thu, 28 Aug 2008 08:32:14 +0000 (+0200) Subject: Finer input type for yytranslate. X-Git-Tag: v2.7.90~1059 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/4654b0c0a8a355e7a8fcdf51b1a5eb6c485126f1 Finer input type for yytranslate. This patch is debatable: the tradition expects yylex to return an int which happens to correspond to token_number (which is an enum). This allows for instance to return characters (such as '*' etc.). But this goes against the stronger typing I am trying to have with the new lex interface which return a symbol_type. So in this case, feed yytranslate_ with a token_type. * data/lalr1.cc (yytranslate_): When in %define lex-symbol, expect a token_type. --- diff --git a/ChangeLog b/ChangeLog index 0ba320e2..fdc0d613 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2008-11-13 Akim Demaille + + Finer input type for yytranslate. + This patch is debatable: the tradition expects yylex to return an int + which happens to correspond to token_number (which is an enum). This + allows for instance to return characters (such as '*' etc.). But this + goes against the stronger typing I am trying to have with the new + lex interface which return a symbol_type. So in this case, feed + yytranslate_ with a token_type. + + * data/lalr1.cc (yytranslate_): When in %define lex-symbol, + expect a token_type. + 2008-11-13 Akim Demaille Honor lex-params in %define lex_symbol mode. diff --git a/data/lalr1.cc b/data/lalr1.cc index c2c634cf..6b0d9d9f 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -635,7 +635,8 @@ m4_ifdef([b4_stype], #endif /// Convert a scanner token number \a t to a symbol number. - static inline token_number_type yytranslate_ (int t); + static inline token_number_type yytranslate_ (]b4_lex_symbol_if( + [token_type], [int])[ t); /// A complete symbol, with its type. template @@ -1587,7 +1588,8 @@ b4_error_verbose_if([int yystate, int yytoken], /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ ]b4_parser_class_name[::token_number_type - ]b4_parser_class_name[::yytranslate_ (int t) + ]b4_parser_class_name[::yytranslate_ (]b4_lex_symbol_if([token_type], + [int])[ t) { static const token_number_type @@ -1598,7 +1600,7 @@ b4_error_verbose_if([int yystate, int yytoken], const unsigned int user_token_number_max_ = ]b4_user_token_number_max[; const token_number_type undef_token_ = ]b4_undef_token_number[; - if (t <= yyeof_) + if (static_cast(t) <= yyeof_) return yyeof_; else if (static_cast (t) <= user_token_number_max_) return translate_table[t];