// 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; }
// 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(); }
// Returns true if the stream is at the end of the file. inline bool Token_stream::eof() const { return pos_ == buf_.end(); }