1 /* $Id: comm5.c,v 2.13 1994/06/24 13:22:08 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
12 extern YYSTYPE yylval;
19 /* scan the input file */
22 while (isspace(c) && c != '\n');
36 c = instring(c); break;
40 while (c != '\n' && c != '\0');
43 c = CODE1; readcode(1); break;
45 c = CODE2; readcode(2); break;
47 c = CODE4; readcode(4); break;
50 /* produce the intermediate token file */
58 /* read from intermediate token file */
77 assert(c >= 256 && c < 256+128);
87 for (n = 0; n < sizeof(v); n++) {
94 putc(c-128, tempfile);
97 putc((int) (v >> (n*8)), tempfile);
101 n = sizeof(item_t *);
102 p = (char *) &yylval.y_item; break;
106 p = (char *) &yylval.y_strp; break;
110 putc(c-128, tempfile);
111 for (n = 0; n < sizeof(v); n++) {
117 putc(c-128, tempfile);
120 putc((int) (v >> (n*8)), tempfile);
124 putc(*p++, tempfile);
137 p = (char *) &yylval.y_word; break;
139 putc(c-128, tempfile);
141 putc(*p++, tempfile);
148 register char *p = 0;
158 c = NUMBER; goto getnum;
160 n = 1; c = NUMBER; goto getnum;
162 n = 2; c = NUMBER; goto getnum;
164 n = 3; c = NUMBER; goto getnum;
177 n = sizeof(item_t *);
178 p = (char *) &yylval.y_item; break;
182 p = (char *) &yylval.y_strp; break;
185 getval(getc(tempfile)+128);
186 stringlen = n = yylval.y_valu;
200 p = (char *) &yylval.y_word; break;
203 *p++ = getc(tempfile);
207 /* ---------- lexical scan in pass 1 ---------- */
219 if (archmode && --archsize < 0)
222 if ((c = getc(input)) == EOF)
225 fatal("non-ascii character");
241 (archmode && --archsize < 0)
244 (c = getc(input)) == EOF
246 fatal("unexpected EOF in compact input");
255 static short duo[] = {
256 ('='<<8) | '=', OP_EQ,
257 ('<'<<8) | '>', OP_NE,
258 ('<'<<8) | '=', OP_LE,
259 ('>'<<8) | '=', OP_GE,
260 ('<'<<8) | '<', OP_LL,
261 ('>'<<8) | '>', OP_RR,
262 ('|'<<8) | '|', OP_OO,
263 ('&'<<8) | '&', OP_AA,
267 c = (c<<8) | nextchar();
268 for (p = duo; *p; p++)
275 static char name[NAMEMAX+1];
280 register char *p = name;
282 register n = NAMEMAX;
288 } while (ISALNUM(c));
291 ip = item_search(name);
293 ip = item_alloc(S_UND);
294 ip->i_name = remember(name);
295 /* printf("ident %s %o\n", ip->i_name, ip); */
297 item_insert(ip, H_LOCAL + (hashindex%H_SIZE));
298 } else if (hashindex < H_SIZE) {
300 yylval.y_word = (word_t) ip->i_valu;
312 register n = NAMEMAX;
313 register char *p = name;
319 } while (ISALNUM(c));
331 static char num[20+1];
337 fatal("number too long");
342 } while (isalnum(c));
354 } else if (*p == 'b') {
359 if (radix != 16 && (c == 'f' || c == 'b'))
360 return(infbsym(num));
364 c -= ('a' - '9' - 1);
366 if ((unsigned)c >= radix)
367 serror("digit exceeds radix");
368 yylval.y_valu = yylval.y_valu * radix + c;
377 static int maxstring = 0;
380 maxstring = STRINGMAX;
381 if ((stringbuf = malloc(maxstring)) == 0) {
382 fatal("out of memory");
388 if (c == '\n' || c == '\0') {
390 serror("non-terminated string");
397 if (p >= &stringbuf[maxstring - 1]) {
398 int cnt = p - stringbuf;
400 if ((stringbuf = realloc(stringbuf, maxstring += 256)) == 0) {
401 fatal("out of memory");
407 stringlen = p - stringbuf;
417 if (c >= '0' && c <= '7') {
419 for (j = 0; j < 2; j++) {
421 if (c < '0' || c > '7') {
431 case 'b': return('\b');
432 case 'f': return('\f');
433 case 'n': return('\n');
434 case 'r': return('\r');
435 case 't': return('\t');
436 case '\'': return('\'');
437 case '"': return('"');
449 if ((unsigned)lab < 10) {
451 ip = fb_ptr[FB_FORW+lab];
454 fb_ptr[FB_FORW+lab] = ip;
458 ip = fb_ptr[FB_BACK+lab];
459 if (ip != 0 && *p == 0)
462 serror("bad numeric label");
472 register unsigned short h;
490 for (h = hash(p); h < H_TOTAL; h += H_SIZE) {
493 if (strcmp(p, ip->i_name) == 0)
506 ip->i_next = hashtab[h];
518 next = (item_t *) malloc(MEMINCR);
520 fatal("out of memory");
521 nleft += (MEMINCR / sizeof(item_t));
535 register item_t *ip, *p;
537 ip = item_alloc(S_UND);
538 p = fb_ptr[FB_TAIL+lab];
540 fb_ptr[FB_HEAD+lab] = ip;
543 fb_ptr[FB_TAIL+lab] = ip;
553 ip = fb_ptr[FB_FORW+lab];
558 ip = fb_ptr[FB_HEAD+lab];
559 fb_ptr[FB_BACK+lab] = ip;
560 fb_ptr[FB_FORW+lab] = ip->i_next;