0
|
1 /*
|
|
2
|
|
3 Copyright (c) 2007 Carl Byington - 510 Software Group, released under
|
|
4 the GPL version 3 or any later version at your choice available at
|
|
5 http://www.gnu.org/licenses/gpl-3.0.txt
|
|
6
|
|
7 */
|
|
8
|
|
9 using namespace std;
|
|
10
|
|
11 struct ltstr {
|
|
12 bool operator()(const char* s1, const char* s2) const {
|
|
13 return strcmp(s1, s2) < 0;
|
|
14 }
|
|
15 };
|
|
16
|
|
17 typedef list<ifstream *> stream_list;
|
|
18 typedef list<const char *> string_list;
|
|
19 typedef set<const char *, ltstr> string_set;
|
|
20 typedef list<int> line_list;
|
|
21
|
|
22 class TOKEN {
|
|
23 stream_list streams;
|
|
24 string_list filenames;
|
|
25 string_set filenamess;
|
|
26 line_list linenumbers;
|
|
27 string_list pending_tokens;
|
|
28 string_set *include_files;
|
|
29 bool pushed;
|
|
30 u_char pushed_char;
|
|
31
|
|
32 void pop();
|
|
33 bool next_char(u_char &c);
|
|
34 void push_char(u_char c);
|
|
35
|
|
36 public:
|
|
37 TOKEN(const char *fn, string_set *includes);
|
|
38 ~TOKEN();
|
|
39 bool include(const char *fn);
|
|
40 const char *next(); // return next token
|
|
41 int nextint();
|
|
42 void skipeol(); // skip to eol
|
|
43 void push(const char *token) {pending_tokens.push_front(token);};
|
|
44 const char *cur_fn() {return filenames.empty() ? "" : filenames.front();};
|
|
45 int cur_line() {return linenumbers.empty() ? 0 : linenumbers.front();};
|
|
46 void token_error(const char *err);
|
|
47 void token_error(const char *fmt, int d, const char *s);
|
|
48 void token_error(const char *fmt, const char *t, const char *h);
|
|
49 void token_error(const char *want, const char *have);
|
|
50 void token_error();
|
|
51 };
|
|
52
|