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