summaryrefslogtreecommitdiffstats
path: root/TokenStream.h
blob: e168a3d021662b69bbb693e387b92c8b7c523670 (plain) (blame)
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
58
#ifndef TOKENSTREAM_H_
#define TOKENSTREAM_H_

#include <string>
#include <vector>

class TokenStream;

class TokenPoint
{
	public:
		TokenPoint(TokenStream& S);
		~TokenPoint();

		bool accept();
		bool reject();

	private:
		TokenPoint& operator=(const TokenPoint&)
		{
			return *this;
		}
		TokenStream& Stream;
		unsigned int Pos;
};

class TokenStream
{
	public:
		TokenStream();
		TokenStream(const std::string& Input);

		bool eos() const;
		bool eosButWhite();
		std::string makeFileName();
		std::string cIdentifier();
		std::string cToken();
		std::string cString();
		bool whiteSpace();
		bool literal(const std::string& S);

		void error(const std::string& Err);
		unsigned int errors() const;

	private:
		bool literal(char c);
		bool alpha();
		bool numeric();

		std::string Content;
		std::vector<unsigned int> LineNo;
		unsigned int Index;
		unsigned int Errors;

		friend class TokenPoint;
};

#endif