annotate src/tokenizer.h @ 1:551433a01cab

initial coding
author carl
date Wed, 23 Nov 2005 19:29:14 -0800
parents
children 276c4edc8521
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 #ifndef tokenizer_include
551433a01cab initial coding
carl
parents:
diff changeset
22 #define tokenizer_include
551433a01cab initial coding
carl
parents:
diff changeset
23
551433a01cab initial coding
carl
parents:
diff changeset
24 #include <fstream>
551433a01cab initial coding
carl
parents:
diff changeset
25 #include <list>
551433a01cab initial coding
carl
parents:
diff changeset
26 #include <set>
551433a01cab initial coding
carl
parents:
diff changeset
27 #include <stdio.h>
551433a01cab initial coding
carl
parents:
diff changeset
28 #include <ctype.h>
551433a01cab initial coding
carl
parents:
diff changeset
29
551433a01cab initial coding
carl
parents:
diff changeset
30
551433a01cab initial coding
carl
parents:
diff changeset
31 using namespace std;
551433a01cab initial coding
carl
parents:
diff changeset
32
551433a01cab initial coding
carl
parents:
diff changeset
33 struct ltstr {
551433a01cab initial coding
carl
parents:
diff changeset
34 bool operator()(char* s1, char* s2) const {
551433a01cab initial coding
carl
parents:
diff changeset
35 return strcmp(s1, s2) < 0;
551433a01cab initial coding
carl
parents:
diff changeset
36 }
551433a01cab initial coding
carl
parents:
diff changeset
37 };
551433a01cab initial coding
carl
parents:
diff changeset
38
551433a01cab initial coding
carl
parents:
diff changeset
39 typedef list<ifstream *> stream_list;
551433a01cab initial coding
carl
parents:
diff changeset
40 typedef list<char *> string_list;
551433a01cab initial coding
carl
parents:
diff changeset
41 typedef set<char *, ltstr> string_set;
551433a01cab initial coding
carl
parents:
diff changeset
42 typedef list<int> line_list;
551433a01cab initial coding
carl
parents:
diff changeset
43
551433a01cab initial coding
carl
parents:
diff changeset
44 class TOKEN {
551433a01cab initial coding
carl
parents:
diff changeset
45 stream_list streams;
551433a01cab initial coding
carl
parents:
diff changeset
46 string_list filenames;
551433a01cab initial coding
carl
parents:
diff changeset
47 string_set filenamess;
551433a01cab initial coding
carl
parents:
diff changeset
48 line_list linenumbers;
551433a01cab initial coding
carl
parents:
diff changeset
49 string_list pending_tokens;
551433a01cab initial coding
carl
parents:
diff changeset
50 string_set *include_files;
551433a01cab initial coding
carl
parents:
diff changeset
51 bool pushed;
551433a01cab initial coding
carl
parents:
diff changeset
52 u_char pushed_char;
551433a01cab initial coding
carl
parents:
diff changeset
53
551433a01cab initial coding
carl
parents:
diff changeset
54 void pop();
551433a01cab initial coding
carl
parents:
diff changeset
55 bool next_char(u_char &c);
551433a01cab initial coding
carl
parents:
diff changeset
56 void push_char(u_char c);
551433a01cab initial coding
carl
parents:
diff changeset
57
551433a01cab initial coding
carl
parents:
diff changeset
58 public:
551433a01cab initial coding
carl
parents:
diff changeset
59 TOKEN(char *fn, string_set *includes);
551433a01cab initial coding
carl
parents:
diff changeset
60 ~TOKEN();
551433a01cab initial coding
carl
parents:
diff changeset
61 bool include(char *fn);
551433a01cab initial coding
carl
parents:
diff changeset
62 char *next(); // return next token
551433a01cab initial coding
carl
parents:
diff changeset
63 int nextint();
551433a01cab initial coding
carl
parents:
diff changeset
64 void skipeol(); // skip to eol
551433a01cab initial coding
carl
parents:
diff changeset
65 void push(char *token) {pending_tokens.push_front(token);};
551433a01cab initial coding
carl
parents:
diff changeset
66 char *cur_fn() {return filenames.front();};
551433a01cab initial coding
carl
parents:
diff changeset
67 int cur_line() {return linenumbers.front();};
551433a01cab initial coding
carl
parents:
diff changeset
68 void token_error(const char *err);
551433a01cab initial coding
carl
parents:
diff changeset
69 void token_error(const char *fmt, int d, const char *s);
551433a01cab initial coding
carl
parents:
diff changeset
70 void token_error(const char *fmt, const char *t, const char *h);
551433a01cab initial coding
carl
parents:
diff changeset
71 void token_error(const char *want, const char *have);
551433a01cab initial coding
carl
parents:
diff changeset
72 void token_error();
551433a01cab initial coding
carl
parents:
diff changeset
73 };
551433a01cab initial coding
carl
parents:
diff changeset
74
551433a01cab initial coding
carl
parents:
diff changeset
75 #endif