Exemplo n.º 1
0
// Puts the given token at the end of the stream.
inline void
Token_stream::put(Token tok)
{
  buf_.push_back(tok);

  // Make sure that the pos_ isn't pointing past
  // then end after insertion into an empty list.
  if (pos_ == buf_.end())
    pos_ = buf_.begin();
}
Exemplo n.º 2
0
// Returns the nth token past the current position.
inline Token
Token_stream::peek(int n) const
{
  // Get the nth token, but restore the stream position
  // afterwards. Note that this will gracefully handle
  // an eof during lookahead.
  Position i = pos_;
  while (i != buf_.end() && n) {
    ++i;
    --n;
  }
  if (i == buf_.end())
    return Token();
  else
    return *i;
}
Exemplo n.º 3
0
// Returns true if the stream is at the end of the file.
inline bool
Token_stream::eof() const
{
  return pos_ == buf_.end();
}
Exemplo n.º 4
0
// Initialize a token stream with an empty
// buffer.
inline
Token_stream::Token_stream()
  : buf_(), pos_(buf_.begin())
{ }