X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/507aa0e2a80ee035146a6429a64df9d6e6fb8a3b..1c72905811fa75e0715eb5ec1066dfcae520d070:/data/lalr1.cc?ds=inline diff --git a/data/lalr1.cc b/data/lalr1.cc index 031d13c5..39167f94 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -1,6 +1,6 @@ # C++ skeleton for Bison -# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 +# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 # Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify @@ -47,18 +47,6 @@ m4_define([b4_integral_parser_table_define], m4_copy([b4_symbol_value], [b4_symbol_value_template]) -# b4_lex_symbol_if([IF-YYLEX-RETURNS-A-COMPLETE-SYMBOL], [IF-NOT]) -# ---------------------------------------------------------------- -m4_define([b4_lex_symbol_if], -[b4_percent_define_ifdef([[lex_symbol]], [$1], [$2])]) - - -# b4_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT]) -# ------------------------------------------------ -m4_define([b4_assert_if], -[b4_percent_define_ifdef([[assert]], [$1], [$2])]) - - # b4_lhs_value([TYPE]) # -------------------- # Expansion of $$. @@ -126,182 +114,9 @@ m4_popdef([b4_at_dollar])dnl m4_popdef([b4_dollar_dollar])dnl ])]) -# b4_symbol_constructor_declaration_(SYMBOL-NUMBER) -# ------------------------------------------------- -# Declare the overloaded version of make_symbol for the (common) type of -# these SYMBOL-NUMBERS. Use at class-level. -m4_define([b4_symbol_constructor_declaration_], -[b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id], -[ static inline - symbol_type - make_[]b4_symbol_([$1], [id]) (dnl -b4_args(b4_symbol_if([$1], [has_type], - [const b4_symbol([$1], [type])& v]), - b4_locations_if([const location_type& l]))); - -])])]) - - -# b4_symbol_constructor_declarations -# ---------------------------------- -# Declare symbol constructors for all the value types. -# Use at class-level. -m4_define([b4_symbol_constructor_declarations], -[b4_variant_if([ - // Symbol constructors declarations. -b4_symbol_foreach([b4_symbol_constructor_declaration_])])]) - - - -# b4_symbol_constructor_definition_(SYMBOL-NUMBER) -# ------------------------------------------------ -# Define symbol constructor for this SYMBOL-NUMBER. -m4_define([b4_symbol_constructor_definition_], -[b4_symbol_if([$1], [is_token], [b4_symbol_if([$1], [has_id], -[ b4_parser_class_name::symbol_type - b4_parser_class_name::make_[]b4_symbol_([$1], [id]) (dnl -b4_args(b4_symbol_if([$1], [has_type], - [const b4_symbol([$1], [type])& v]), - b4_locations_if([const location_type& l]))) - { - return symbol_type (b4_args([yytranslate_ (token::b4_symbol([$1], [id]))], - b4_symbol_if([$1], [has_type], [v]), - b4_locations_if([l]))); - } - -])])]) - - -# b4_symbol_constructor_definitions -# ---------------------------------- -# Define the overloaded versions of make_symbol for all the value types. -m4_define([b4_symbol_constructor_definitions], -[[ // symbol_base_type. - template - ]b4_parser_class_name[::symbol_base_type::symbol_base_type () - : value()]b4_locations_if([ - , location()])[ - { - }]b4_locations_if([[ - - template - ]b4_parser_class_name[::symbol_base_type::symbol_base_type (const location_type& l) - : value() - , location(l) - { - }]])[ - - template - ]b4_parser_class_name[::symbol_base_type::symbol_base_type (]b4_args( - [const semantic_type& v], - b4_locations_if([const location_type& l]))[) - : value(v)]b4_locations_if([ - , location(l)])[ - { - } - - template - const Exact& - ]b4_parser_class_name[::symbol_base_type::self () const - { - return static_cast(*this); - } - - template - Exact& - ]b4_parser_class_name[::symbol_base_type::self () - { - return static_cast(*this); - } - - template - int - ]b4_parser_class_name[::symbol_base_type::type_get () const - { - return self ().type_get_ (); - } - - // symbol_type. - ]b4_parser_class_name[::symbol_type::symbol_type () - : super_type () - , type () - { - } - - ]b4_parser_class_name[::symbol_type::symbol_type (]b4_args( - [int t], - b4_locations_if([const location_type& l]))[) - : super_type (]b4_locations_if([l])[) - , type (t) - { - } - - ]b4_parser_class_name[::symbol_type::symbol_type (]b4_args( - [int t], - [const semantic_type& v], - b4_locations_if([const location_type& l]))[) - : super_type (v]b4_locations_if([, l])[) - , type (t) - { - } - - int - ]b4_parser_class_name[::symbol_type::type_get_ () const - { - return type; - } -]b4_lex_symbol_if([[ - ]b4_parser_class_name[::token_type - ]b4_parser_class_name[::symbol_type::token () const - { - // YYTOKNUM[NUM] -- (External) token number corresponding to the - // (internal) symbol number NUM (which must be that of a token). */ - static - const ]b4_int_type_for([b4_toknum])[ - yytoken_number_[] = - { - ]b4_toknum[ - }; - return static_cast (yytoken_number_[type]); - } -]])[ - -]b4_variant_if( -[ // Implementation of make_symbol for each symbol type. -b4_symbol_foreach([b4_symbol_constructor_definition_])])]) - - -# b4_yytranslate_definition -# ------------------------- -# Define yytranslate_. Sometimes we want it in the header file, -# sometimes the cc file suffices. -m4_define([b4_yytranslate_definition], -[[ // Symbol number corresponding to token number t. - ]b4_parser_class_name[::token_number_type - ]b4_parser_class_name[::yytranslate_ (]b4_lex_symbol_if([token_type], - [int])[ t) - { - static - const token_number_type - translate_table[] = - { -]b4_translate[ - }; - const unsigned int user_token_number_max_ = ]b4_user_token_number_max[; - const token_number_type undef_token_ = ]b4_undef_token_number[; - - if (static_cast(t) <= yyeof_) - return yyeof_; - else if (static_cast (t) <= user_token_number_max_) - return translate_table[t]; - else - return undef_token_; - } -]]) - m4_pushdef([b4_copyright_years], - [2002, 2003, 2004, 2005, 2006, 2007, 2008]) + [2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009]) m4_define([b4_parser_class_name], [b4_percent_define_get([[parser_class_name]])]) @@ -331,7 +146,7 @@ dnl FIXME: This is wrong, we want computed header guards. ]b4_percent_code_get([[requires]])[ -]b4_assert_if([#include ])[ +]b4_parse_assert_if([#include ])[ #include #include #include "stack.hh" @@ -339,14 +154,14 @@ dnl FIXME: This is wrong, we want computed header guards. ]b4_namespace_open[ ]b4_locations_if([ class position; class location;])[ -]b4_variant_if([b4_variant_definition])[ +]b4_variant_if([b4_variant_define])[ ]b4_namespace_close[ ]b4_locations_if([#include "location.hh"])[ /* Enabling traces. */ #ifndef YYDEBUG -# define YYDEBUG ]b4_debug_flag[ +# define YYDEBUG ]b4_parse_trace_if([1], [0])[ #endif /* Enabling verbose error messages. */ @@ -354,7 +169,7 @@ dnl FIXME: This is wrong, we want computed header guards. # undef YYERROR_VERBOSE # define YYERROR_VERBOSE 1 #else -# define YYERROR_VERBOSE ]b4_error_verbose_flag[ +# define YYERROR_VERBOSE ]b4_error_verbose_if([1], [0])[ #endif /* Enabling the token table. */ @@ -388,35 +203,7 @@ do { \ class ]b4_parser_class_name[ { public: -#ifndef YYSTYPE -]b4_variant_if( -[ /// An auxiliary type to compute the largest semantic type. - union union_type - {]b4_type_foreach([b4_char_sizeof])[}; - - /// Symbol semantic values. - typedef variant semantic_type;], -[ /// Symbol semantic values. -m4_ifdef([b4_stype], -[ union semantic_type - {b4_user_stype - };], -[m4_if(b4_tag_seen_flag, 0, -[[ typedef int semantic_type;]], -[[ typedef YYSTYPE semantic_type;]])])])[ -#else - typedef YYSTYPE semantic_type; -#endif]b4_locations_if([ - /// Symbol locations. - typedef b4_percent_define_get([[location_type]]) location_type;])[ - /// Tokens. - struct token - { - ]b4_token_enums(b4_tokens)[ - }; - /// Token type. - typedef token::yytokentype token_type; - +]b4_public_types_declare[ /// Build a parser object. ]b4_parser_class_name[ (]b4_parse_param_decl[); virtual ~]b4_parser_class_name[ (); @@ -439,12 +226,12 @@ m4_ifdef([b4_stype], void set_debug_level (debug_level_type l); #endif - private: /// Report a syntax error.]b4_locations_if([ /// \param loc where the syntax error is found.])[ /// \param msg a description of the syntax error. virtual void error (]b4_locations_if([const location_type& loc, ])[const std::string& msg); + private: /// Generate an error message. /// \param state the state where the error occurred. /// \param tok the lookahead token. @@ -485,33 +272,6 @@ m4_ifdef([b4_stype], /// Convert a scanner token number \a t to a symbol number. static inline token_number_type yytranslate_ (]b4_lex_symbol_if([token_type], [int])[ t); - /// A complete symbol, with its type. - template - struct symbol_base_type - { - /// Default constructor. - inline symbol_base_type (); - - /// Constructor.]b4_locations_if([ - inline symbol_base_type (const location_type& l)])[; - inline symbol_base_type (]b4_args( - [const semantic_type& v], - b4_locations_if([const location_type& l]))[); - - /// Return this with its exact type. - const Exact& self () const; - Exact& self (); - - /// Return the type of this symbol. - int type_get () const; - - /// The semantic value. - semantic_type value;]b4_locations_if([ - - /// The location. - location_type location;])[ - }; - #if YYDEBUG /// \brief Display a symbol type, value and location. /// \param yyo The output stream. @@ -529,36 +289,6 @@ m4_ifdef([b4_stype], inline void yy_destroy_ (const char* yymsg, symbol_base_type& yysym) const; - public: - /// Element of the stack: a state and its attributes. - struct symbol_type : symbol_base_type - { - /// The parent class. - typedef symbol_base_type super_type; - - /// Default constructor. - inline symbol_type (); - - /// Constructor. - inline symbol_type (]b4_args([int t], - [const semantic_type& v], - b4_locations_if([const location_type& l]))[); - - inline symbol_type (]b4_args([int t], - b4_locations_if([const location_type& l]))[); - - /// The symbol type. - int type; - - /// Return the type corresponding to this state. - inline int type_get_ () const; - - /// Its token. - inline token_type token () const; - }; - -]b4_symbol_constructor_declarations[ - private: /// Element of the stack: a state and its attributes. struct stack_symbol_type : symbol_base_type @@ -621,8 +351,8 @@ m4_ifdef([b4_stype], ]b4_parse_param_vars[ }; -]b4_lex_symbol_if([b4_yytranslate_definition])[ -]b4_lex_symbol_if([b4_symbol_constructor_definitions])[ +]b4_lex_symbol_if([b4_yytranslate_define +b4_public_types_define])[ ]b4_namespace_close[ ]b4_percent_define_flag_if([[global_tokens_and_yystype]], @@ -772,7 +502,7 @@ b4_percent_code_get[]dnl | Symbol types. | `---------------*/ -]b4_lex_symbol_if([], [b4_symbol_constructor_definitions])[ +]b4_lex_symbol_if([], [b4_public_types_define])[ // stack_symbol_type. ]b4_parser_class_name[::stack_symbol_type::stack_symbol_type () @@ -1029,8 +759,8 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[ yyreduce: yylen = yyr2_[yyn];]b4_variant_if([ /* Variants are always initialized to an empty instance of the - correct type. The default $$=$1 rule is NOT applied when using - variants */ + correct type. The default $$=$1 action is NOT applied when using + variants. */ ]b4_symbol_variant([[yyr1_@{yyn@}]], [yylhs.value], [build]),[ /* If YYLEN is nonzero, implement the default value of the action: `$$ = $1'. Otherwise, use the top of the stack. @@ -1069,16 +799,18 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[ yylhs.state = yystate; YY_SYMBOL_PRINT ("-> $$ =", yylhs); ]b4_variant_if([[ - // Destroy the lhs symbols. + // Destroy the rhs symbols. for (int i = 0; i < yylen; ++i) - // Destroy a variant which value may have be swapped with - // yylhs.value. The value of yylhs.value (hence maybe one of - // these lhs symbols) depends on what does the default - // contruction for this type. In the case of pointers for - // instance, nothing is done, so the value is junk. Therefore - // do not try to report the content in the debug trace, it's - // junk. Hence yymsg = 0. Besides, that keeps exactly the same - // traces as with the other Bison skeletons. + // Destroy a variant which value may have been swapped with + // yylhs.value (for instance if the action was "std::swap($$, + // $1)"). The value of yylhs.value (hence possibly one of these + // rhs symbols) depends on the default contruction for this + // type. In the case of pointers for instance, no + // initialization is done, so the value is junk. Therefore do + // not try to report the value of symbols about to be destroyed + // in the debug trace, it's possibly junk. Hence yymsg = 0. + // Besides, that keeps exactly the same traces as with the other + // Bison skeletons. yy_destroy_ (0, yystack_[i]);]])[ yypop_ (yylen); @@ -1089,9 +821,9 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param)));])[ yypush_ (0, yylhs); goto yynewstate; - /*------------------------------------. - | yyerrlab -- here on detecting error | - `------------------------------------*/ + /*--------------------------------------. + | yyerrlab -- here on detecting error. | + `--------------------------------------*/ yyerrlab: /* If not already recovering from an error, report this error. */ if (!yyerrstatus_) @@ -1328,7 +1060,7 @@ b4_error_verbose_if([int yystate, int yytoken], } #endif // YYDEBUG -]b4_lex_symbol_if([], [b4_yytranslate_definition])[ +]b4_lex_symbol_if([], [b4_yytranslate_define])[ ]b4_namespace_close[ ]b4_epilogue[]dnl m4_divert_pop(0)