annotate src/tokenizer.h @ 2:32b57406b656

initial version
author carl
date Fri, 10 Mar 2006 10:47:12 -0800
parents 616666e2f34c
children 75e1a9bcbc2e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
616666e2f34c initial version
carl
parents:
diff changeset
1 #ifndef tokenizer_include
616666e2f34c initial version
carl
parents:
diff changeset
2 #define tokenizer_include
616666e2f34c initial version
carl
parents:
diff changeset
3
616666e2f34c initial version
carl
parents:
diff changeset
4 #include <fstream>
616666e2f34c initial version
carl
parents:
diff changeset
5 #include <list>
616666e2f34c initial version
carl
parents:
diff changeset
6 #include <set>
616666e2f34c initial version
carl
parents:
diff changeset
7 #include <stdio.h>
616666e2f34c initial version
carl
parents:
diff changeset
8 #include <ctype.h>
616666e2f34c initial version
carl
parents:
diff changeset
9
616666e2f34c initial version
carl
parents:
diff changeset
10
616666e2f34c initial version
carl
parents:
diff changeset
11 using namespace std;
616666e2f34c initial version
carl
parents:
diff changeset
12
616666e2f34c initial version
carl
parents:
diff changeset
13 struct ltstr {
616666e2f34c initial version
carl
parents:
diff changeset
14 bool operator()(char* s1, char* s2) const {
616666e2f34c initial version
carl
parents:
diff changeset
15 return strcmp(s1, s2) < 0;
616666e2f34c initial version
carl
parents:
diff changeset
16 }
616666e2f34c initial version
carl
parents:
diff changeset
17 };
616666e2f34c initial version
carl
parents:
diff changeset
18
616666e2f34c initial version
carl
parents:
diff changeset
19 typedef list<ifstream *> stream_list;
616666e2f34c initial version
carl
parents:
diff changeset
20 typedef list<char *> string_list;
616666e2f34c initial version
carl
parents:
diff changeset
21 typedef set<char *, ltstr> string_set;
616666e2f34c initial version
carl
parents:
diff changeset
22 typedef list<int> line_list;
616666e2f34c initial version
carl
parents:
diff changeset
23
616666e2f34c initial version
carl
parents:
diff changeset
24 class TOKEN {
616666e2f34c initial version
carl
parents:
diff changeset
25 stream_list streams;
616666e2f34c initial version
carl
parents:
diff changeset
26 string_list filenames;
616666e2f34c initial version
carl
parents:
diff changeset
27 string_set filenamess;
616666e2f34c initial version
carl
parents:
diff changeset
28 line_list linenumbers;
616666e2f34c initial version
carl
parents:
diff changeset
29 string_list pending_tokens;
616666e2f34c initial version
carl
parents:
diff changeset
30 string_set *include_files;
616666e2f34c initial version
carl
parents:
diff changeset
31 bool pushed;
616666e2f34c initial version
carl
parents:
diff changeset
32 u_char pushed_char;
616666e2f34c initial version
carl
parents:
diff changeset
33
616666e2f34c initial version
carl
parents:
diff changeset
34 void pop();
616666e2f34c initial version
carl
parents:
diff changeset
35 bool next_char(u_char &c);
616666e2f34c initial version
carl
parents:
diff changeset
36 void push_char(u_char c);
616666e2f34c initial version
carl
parents:
diff changeset
37
616666e2f34c initial version
carl
parents:
diff changeset
38 public:
616666e2f34c initial version
carl
parents:
diff changeset
39 TOKEN(char *fn, string_set *includes);
616666e2f34c initial version
carl
parents:
diff changeset
40 ~TOKEN();
616666e2f34c initial version
carl
parents:
diff changeset
41 bool include(char *fn);
616666e2f34c initial version
carl
parents:
diff changeset
42 char *next(); // return next token
616666e2f34c initial version
carl
parents:
diff changeset
43 int nextint();
616666e2f34c initial version
carl
parents:
diff changeset
44 void skipeol(); // skip to eol
616666e2f34c initial version
carl
parents:
diff changeset
45 void push(char *token) {pending_tokens.push_front(token);};
616666e2f34c initial version
carl
parents:
diff changeset
46 char *cur_fn() {return filenames.front();};
616666e2f34c initial version
carl
parents:
diff changeset
47 int cur_line() {return linenumbers.front();};
616666e2f34c initial version
carl
parents:
diff changeset
48 void token_error(const char *err);
616666e2f34c initial version
carl
parents:
diff changeset
49 void token_error(const char *fmt, int d, const char *s);
616666e2f34c initial version
carl
parents:
diff changeset
50 void token_error(const char *fmt, const char *t, const char *h);
616666e2f34c initial version
carl
parents:
diff changeset
51 void token_error(const char *want, const char *have);
616666e2f34c initial version
carl
parents:
diff changeset
52 void token_error();
616666e2f34c initial version
carl
parents:
diff changeset
53 };
616666e2f34c initial version
carl
parents:
diff changeset
54
616666e2f34c initial version
carl
parents:
diff changeset
55 #endif