1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* @file Scanner.h
*
* @author <a href="mailto:mellmann@informatik.hu-berlin.de">Heinrich Mellmann</a>
* Declaration of class Scanner
*/

#ifndef __Scanner_h_
#define __Scanner_h_

#include <stdio.h>
#include <stdlib.h>

#include <string>
#include <iostream>
#include <cctype>

// defines the maximal length of a token
#define MAX_TOKEN_LENGTH 1024

class Scanner
{
public:

  Scanner(std::istream& inputStream)
    : inputStream(inputStream),
      nextChar(' '),
      bufferLength(0),
      lineNumber(1)
  {
    buffer[0] = '\0';
  }

  virtual ~Scanner(){}

  bool eof();
  bool isToken(std::string token);
  void getNextToken();
  bool endOfFile();

  char buffer[MAX_TOKEN_LENGTH];
  int getLineNumber();

private:
  std::istream& inputStream;
  
  char nextChar;
  int bufferLength;
  virtual bool isTokenChar(char c);
  int lineNumber;

  void getNextChar();
  void skipLine();
  void skipSpace();
};

#endif //__Scanner_h_