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