comparison src/tokenizer.h @ 13:75e1a9bcbc2e

gpl3, add removal option for original recipients
author carl
date Sat, 25 Aug 2007 11:14:49 -0700
parents 616666e2f34c
children b24369330483
comparison
equal deleted inserted replaced
12:bb3d2cd6007e 13:75e1a9bcbc2e
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 */
1 #ifndef tokenizer_include 8 #ifndef tokenizer_include
2 #define tokenizer_include 9 #define tokenizer_include
3 10
4 #include <fstream> 11 #include <fstream>
5 #include <list> 12 #include <list>
9 16
10 17
11 using namespace std; 18 using namespace std;
12 19
13 struct ltstr { 20 struct ltstr {
14 bool operator()(char* s1, char* s2) const { 21 bool operator()(char* s1, char* s2) const {
15 return strcmp(s1, s2) < 0; 22 return strcmp(s1, s2) < 0;
16 } 23 }
17 }; 24 };
18 25
19 typedef list<ifstream *> stream_list; 26 typedef list<ifstream *> stream_list;
20 typedef list<char *> string_list; 27 typedef list<char *> string_list;
21 typedef set<char *, ltstr> string_set; 28 typedef set<char *, ltstr> string_set;
22 typedef list<int> line_list; 29 typedef list<int> line_list;
23 30
24 class TOKEN { 31 class TOKEN {
25 stream_list streams; 32 stream_list streams;
26 string_list filenames; 33 string_list filenames;
27 string_set filenamess; 34 string_set filenamess;
28 line_list linenumbers; 35 line_list linenumbers;
29 string_list pending_tokens; 36 string_list pending_tokens;
30 string_set *include_files; 37 string_set *include_files;
31 bool pushed; 38 bool pushed;
32 u_char pushed_char; 39 u_char pushed_char;
33 40
34 void pop(); 41 void pop();
35 bool next_char(u_char &c); 42 bool next_char(u_char &c);
36 void push_char(u_char c); 43 void push_char(u_char c);
37 44
38 public: 45 public:
39 TOKEN(char *fn, string_set *includes); 46 TOKEN(char *fn, string_set *includes);
40 ~TOKEN(); 47 ~TOKEN();
41 bool include(char *fn); 48 bool include(char *fn);
42 char *next(); // return next token 49 char *next(); // return next token
43 int nextint(); 50 int nextint();
44 void skipeol(); // skip to eol 51 void skipeol(); // skip to eol
45 void push(char *token) {pending_tokens.push_front(token);}; 52 void push(char *token) {pending_tokens.push_front(token);};
46 char *cur_fn() {return filenames.front();}; 53 char *cur_fn() {return filenames.front();};
47 int cur_line() {return linenumbers.front();}; 54 int cur_line() {return linenumbers.front();};
48 void token_error(const char *err); 55 void token_error(const char *err);
49 void token_error(const char *fmt, int d, const char *s); 56 void token_error(const char *fmt, int d, const char *s);
50 void token_error(const char *fmt, const char *t, const char *h); 57 void token_error(const char *fmt, const char *t, const char *h);
51 void token_error(const char *want, const char *have); 58 void token_error(const char *want, const char *have);
52 void token_error(); 59 void token_error();
53 }; 60 };
54 61
55 #endif 62 #endif