1
|
1 /***************************************************************************
|
|
2 * Copyright (C) 2005 by 510 Software Group *
|
|
3 * *
|
|
4 * *
|
|
5 * This program is free software; you can redistribute it and/or modify *
|
|
6 * it under the terms of the GNU General Public License as published by *
|
|
7 * the Free Software Foundation; either version 2 of the License, or *
|
|
8 * (at your option) any later version. *
|
|
9 * *
|
|
10 * This program is distributed in the hope that it will be useful, *
|
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
13 * GNU General Public License for more details. *
|
|
14 * *
|
|
15 * You should have received a copy of the GNU General Public License *
|
|
16 * along with this program; if not, write to the *
|
|
17 * Free Software Foundation, Inc., *
|
|
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
19 ***************************************************************************/
|
|
20
|
|
21
|
|
22
|
|
23 using namespace std;
|
|
24
|
|
25 struct ltstr {
|
|
26 bool operator()(char* s1, char* s2) const {
|
|
27 return strcmp(s1, s2) < 0;
|
|
28 }
|
|
29 };
|
|
30
|
|
31 typedef list<ifstream *> stream_list;
|
|
32 typedef list<char *> string_list;
|
|
33 typedef set<char *, ltstr> string_set;
|
|
34 typedef list<int> line_list;
|
|
35
|
|
36 class TOKEN {
|
|
37 stream_list streams;
|
|
38 string_list filenames;
|
|
39 string_set filenamess;
|
|
40 line_list linenumbers;
|
|
41 string_list pending_tokens;
|
|
42 string_set *include_files;
|
|
43 bool pushed;
|
|
44 u_char pushed_char;
|
|
45
|
|
46 void pop();
|
|
47 bool next_char(u_char &c);
|
|
48 void push_char(u_char c);
|
|
49
|
|
50 public:
|
|
51 TOKEN(char *fn, string_set *includes);
|
|
52 ~TOKEN();
|
5
|
53 bool include(char *fn);
|
|
54 char *next(); // return next token
|
|
55 int nextint();
|
|
56 void skipeol(); // skip to eol
|
|
57 void push(char *token) {pending_tokens.push_front(token);};
|
|
58 const char *cur_fn() {return filenames.empty() ? "" : filenames.front();};
|
|
59 int cur_line() {return linenumbers.empty() ? 0 : linenumbers.front();};
|
|
60 void token_error(const char *err);
|
|
61 void token_error(const char *fmt, int d, const char *s);
|
|
62 void token_error(const char *fmt, const char *t, const char *h);
|
|
63 void token_error(const char *want, const char *have);
|
|
64 void token_error();
|
1
|
65 };
|
|
66
|