From: Robert Anisko Date: Thu, 2 May 2002 16:43:00 +0000 (+0000) Subject: * data/bison.c++: Adapt expansion of $s and @s to the C++ parser. X-Git-Tag: BISON-1_49b~256 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/45119f0446d8df8e9c54498194f120c20aa24c83?ds=sidebyside * data/bison.c++: Adapt expansion of $s and @s to the C++ parser. Update the stack class, give a try to deque as the default container. --- diff --git a/ChangeLog b/ChangeLog index 819c6d2d..25d8956d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2002-05-02 Robert Anisko + + * data/bison.c++: Adapt expansion of $s and @s to the C++ parser. + Update the stack class, give a try to deque as the default container. + 2002-05-02 Akim Demaille * data/bison.simple (yyparse): Do not implement @$ = @1. diff --git a/data/bison.c++ b/data/bison.c++ index 41f3dec0..b0ba32f4 100644 --- a/data/bison.c++ +++ b/data/bison.c++ @@ -32,7 +32,7 @@ m4_define([b4_lhs_value], # Expansion of $NUM, where the current rule has RULE-LENGTH # symbols on RHS. m4_define([b4_rhs_value], -[yyvsp@<:@m4_eval([$2 - $1])@:>@m4_ifval([$3], [.$3])]) +[semantic_stack_@<:@m4_eval([$1 - $2])@:>@m4_ifval([$3], [.$3])]) # b4_lhs_location() @@ -47,7 +47,7 @@ m4_define([b4_lhs_location], # Expansion of @NUM, where the current rule has RULE-LENGTH symbols # on RHS. m4_define([b4_rhs_location], -[yylsp@<:@m4_eval([$2 - $1])@:>@]) +[location_stack_@<:@m4_eval([$1 - $2])@:>@]) # b4_token_defines(TOKEN-NAME, TOKEN-NUMBER) @@ -351,12 +351,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_; @@ -459,8 +453,8 @@ yy::b4_name::parse () len_ = r2_[[n_]]; if (len_) { - yyval = semantic_stack_[[1 - len_]]; - yyloc = location_stack_[[1 - len_]]; + yyval = semantic_stack_[[len_ - 1]]; + yyloc = location_stack_[[len_ - 1]]; } else { @@ -485,15 +479,10 @@ yy::b4_name::parse () YYLLOC_DEFAULT (yyloc, slice, len_); } - { - SemanticStack& yyvsp (semantic_stack_); - LocationStack& yylsp (location_stack_); - - switch (n_) - { - b4_actions - } - } + switch (n_) + { + b4_actions + } /* Line __line__ of __file__. */ #line __oline__ "__ofile__" @@ -786,11 +775,11 @@ 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: @@ -808,23 +797,23 @@ namespace yy inline T& - operator [[]] (int index) + operator [[]] (unsigned index) { - return seq_[[height () - 1 + index]]; + return seq_[[index]]; } inline const T& - operator [[]] (int index) const + operator [[]] (unsigned index) const { - return seq_[[height () - 1 + index]]; + return seq_[[index]]; } inline void push (const T& t) { - seq_.push_back (t); + seq_.push_front (t); } inline @@ -832,14 +821,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 @@ -872,7 +854,7 @@ namespace yy const T& operator [[]] (unsigned index) const { - return stack_[[index - range_]]; + return stack_[[range_ - index]]; } private: