* data/bison.c++: Unmerge value as yylval and value as yyval. Unmerge

location as yylloc and location as yyloc.  Use YYLLOC_DEFAULT, and
provide a default implementation.
This commit is contained in:
Robert Anisko
2002-03-04 16:37:52 +00:00
parent bfcf1f3af0
commit 374f5a14de
2 changed files with 57 additions and 11 deletions

View File

@@ -1,3 +1,9 @@
2002-03-04 Robert Anisko <robert@lrde.epita.fr>
* data/bison.c++: Unmerge value as yylval and value as yyval. Unmerge
location as yylloc and location as yyloc. Use YYLLOC_DEFAULT, and
provide a default implementation.
2002-03-04 Akim Demaille <akim@epita.fr> 2002-03-04 Akim Demaille <akim@epita.fr>
* tests/input.at (Invalid $n, Invalid @n): Add the ending `;'. * tests/input.at (Invalid $n, Invalid @n): Add the ending `;'.

View File

@@ -88,6 +88,12 @@ yystype;
# define YYSTYPE yystype # define YYSTYPE yystype
#endif #endif
#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], [], m4_if(b4_locations_flag, [0], [],
[#ifndef YYLTYPE [#ifndef YYLTYPE
typedef struct yyltype typedef struct yyltype
@@ -210,10 +216,14 @@ namespace yy
/* Message. */ /* Message. */
std::string message; std::string message;
/* @$ and $$. */ /* Semantic value and location of lookahead token. */
SemanticType value; SemanticType value;
LocationType location; LocationType location;
/* @$ and $$. */
SemanticType yyval;
LocationType yyloc;
/* Initial location. */ /* Initial location. */
LocationType initlocation_; LocationType initlocation_;
}; };
@@ -358,13 +368,13 @@ yy::b4_name::parse ()
len_ = r2_[[n_]]; len_ = r2_[[n_]];
if (len_) if (len_)
{ {
value = semantic_stack_[[1 - len_]]; yyval = semantic_stack_[[1 - len_]];
location = location_stack_[[1 - len_]]; yyloc = location_stack_[[1 - len_]];
} }
else else
{ {
value = semantic_stack_[[0]]; yyval = semantic_stack_[[0]];
location = location_stack_[[0]]; yyloc = location_stack_[[0]];
} }
#if YYDEBUG #if YYDEBUG
@@ -378,9 +388,15 @@ yy::b4_name::parse ()
} }
#endif #endif
if (len_)
{
Slice< LocationType, LocationStack > slice (location_stack_, len_);
YYLLOC_DEFAULT (yyloc, slice, len_);
}
std::cout << "Reduced location is :" << yyloc << std::endl;
{ {
SemanticType& yyval (value);
LocationType& yyloc (location);
SemanticStack& yyvsp (semantic_stack_); SemanticStack& yyvsp (semantic_stack_);
LocationStack& yylsp (location_stack_); LocationStack& yylsp (location_stack_);
@@ -405,8 +421,8 @@ yy::b4_name::parse ()
} }
#endif #endif
semantic_stack_.push (value); semantic_stack_.push (yyval);
location_stack_.push (location); location_stack_.push (yyloc);
/* Shift the result of the reduction. */ /* Shift the result of the reduction. */
n_ = r1_[[n_]]; n_ = r1_[[n_]];
@@ -698,14 +714,14 @@ namespace yy
T& T&
operator [[]] (int index) operator [[]] (int index)
{ {
return seq_[[seq_.size () - 1 + index]]; return seq_[[height () - 1 + index]];
} }
inline inline
const T& const T&
operator [[]] (int index) const operator [[]] (int index) const
{ {
return seq_[[seq_.size () - 1 + index]]; return seq_[[height () - 1 + index]];
} }
inline inline
@@ -744,6 +760,30 @@ namespace yy
S seq_; 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_[[index - range_]];
}
private:
const S& stack_;
unsigned range_;
};
} }
#endif // not BISON_STACK_HH #endif // not BISON_STACK_HH