comparison src/tokenizer.h @ 0:616666e2f34c

initial version
author carl
date Fri, 10 Mar 2006 10:30:08 -0800
parents
children 75e1a9bcbc2e
comparison
equal deleted inserted replaced
-1:000000000000 0:616666e2f34c
1 #ifndef tokenizer_include
2 #define tokenizer_include
3
4 #include <fstream>
5 #include <list>
6 #include <set>
7 #include <stdio.h>
8 #include <ctype.h>
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);
51 void token_error(const char *want, const char *have);
52 void token_error();
53 };
54
55 #endif