home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 31 / CDASC_31_1996_juillet_aout.iso / vrac / cuj0796.zip / SAKS.ZIP / SCANNER.H < prev    next >
C/C++ Source or Header  |  1996-04-22  |  1KB  |  71 lines

  1. Listing 1 - Definitions for the scanner and token classes
  2. that can look ahead at most one token.
  3.  
  4. //
  5. // scanner.h
  6. //
  7. // Copyright (C) 1996 by Dan Saks.
  8. // May be copied for private, non-commercial use,
  9. // provided this copyright notice remains intact.
  10. // All other rights reserved.
  11. //
  12.  
  13. #ifndef SCANNER_H_INCLUDED
  14. #define SCANNER_H_INCLUDED
  15.  
  16. #include <iostream.h>
  17. #include <limits.h>
  18. #include <string>
  19.  
  20. class token
  21.     {
  22.     friend class scanner;
  23. public:
  24.     enum category
  25.         {
  26.         AMPERSAND = '&',
  27.         COMMA = ',',
  28.         ...
  29.         };
  30.     token();
  31.     string text() const;
  32.     category kind() const;
  33. private:
  34.     token(category, const string &);
  35.     category the_kind;
  36.     string the_text;
  37.     };
  38.  
  39. const char *image(token::category);
  40.  
  41. class scanner
  42.     {
  43. public:
  44.     scanner(istream &);
  45.     token get();
  46.     token unget();
  47.     token current() const;
  48.     void reset();
  49. private:
  50.     token scan();
  51.     token previous_token;
  52.     token current_token;
  53.     token next_token;
  54.     istream &in_stream;
  55.     struct pair
  56.         {
  57.         char const *text;
  58.         token::category kind;
  59.         };
  60.     static pair const keyword[];
  61.     scanner(const scanner &);
  62.     scanner &operator=(const scanner &);
  63.     };
  64.  
  65. //
  66. // inline function definitions ...
  67. //
  68.  
  69. #endif
  70.  
  71.