1 /*******************************************************
3 * a56 - a DSP56001 assembler
5 * Written by Quinn C. Jensen
8 *******************************************************\
11 * Copyright (C) 1990-1998 Quinn C. Jensen
13 * Permission to use, copy, modify, distribute, and sell this
14 * software and its documentation for any purpose is hereby granted
15 * without fee, provided that the above copyright notice appear in
16 * all copies and that both that copyright notice and this permission
17 * notice appear in supporting documentation. The author makes no
18 * representations about the suitability of this software for any
19 * purpose. It is provided "as is" without express or implied
24 * lex.c - lexical analyzer envelope. lexyy.c, included below,
25 * is the LEX-generated code.
37 printf("[%s]", tok_print(val));\
43 #define RET(val) {return val;}
50 /**************** yylex - returns next token *****************************/
57 int ltok = next_tok();
68 if(itok = is_keyword(tok)) {
71 yylval.sval = strsave(tok);
78 yylval.n.val.i = strtol(tok, 0, 16);
84 yylval.n.val.i = atoi(tok);
90 yylval.n.val.f = atof(tok);
96 yylval.sval = (char *)fixstring(tok);
97 yylval.sval = strsave(yylval.sval);
107 int kval = kparse(tok);
118 #define IS_NONE 0x0000
119 #define IS_NUM 0x0001
120 #define IS_ALPHA 0x0002
121 #define IS_HEX 0x0004
122 #define IS_WHITE 0x0008
129 enum {S_TOP, S_HEXNUM, S_NUM, S_ALNUM, S_CHAR, S_ESC_CHAR, S_COMMENT,
130 S_SQ_STRING, S_DQ_STRING, S_SHL, S_SHR} state = S_TOP;
131 static int unget = 0;
132 BOOL dot_seen = FALSE;
135 int c = unget ? unget : lgetc(yyin);
138 flags = ascii_tab[c & 0x7F].flags;
139 if(tp > tok + MAX_TOK - 2) return LEXBAD;
144 } else if(flags & IS_WHITE) {
146 } else if(flags & IS_ALPHA) {
149 } else if((flags & IS_NUM) || c == '.') {
154 case '$': state = S_HEXNUM; break;
155 case '"': state = S_DQ_STRING; break;
156 case '\'': state = S_CHAR; break;
157 case '>': state = S_SHR; break;
158 case '<': state = S_SHL; break;
159 case ';': state = S_COMMENT; break;
160 case '\n': return EOL;
161 case '@': return EOS;
171 } else if(c == '\n') {
180 } else if(c == '>') {
192 } else if(c == '<') {
204 } else if(flags & IS_HEX) {
218 } else if(c == ':') {
223 } else if(flags & (IS_ALPHA|IS_NUM)) {
236 return dot_seen ? FRAC : CDEC;
237 } else if((flags & IS_NUM) || (c == '.' && NOT dot_seen)) {
239 if(c == '.') dot_seen = TRUE;
244 return dot_seen ? FRAC : CDEC;
252 } else if(c == '\\') {
254 } else if(c == '\'') {
270 case 'b': *tp = '\b'; break;
271 case 'f': *tp = '\f'; break;
272 case 'n': *tp = '\n'; break;
273 case 'r': *tp = '\r'; break;
274 case 't': *tp = '\t'; break;
275 case '\\': *tp = '\\'; break;
291 } else if(c == '\'') {
303 } else if(c == '"') {
310 } /* switch(state) */
314 struct ascii_tab ascii_tab[] = {
315 {"\\z00", IS_NONE /* 0x00 */},
316 {"\\z01", IS_NONE /* 0x01 */},
317 {"\\z02", IS_NONE /* 0x02 */},
318 {"\\z03", IS_NONE /* 0x03 */},
319 {"\\z04", IS_NONE /* 0x04 */},
320 {"\\z05", IS_NONE /* 0x05 */},
321 {"\\z06", IS_NONE /* 0x06 */},
322 {"\\z07", IS_NONE /* 0x07 */},
323 {"\\b", IS_NONE /* 0x08 */},
324 {"\\t", IS_NONE|IS_WHITE /* 0x09 */},
325 {"\\n", IS_NONE /* 0x0A */},
326 {"\\z0B", IS_NONE /* 0x0B */},
327 {"\\z0C", IS_NONE /* 0x0C */},
328 {"\\r", IS_NONE /* 0x0D */},
329 {"\\z0E", IS_NONE /* 0x0E */},
330 {"\\z0F", IS_NONE /* 0x0F */},
331 {"\\z10", IS_NONE /* 0x10 */},
332 {"\\z11", IS_NONE /* 0x11 */},
333 {"\\z12", IS_NONE /* 0x12 */},
334 {"\\z13", IS_NONE /* 0x13 */},
335 {"\\z14", IS_NONE /* 0x14 */},
336 {"\\z15", IS_NONE /* 0x15 */},
337 {"\\z16", IS_NONE /* 0x16 */},
338 {"\\z17", IS_NONE /* 0x17 */},
339 {"\\z18", IS_NONE /* 0x18 */},
340 {"\\z19", IS_NONE /* 0x19 */},
341 {"\\z1A", IS_NONE /* 0x1A */},
342 {"\\z1B", IS_NONE /* 0x1B */},
343 {"\\z1C", IS_NONE /* 0x1C */},
344 {"\\z1D", IS_NONE /* 0x1D */},
345 {"\\z1E", IS_NONE /* 0x1E */},
346 {"\\z1F", IS_NONE /* 0x1F */},
347 {" ", IS_NONE|IS_WHITE /* 0x20 */},
348 {"!", IS_NONE /* 0x21 */},
349 {"\"", IS_NONE /* 0x22 */},
350 {"#", IS_NONE /* 0x23 */},
351 {"$", IS_NONE /* 0x24 */},
352 {"%", IS_NONE /* 0x25 */},
353 {"&", IS_NONE /* 0x26 */},
354 {"'", IS_NONE /* 0x27 */},
355 {"(", IS_NONE /* 0x28 */},
356 {")", IS_NONE /* 0x29 */},
357 {"*", IS_NONE /* 0x2A */},
358 {"+", IS_NONE /* 0x2B */},
359 {",", IS_NONE /* 0x2C */},
360 {"-", IS_NONE /* 0x2D */},
361 {".", IS_NONE /* 0x2E */},
362 {"/", IS_NONE /* 0x2F */},
363 {"0", IS_NONE|IS_NUM|IS_HEX /* 0x30 */},
364 {"1", IS_NONE|IS_NUM|IS_HEX /* 0x31 */},
365 {"2", IS_NONE|IS_NUM|IS_HEX /* 0x32 */},
366 {"3", IS_NONE|IS_NUM|IS_HEX /* 0x33 */},
367 {"4", IS_NONE|IS_NUM|IS_HEX /* 0x34 */},
368 {"5", IS_NONE|IS_NUM|IS_HEX /* 0x35 */},
369 {"6", IS_NONE|IS_NUM|IS_HEX /* 0x36 */},
370 {"7", IS_NONE|IS_NUM|IS_HEX /* 0x37 */},
371 {"8", IS_NONE|IS_NUM|IS_HEX /* 0x38 */},
372 {"9", IS_NONE|IS_NUM|IS_HEX /* 0x39 */},
373 {":", IS_NONE /* 0x3A */},
374 {";", IS_NONE /* 0x3B */},
375 {"<", IS_NONE /* 0x3C */},
376 {"=", IS_NONE /* 0x3D */},
377 {">", IS_NONE /* 0x3E */},
378 {"?", IS_NONE /* 0x3F */},
379 {"@", IS_NONE /* 0x40 */},
380 {"A", IS_NONE|IS_ALPHA|IS_HEX /* 0x41 */},
381 {"B", IS_NONE|IS_ALPHA|IS_HEX /* 0x42 */},
382 {"C", IS_NONE|IS_ALPHA|IS_HEX /* 0x43 */},
383 {"D", IS_NONE|IS_ALPHA|IS_HEX /* 0x44 */},
384 {"E", IS_NONE|IS_ALPHA|IS_HEX /* 0x45 */},
385 {"F", IS_NONE|IS_ALPHA|IS_HEX /* 0x46 */},
386 {"G", IS_NONE|IS_ALPHA /* 0x47 */},
387 {"H", IS_NONE|IS_ALPHA /* 0x48 */},
388 {"I", IS_NONE|IS_ALPHA /* 0x49 */},
389 {"J", IS_NONE|IS_ALPHA /* 0x4A */},
390 {"K", IS_NONE|IS_ALPHA /* 0x4B */},
391 {"L", IS_NONE|IS_ALPHA /* 0x4C */},
392 {"M", IS_NONE|IS_ALPHA /* 0x4D */},
393 {"N", IS_NONE|IS_ALPHA /* 0x4E */},
394 {"O", IS_NONE|IS_ALPHA /* 0x4F */},
395 {"P", IS_NONE|IS_ALPHA /* 0x50 */},
396 {"Q", IS_NONE|IS_ALPHA /* 0x51 */},
397 {"R", IS_NONE|IS_ALPHA /* 0x52 */},
398 {"S", IS_NONE|IS_ALPHA /* 0x53 */},
399 {"T", IS_NONE|IS_ALPHA /* 0x54 */},
400 {"U", IS_NONE|IS_ALPHA /* 0x55 */},
401 {"V", IS_NONE|IS_ALPHA /* 0x56 */},
402 {"W", IS_NONE|IS_ALPHA /* 0x57 */},
403 {"X", IS_NONE|IS_ALPHA /* 0x58 */},
404 {"Y", IS_NONE|IS_ALPHA /* 0x59 */},
405 {"Z", IS_NONE|IS_ALPHA /* 0x5A */},
406 {"[", IS_NONE /* 0x5B */},
407 {"\\", IS_NONE /* 0x5C */},
408 {"]", IS_NONE /* 0x5D */},
409 {"^", IS_NONE /* 0x5E */},
410 {"_", IS_NONE|IS_ALPHA /* 0x5F */},
411 {"`", IS_NONE /* 0x60 */},
412 {"a", IS_NONE|IS_ALPHA|IS_HEX /* 0x61 */},
413 {"b", IS_NONE|IS_ALPHA|IS_HEX /* 0x62 */},
414 {"c", IS_NONE|IS_ALPHA|IS_HEX /* 0x63 */},
415 {"d", IS_NONE|IS_ALPHA|IS_HEX /* 0x64 */},
416 {"e", IS_NONE|IS_ALPHA|IS_HEX /* 0x65 */},
417 {"f", IS_NONE|IS_ALPHA|IS_HEX /* 0x66 */},
418 {"g", IS_NONE|IS_ALPHA /* 0x67 */},
419 {"h", IS_NONE|IS_ALPHA /* 0x68 */},
420 {"i", IS_NONE|IS_ALPHA /* 0x69 */},
421 {"j", IS_NONE|IS_ALPHA /* 0x6A */},
422 {"k", IS_NONE|IS_ALPHA /* 0x6B */},
423 {"l", IS_NONE|IS_ALPHA /* 0x6C */},
424 {"m", IS_NONE|IS_ALPHA /* 0x6D */},
425 {"n", IS_NONE|IS_ALPHA /* 0x6E */},
426 {"o", IS_NONE|IS_ALPHA /* 0x6F */},
427 {"p", IS_NONE|IS_ALPHA /* 0x70 */},
428 {"q", IS_NONE|IS_ALPHA /* 0x71 */},
429 {"r", IS_NONE|IS_ALPHA /* 0x72 */},
430 {"s", IS_NONE|IS_ALPHA /* 0x73 */},
431 {"t", IS_NONE|IS_ALPHA /* 0x74 */},
432 {"u", IS_NONE|IS_ALPHA /* 0x75 */},
433 {"v", IS_NONE|IS_ALPHA /* 0x76 */},
434 {"w", IS_NONE|IS_ALPHA /* 0x77 */},
435 {"x", IS_NONE|IS_ALPHA /* 0x78 */},
436 {"y", IS_NONE|IS_ALPHA /* 0x79 */},
437 {"z", IS_NONE|IS_ALPHA /* 0x7A */},
438 {"{", IS_NONE /* 0x7B */},
439 {"|", IS_NONE /* 0x7C */},
440 {"}", IS_NONE /* 0x7D */},
441 {"~", IS_NONE /* 0x7E */},
442 {"\\z7F", IS_NONE /* 0x7F */},
446 /**************** lgetc - returns next character *************************/
450 char line_buf[INLINE];
451 char *cur_line = line_buf; /* points to current line buffer */
452 char *clp = NULL; /* where we're at in cur_line */
460 if(fgets(cur_line, INLINE, fp) == NULL) {
472 /* at EOF: all done */
487 printf(c < ' ' ? "<\\z%02X>%s" : "<%c>", c, c == '\n' ? "\n" : "");