annotate src/tokenizer.h @ 25:caff690d7766

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