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