71
|
1 #include <fstream>
|
|
2 #include <list>
|
|
3 #include <set>
|
|
4
|
|
5
|
|
6 using namespace std;
|
|
7
|
|
8 struct ltstr {
|
|
9 bool operator()(char* s1, char* s2) const {
|
|
10 return strcmp(s1, s2) < 0;
|
|
11 }
|
|
12 };
|
|
13
|
|
14 typedef list<ifstream *> stream_list;
|
|
15 typedef list<char *> string_list;
|
|
16 typedef set<char *, ltstr> string_set;
|
|
17 typedef list<int> line_list;
|
|
18
|
|
19 class TOKEN {
|
|
20 stream_list streams;
|
|
21 string_list filenames;
|
|
22 string_set filenamess;
|
|
23 line_list linenumbers;
|
|
24 string_list pending_tokens;
|
|
25 string_set *include_files;
|
|
26 bool pushed;
|
|
27 u_char pushed_char;
|
|
28
|
|
29 void pop();
|
|
30 bool next_char(u_char &c);
|
|
31 void push_char(u_char c);
|
|
32
|
|
33 public:
|
|
34 TOKEN(char *fn, string_set *includes);
|
|
35 ~TOKEN();
|
|
36 bool include(char *fn);
|
|
37 char *next(); // return next token
|
|
38 int nextint();
|
|
39 void skipeol(); // skip to eol
|
|
40 void push(char *token) {pending_tokens.push_front(token);};
|
|
41 char *cur_fn() {return filenames.front();};
|
|
42 int cur_line() {return linenumbers.front();};
|
|
43 void token_error(const char *err);
|
|
44 void token_error(const char *fmt, int d, const char *s);
|
|
45 void token_error(const char *fmt, const char *t, const char *h);
|
|
46 void token_error(const char *token, const char *have);
|
|
47 void token_error();
|
|
48 };
|
|
49
|