// File: token.h
//
// Token and TokenStream class declarations

#ifndef _token_h
#define _token_h

#include "iostream.h"


class Token {
public:
   enum {UNDEF, NUMBER, PLUS, MINUS, TIMES, DIVIDE, L_PAREN, R_PAREN, EOL} ;

   int kind ;   // what kind of token?
   int value ;  // value if any associated with this token

   Token() : kind(UNDEF), value(0) {}
   Token(const Token& t) { kind = t.kind ; value = t.value ; }
} ;

ostream& operator <<(ostream&, const Token&) ;


class TokenStream {
public:
   TokenStream(const char *);   // constructor requires a string
   ~TokenStream() ;             // destructor

   Token look() ;               // get lookahead token
   void eat() ;                 // consume next token
   void error() ;               // generate error diagram

private:
   char *str ;                  // input string
   int pos ;                    // current position
   int last ;                   // last position
   int looked ;                 // = 1, if looked ahead. = 0, otherwise
   int lookahead_pos ;          // stopped scanning here, after looking
   Token lookahead ;            // lookahead token cached

   void skip_spaces(int) ;       // skip over white space
} ;


#endif
