Subversion Repositories tendra.SVN

Rev

Rev 5 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
/*
6 7u83 31
 *  AUTOMATICALLY GENERATED BY lexi VERSION 1.2
32
 */
2 7u83 33
 
34
 
35
/* LOOKUP TABLE */
36
 
6 7u83 37
static unsigned char lookup_tab[257] = {
2 7u83 38
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
39
    0x0000, 0x0001, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000,
40
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
41
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
42
    0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
43
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
44
    0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c, 0x001c,
45
    0x001c, 0x001c, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
46
    0x0000, 0x001a, 0x001a, 0x001a, 0x001a, 0x001a, 0x001a, 0x000a,
47
    0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a,
48
    0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a,
49
    0x000a, 0x000a, 0x000a, 0x0000, 0x0000, 0x0000, 0x0000, 0x000a,
50
    0x0000, 0x001a, 0x001a, 0x001a, 0x001a, 0x001a, 0x001a, 0x000a,
51
    0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a,
52
    0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x000a,
53
    0x000a, 0x000a, 0x000a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
54
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
55
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
56
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
57
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
58
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
59
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
60
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
61
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
62
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
63
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
64
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
65
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
66
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
67
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
68
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
69
    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
70
    0x0000
6 7u83 71
};
2 7u83 72
 
73
#ifndef LEX_EOF
6 7u83 74
#define LEX_EOF		256
2 7u83 75
#endif
76
 
6 7u83 77
#define lookup_char(C)	((int)lookup_tab[(C)])
78
#define is_white(T)	((T) & 0x0001)
79
#define is_alpha(T)	((T) & 0x0002)
80
#define is_digit(T)	((T) & 0x0004)
81
#define is_alphanum(T)	((T) & 0x0008)
82
#define is_hexdigit(T)	((T) & 0x0010)
2 7u83 83
 
84
 
85
/* MAIN PASS ANALYSER */
86
 
6 7u83 87
int
88
read_token(void)
2 7u83 89
{
6 7u83 90
    start: {
91
	int c0 = read_char(), t0;
92
	t0 = lookup_char(c0);
93
	if (is_white(t0)) goto start;
94
	switch (c0) {
95
	    case '!': {
96
		return(lex_exclaim);
2 7u83 97
	    }
6 7u83 98
	    case '"': {
99
		return(get_string(c0));
2 7u83 100
	    }
6 7u83 101
	    case '#': {
102
		return(lex_hash);
2 7u83 103
	    }
6 7u83 104
	    case '%': {
105
		return(lex_rem);
2 7u83 106
	    }
6 7u83 107
	    case '&': {
108
		return(lex_and);
2 7u83 109
	    }
6 7u83 110
	    case '(': {
111
		return(lex_open_Hround);
2 7u83 112
	    }
6 7u83 113
	    case ')': {
114
		return(lex_close_Hround);
2 7u83 115
	    }
6 7u83 116
	    case '*': {
117
		return(lex_star);
2 7u83 118
	    }
6 7u83 119
	    case '+': {
120
		return(lex_plus);
2 7u83 121
	    }
6 7u83 122
	    case ',': {
123
		return(lex_comma);
2 7u83 124
	    }
6 7u83 125
	    case '-': {
126
		int c1 = read_char();
127
		if (c1 == '>') {
128
		    return(lex_arrow);
2 7u83 129
		}
6 7u83 130
		unread_char(c1);
131
		return(lex_minus);
2 7u83 132
	    }
6 7u83 133
	    case '.': {
134
		return(lex_dot);
2 7u83 135
	    }
6 7u83 136
	    case '/': {
137
		int c1 = read_char();
138
		if (c1 == '*') {
139
		    return(get_comment(c0, c1));
2 7u83 140
		}
6 7u83 141
		unread_char(c1);
142
		return(lex_div);
2 7u83 143
	    }
6 7u83 144
	    case '0': {
145
		int c1 = read_char();
146
		if (c1 == 'X') {
147
		    int c2 = read_char(), t2;
148
		    t2 = lookup_char(c2);
149
		    if (is_hexdigit(t2)) {
150
			return(get_hex(c0, c1, c2));
2 7u83 151
		    }
6 7u83 152
		    unread_char(c2);
153
		} else if (c1 == 'x') {
154
		    int c2 = read_char(), t2;
155
		    t2 = lookup_char(c2);
156
		    if (is_hexdigit(t2)) {
157
			return(get_hex(c0, c1, c2));
2 7u83 158
		    }
6 7u83 159
		    unread_char(c2);
2 7u83 160
		}
6 7u83 161
		unread_char(c1);
162
		break;
2 7u83 163
	    }
6 7u83 164
	    case ':': {
165
		int c1 = read_char();
166
		if (c1 == ':') {
167
		    return(lex_colon_Hcolon);
2 7u83 168
		}
6 7u83 169
		unread_char(c1);
170
		return(lex_colon);
2 7u83 171
	    }
6 7u83 172
	    case ';': {
173
		return(lex_semicolon);
2 7u83 174
	    }
6 7u83 175
	    case '<': {
176
		int c1 = read_char();
177
		if (c1 == '<') {
178
		    return(lex_lshift);
2 7u83 179
		}
6 7u83 180
		unread_char(c1);
181
		break;
2 7u83 182
	    }
6 7u83 183
	    case '=': {
184
		return(lex_equal);
2 7u83 185
	    }
6 7u83 186
	    case '>': {
187
		int c1 = read_char();
188
		if (c1 == '>') {
189
		    return(lex_rshift);
2 7u83 190
		}
6 7u83 191
		unread_char(c1);
192
		break;
2 7u83 193
	    }
6 7u83 194
	    case '?': {
195
		return(lex_question);
2 7u83 196
	    }
6 7u83 197
	    case '[': {
198
		return(lex_open_Hsquare);
2 7u83 199
	    }
6 7u83 200
	    case ']': {
201
		return(lex_close_Hsquare);
2 7u83 202
	    }
6 7u83 203
	    case '^': {
204
		return(lex_xor);
2 7u83 205
	    }
6 7u83 206
	    case '{': {
207
		return(lex_open_Hbrace);
2 7u83 208
	    }
6 7u83 209
	    case '|': {
210
		return(lex_or);
2 7u83 211
	    }
6 7u83 212
	    case '}': {
213
		return(lex_close_Hbrace);
2 7u83 214
	    }
6 7u83 215
	    case '~': {
216
		return(lex_compl);
2 7u83 217
	    }
6 7u83 218
	    case LEX_EOF: {
219
		return(lex_eof);
2 7u83 220
	    }
221
	}
6 7u83 222
	if (is_alpha(t0)) {
223
	    return(get_identifier(c0));
224
	} else if (is_digit(t0)) {
225
	    return(get_number(c0));
2 7u83 226
	}
6 7u83 227
	return(unknown_token(c0));
2 7u83 228
    }
229
}