annotate src/tokenizer.h @ 80:858aec84fe13 default tip

Added tag stable-1-0-18 for changeset 831d0b46bbd2
author Carl Byington <carl@five-ten-sg.com>
date Wed, 15 Jul 2020 14:29:47 -0700
parents ba0259c9e411
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
6a2f26976898 shutdown removes iptables entries that we added
carl
parents: 9
diff changeset
1 /*
1
551433a01cab initial coding
carl
parents:
diff changeset
2
36
6a2f26976898 shutdown removes iptables entries that we added
carl
parents: 9
diff changeset
3 Copyright (c) 2007 Carl Byington - 510 Software Group, released under
6a2f26976898 shutdown removes iptables entries that we added
carl
parents: 9
diff changeset
4 the GPL version 3 or any later version at your choice available at
6a2f26976898 shutdown removes iptables entries that we added
carl
parents: 9
diff changeset
5 http://www.gnu.org/licenses/gpl-3.0.txt
6a2f26976898 shutdown removes iptables entries that we added
carl
parents: 9
diff changeset
6
6a2f26976898 shutdown removes iptables entries that we added
carl
parents: 9
diff changeset
7 */
1
551433a01cab initial coding
carl
parents:
diff changeset
8
551433a01cab initial coding
carl
parents:
diff changeset
9 using namespace std;
551433a01cab initial coding
carl
parents:
diff changeset
10
551433a01cab initial coding
carl
parents:
diff changeset
11 struct ltstr {
48
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
12 bool operator()(const char* s1, const char* s2) const {
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
13 return strcmp(s1, s2) < 0;
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
14 }
1
551433a01cab initial coding
carl
parents:
diff changeset
15 };
551433a01cab initial coding
carl
parents:
diff changeset
16
48
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
17 typedef list<ifstream *> stream_list;
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
18 typedef list<const char *> string_list;
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
19 typedef set<const char *, ltstr> string_set;
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
20 typedef list<int> line_list;
1
551433a01cab initial coding
carl
parents:
diff changeset
21
551433a01cab initial coding
carl
parents:
diff changeset
22 class TOKEN {
48
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
23 stream_list streams;
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
24 string_list filenames;
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
25 string_set filenamess;
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
26 line_list linenumbers;
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
27 string_list pending_tokens;
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
28 string_set *include_files;
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
29 bool pushed;
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
30 u_char pushed_char;
1
551433a01cab initial coding
carl
parents:
diff changeset
31
48
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
32 void pop();
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
33 bool next_char(u_char &c);
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
34 void push_char(u_char c);
1
551433a01cab initial coding
carl
parents:
diff changeset
35
551433a01cab initial coding
carl
parents:
diff changeset
36 public:
48
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
37 TOKEN(const char *fn, string_set *includes);
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
38 ~TOKEN();
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
39 bool include(const char *fn);
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
40 const char *next(); // return next token
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
41 int nextint();
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
42 void skipeol(); // skip to eol
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
43 void push(const char *token) {pending_tokens.push_front(token);};
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
44 const char *cur_fn() {return filenames.empty() ? "" : filenames.front();};
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
45 int cur_line() {return linenumbers.empty() ? 0 : linenumbers.front();};
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
46 void token_error(const char *err);
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
47 void token_error(const char *fmt, int d, const char *s);
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
48 void token_error(const char *fmt, const char *t, const char *h);
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
49 void token_error(const char *want, const char *have);
ba0259c9e411 Fixes to compile on Fedora 9 and for const correctness
Carl Byington <carl@five-ten-sg.com>
parents: 36
diff changeset
50 void token_error();
1
551433a01cab initial coding
carl
parents:
diff changeset
51 };
551433a01cab initial coding
carl
parents:
diff changeset
52