X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/8d69a1a3ae9c07e97951d98be9576a12e16a7c2b..ec3bc39:/data/bison.c%20%20/bison.git/blobdiff_plain/8d69a1a3ae9c07e97951d98be9576a12e16a7c2b..ec3bc39:/data/bison.c++ diff --git a/data/bison.c++ b/data/bison.c++ index 2e82826d..c418bad3 100644 --- a/data/bison.c++ +++ b/data/bison.c++ @@ -1,11 +1,111 @@ -#output "b4_output_prefix[]b4_output_infix[]-class.hh" -/* -*- C++ -*- */ +m4_divert(-1) +# b4_sint_type(MAX) +# ----------------- +# Return the smallest signed int type able to handle the number MAX. +m4_define([b4_sint_type], +[m4_if(m4_eval([$1 <= 127]), [1], [signed char], + m4_eval([$1 <= 32767]), [1], [signed short], + [signed int])]) + + +# b4_uint_type(MAX) +# ----------------- +# Return the smallest unsigned int type able to handle the number MAX. +m4_define([b4_uint_type], +[m4_if(m4_eval([$1 <= 255]), [1], [unsigned char], + m4_eval([$1 <= 65535]), [1], [unsigned short], + [unsigned int])]) + + +# b4_lhs_value([TYPE]) +# -------------------- +# Expansion of $$. +m4_define([b4_lhs_value], +[yyval[]m4_ifval([$1], [.$1])]) + + +# b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) +# -------------------------------------- +# Expansion of $NUM, where the current rule has RULE-LENGTH +# symbols on RHS. +m4_define([b4_rhs_value], +[semantic_stack_@<:@m4_eval([$1 - $2])@:>@m4_ifval([$3], [.$3])]) + + +# b4_lhs_location() +# ----------------- +# Expansion of @$. +m4_define([b4_lhs_location], +[yyloc]) + + +# b4_rhs_location(RULE-LENGTH, NUM) +# --------------------------------- +# Expansion of @NUM, where the current rule has RULE-LENGTH symbols +# on RHS. +m4_define([b4_rhs_location], +[location_stack_@<:@m4_eval([$1 - $2])@:>@]) + + +# b4_token_define(TOKEN-NAME, TOKEN-NUMBER) +# ----------------------------------------- +# Output the definition of this token as #define. +m4_define([b4_token_define], +[#define $1 $2 +]) + + +# b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) +# ------------------------------------------------------- +# Output the definition of the tokens as #define. +m4_define([b4_token_defines], +[m4_map([b4_token_define], [$@])]) + +m4_define_default([b4_input_suffix], [.y]) + +m4_define_default([b4_output_parser_suffix], +[m4_translit(b4_input_suffix, [yY], [cC])]) + +m4_define_default([b4_output_parser_name], +[b4_output_prefix[]b4_output_infix[]b4_output_parser_suffix[]]) + + +m4_define_default([b4_output_header_suffix], +[m4_translit(b4_input_suffix, [yY], [hH])]) + +m4_define_default([b4_output_header_name], +[b4_output_prefix[]b4_output_infix[]b4_output_header_suffix[]]) + +m4_define_default([b4_header_guard], + [m4_bpatsubst(m4_toupper([BISON_]b4_output_header_name), + [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])]) + +m4_define([b4_inherit], + [m4_ifdef([b4_root], + [: public b4_root +], + [])]) + +m4_define([b4_param], + [m4_ifdef([b4_root], + [, + const Param& param], + [])]) + +m4_define([b4_constructor], + [m4_ifdef([b4_root], + [b4_root (param), + ], + [])]) + +m4_define([b4_copyright], + [/* -*- C++ -*- */ /* A Bison parser, made from b4_filename, by GNU bison b4_version. */ /* Skeleton output parser for bison, - Copyright 1984, 1989, 1990, 2000, 2001 Free Software Foundation, Inc. + Copyright 2002 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,13 +125,28 @@ /* As a special exception, when this file is copied by Bison into a Bison output file, you may use that output file without restriction. This special exception was added by the Free Software Foundation - in version 1.24 of Bison. */ + in version 1.24 of Bison. */]) + +m4_divert(0)dnl +#output "b4_output_header_name" +b4_copyright +#ifndef b4_header_guard +# define b4_header_guard #include "stack.hh" #include "location.hh" #include +/* Using locations. */ +#define YYLSP_NEEDED b4_locations_flag + +/* Copy the first part of user declarations. */ +b4_pre_prologue + +/* Tokens. */ +b4_token_defines(b4_tokens) + /* Enabling traces. */ #ifndef YYDEBUG # define YYDEBUG b4_debug @@ -42,13 +157,36 @@ # define YYERROR_VERBOSE b4_error_verbose #endif -/* Using locations. */ -#define YYLSP_NEEDED b4_locations_flag +#ifndef YYSTYPE +m4_ifdef([b4_stype_line], +[#line b4_stype_line "b4_filename" +])dnl +typedef b4_stype +yystype; +# define YYSTYPE yystype +#endif -b4_prologue +/* Copy the second part of user declarations. */ +b4_post_prologue -// FIXME: This should be defined in traits, not here. -typedef b4_stype yystype; +#line __oline__ "__ofile__" +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + Current.last_line = Rhs[[N]].last_line; \ + Current.last_column = Rhs[[N]].last_column; +#endif + +m4_if(b4_locations_flag, [0], [], +[#ifndef YYLTYPE +typedef struct yyltype +{ + int first_line; + int first_column; + int last_line; + int last_column; +} yyltype; +# define YYLTYPE yyltype +#endif]) namespace yy { @@ -62,6 +200,8 @@ namespace yy template < > struct Traits< b4_name > { + typedef b4_uint_type(b4_translate_max) TokenNumberType; + typedef b4_sint_type(b4_rhs_max) RhsNumberType; typedef int StateType; typedef yystype SemanticType; typedef b4_ltype LocationType; @@ -70,13 +210,15 @@ namespace yy namespace yy { - class b4_name + class b4_name b4_inherit { public: - typedef Traits< b4_name >::StateType StateType; - typedef Traits< b4_name >::SemanticType SemanticType; - typedef Traits< b4_name >::LocationType LocationType; + typedef Traits< b4_name >::TokenNumberType TokenNumberType; + typedef Traits< b4_name >::RhsNumberType RhsNumberType; + typedef Traits< b4_name >::StateType StateType; + typedef Traits< b4_name >::SemanticType SemanticType; + typedef Traits< b4_name >::LocationType LocationType; typedef Stack< StateType > StateStack; typedef Stack< SemanticType > SemanticStack; @@ -84,10 +226,12 @@ namespace yy #if YYLSP_NEEDED b4_name (bool debug, - LocationType initlocation) : debug_ (debug), - initlocation_ (initlocation) + LocationType initlocation[]b4_param) : + b4_constructor[]debug_ (debug), + initlocation_ (initlocation) #else - b4_name (bool debug) : debug_ (debug) + b4_name (bool debug[]b4_param) : + b4_constructor[]debug_ (debug) #endif { } @@ -116,8 +260,8 @@ namespace yy static const short defgoto_[[]]; static const short table_[[]]; static const short check_[[]]; - static const short r1_[[]]; - static const short r2_[[]]; + static const b4_uint_type(b4_r1_max) r1_[[]]; + static const b4_uint_type(b4_r2_max) r2_[[]]; #if YYDEBUG || YYERROR_VERBOSE static const char* const name_[[]]; @@ -125,13 +269,13 @@ namespace yy /* More tables, for debugging. */ #if YYDEBUG - static const short rhs_[[]]; - static const short prhs_[[]]; - static const short rline_[[]]; + static const RhsNumberType rhs_[[]]; + static const b4_uint_type(b4_prhs_max) prhs_[[]]; + static const b4_uint_type(b4_rline_max) rline_[[]]; #endif /* Even more tables. */ - static inline char translate_ (int token); + static inline TokenNumberType translate_ (int token); /* Constants. */ static const int eof_; @@ -145,7 +289,8 @@ namespace yy static const int errcode_; static const int ntokens_; static const int initdepth_; - static const unsigned maxtok_; + static const unsigned user_token_number_max_; + static const TokenNumberType undef_token_; /* State. */ int n_; @@ -160,17 +305,25 @@ namespace yy /* Message. */ std::string message; - /* @$ and $$. */ + /* Semantic value and location of lookahead token. */ SemanticType value; LocationType location; + /* @$ and $$. */ + SemanticType yyval; + LocationType yyloc; + /* Initial location. */ LocationType initlocation_; }; } +#endif /* not b4_header_guard */ + #output "b4_output_prefix[]b4_output_infix[].cc" -#include "b4_output_prefix[]b4_output_infix-class.hh" +b4_copyright + +#include "b4_output_header_name" /* Enable debugging if requested. */ #if YYDEBUG @@ -185,9 +338,6 @@ do { \ # define YYDPRINTF(Args) #endif /* !YYDEBUG */ -/* Tokens. */ -b4_tokendef - int yy::b4_name::parse () { @@ -199,12 +349,6 @@ yy::b4_name::parse () semantic_stack_ = SemanticStack (1); location_stack_ = LocationStack (1); - /* Reserve initial space. The C parser needed that, but is it really - useful here? */ - state_stack_.reserve (initdepth_); - semantic_stack_.reserve (initdepth_); - location_stack_.reserve (initdepth_); - /* Start. */ state_ = 0; looka_ = empty_; @@ -272,7 +416,7 @@ yy::b4_name::parse () } else if (n_ == 0) goto yyerrlab; - + /* Accept? */ if (n_ == final_) goto yyacceptlab; @@ -307,38 +451,40 @@ yy::b4_name::parse () len_ = r2_[[n_]]; if (len_) { - value = semantic_stack_[[1 - len_]]; - location = location_stack_[[1 - len_]]; + yyval = semantic_stack_[[len_ - 1]]; + yyloc = location_stack_[[len_ - 1]]; } else { - value = semantic_stack_[[0]]; - location = location_stack_[[0]]; + yyval = semantic_stack_[[0]]; + yyloc = location_stack_[[0]]; } #if YYDEBUG if (debug_) { YYFPRINTF (stderr, "Reducing via rule %d (line %d), ", n_ - 1, rline_[[n_]]); - for (unsigned i = prhs_[[n_]]; + for (b4_uint_type(b4_prhs_max) i = prhs_[[n_]]; rhs_[[i]] >= 0; ++i) YYFPRINTF (stderr, "%s ", name_[[rhs_[i]]]); YYFPRINTF (stderr, "-> %s\n", name_[[r1_[n_]]]); } #endif - - { - SemanticType& yyval (value); - LocationType& yyloc (location); - SemanticStack& yyvsp (semantic_stack_); - LocationStack& yylsp (location_stack_); - - switch (n_) - { - b4_actions - } - } - + + if (len_) + { + Slice< LocationType, LocationStack > slice (location_stack_, len_); + YYLLOC_DEFAULT (yyloc, slice, len_); + } + + switch (n_) + { + b4_actions + } + +/* Line __line__ of __file__. */ +#line __oline__ "__ofile__" + state_stack_.pop (len_); semantic_stack_.pop (len_); location_stack_.pop (len_); @@ -347,15 +493,15 @@ yy::b4_name::parse () if (debug_) { YYFPRINTF (stderr, "state stack now"); - for (StateStack::ConstIterator i = state_stack_.begin (); + for (StateStack::ConstIterator i = state_stack_.begin (); i != state_stack_.end (); ++i) YYFPRINTF (stderr, " %d", *i); YYFPRINTF (stderr, "\n"); } #endif - - semantic_stack_.push (value); - location_stack_.push (location); + + semantic_stack_.push (yyval); + location_stack_.push (yyloc); /* Shift the result of the reduction. */ n_ = r1_[[n_]]; @@ -372,7 +518,7 @@ yy::b4_name::parse () if (!errstatus) { ++nerrs; - + #if YYERROR_VERBOSE n_ = pact_[[state_]]; if (n_ > flag_ && n_ < last_) @@ -390,7 +536,7 @@ yy::b4_name::parse () for (int x = (n_ < 0 ? -n_ : 0); x < ntokens_ + nnts_; ++x) if (check_[[x + n_]] == x) { - message += (!count++) ? ", expecting " : " or "; + message += (!count++) ? ", expecting " : " or "; message += name_[[x]]; } } @@ -402,7 +548,7 @@ yy::b4_name::parse () error_ (); } goto yyerrlab1; - + /* Error raised explicitly by an action. */ yyerrlab1: if (errstatus == 3) @@ -436,10 +582,10 @@ yy::b4_name::parse () if (debug_) { YYFPRINTF (stderr, "Error: state stack now"); - for (StateStack::ConstIterator i = state_stack_.begin (); + for (StateStack::ConstIterator i = state_stack_.begin (); i != state_stack_.end (); ++i) YYFPRINTF (stderr, " %d", *i); - YYFPRINTF (stderr, "\n"); + YYFPRINTF (stderr, "\n"); } #endif @@ -541,14 +687,14 @@ yy::b4_name::check_[[]] = }; /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */ -const short +const b4_uint_type(b4_r1_max) yy::b4_name::r1_[[]] = { b4_r1 }; /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */ -const short +const b4_uint_type(b4_r2_max) yy::b4_name::r2_[[]] = { b4_r2 @@ -566,7 +712,7 @@ const yy::b4_name::name_[[]] = #if YYDEBUG /* YYRHS -- A `-1'-separated list of the rules' RHS. */ -const short +const yy::b4_name::RhsNumberType yy::b4_name::rhs_[[]] = { b4_rhs @@ -574,14 +720,14 @@ yy::b4_name::rhs_[[]] = /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in YYRHS. */ -const short +const b4_uint_type(b4_prhs_max) yy::b4_name::prhs_[[]] = { b4_prhs }; /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */ -const short +const b4_uint_type(b4_rline_max) yy::b4_name::rline_[[]] = { b4_rline @@ -589,16 +735,19 @@ yy::b4_name::rline_[[]] = #endif /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ -char +yy::b4_name::TokenNumberType yy::b4_name::translate_ (int token) { - static - const char + static + const TokenNumberType translate_[[]] = { b4_translate }; - return ((unsigned)(token) <= maxtok_ ? translate_[[token]] : nsym_); + if ((unsigned) token <= user_token_number_max_) + return translate_[[token]]; + else + return undef_token_; } const int yy::b4_name::eof_ = 0; @@ -613,19 +762,22 @@ const int yy::b4_name::errcode_ = 256; const int yy::b4_name::ntokens_ = b4_ntokens; const int yy::b4_name::initdepth_ = b4_initdepth; -const unsigned yy::b4_name::maxtok_ = b4_maxtok; +const unsigned yy::b4_name::user_token_number_max_ = b4_user_token_number_max; +const yy::b4_name::TokenNumberType yy::b4_name::undef_token_ = b4_undef_token_number; b4_epilogue #output "stack.hh" +b4_copyright + #ifndef BISON_STACK_HH # define BISON_STACK_HH -#include +#include namespace yy { - template < class T, class S = std::vector< T > > + template < class T, class S = std::deque< T > > class Stack { public: @@ -643,23 +795,23 @@ namespace yy inline T& - operator [[]] (int index) + operator [[]] (unsigned index) { - return seq_[[seq_.size () - 1 + index]]; + return seq_[[index]]; } inline const T& - operator [[]] (int index) const + operator [[]] (unsigned index) const { - return seq_[[seq_.size () - 1 + index]]; + return seq_[[index]]; } inline void push (const T& t) { - seq_.push_back (t); + seq_.push_front (t); } inline @@ -667,14 +819,7 @@ namespace yy pop (unsigned n = 1) { for (; n; --n) - seq_.pop_back (); - } - - inline - void - reserve (unsigned n) - { - seq_.reserve (n); + seq_.pop_front (); } inline @@ -691,11 +836,37 @@ namespace yy S seq_; }; + + template < class T, class S = Stack< T > > + class Slice + { + public: + + Slice (const S& stack, + unsigned range) : stack_ (stack), + range_ (range) + { + } + + inline + const T& + operator [[]] (unsigned index) const + { + return stack_[[range_ - index]]; + } + + private: + + const S& stack_; + unsigned range_; + }; } #endif // not BISON_STACK_HH #output "location.hh" +b4_copyright + #ifndef BISON_LOCATION_HH # define BISON_LOCATION_HH @@ -715,37 +886,3 @@ namespace yy } #endif // not BISON_LOCATION_HH - -m4_if(b4_defines_flag, 0, [], -[#output "b4_output_header_name" -#ifndef b4_header_guard -# define b4_header_guard - -b4_tokendef - -#ifndef YYSTYPE -typedef b4_stype -yystype; -# define YYSTYPE yystype -#endif - -m4_if(b4_pure, [0], -[extern YYSTYPE b4_prefix[]lval;]) - -m4_if(b4_locations_flag, [0], [], -[#ifndef YYLTYPE -typedef struct yyltype -{ - int first_line; - int first_column; - int last_line; - int last_column; -} yyltype; -# define YYLTYPE yyltype -#endif - -m4_if(b4_pure, [0], -[extern YYLTYPE b4_prefix[]lloc;]) -]) -#endif /* not b4_header_guard */ -])