comparison src/tokenizer.h @ 1:551433a01cab

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