/[projet1]/public/pc/tools/osdk/main/compiler/sources/lex.c
Defence Force logotype

Contents of /public/pc/tools/osdk/main/compiler/sources/lex.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1139 - (show annotations)
Fri May 16 08:24:20 2014 UTC (5 years, 6 months ago) by Jylam
File MIME type: text/plain
File size: 18282 byte(s)
Add support for binary constants (0b11111111)

1 /* C compiler: lexical analysis */
2 #include "c.h"
3
4 int printf(const char *,...);
5
6 char kind[] = { /* token kind, i.e., classification */
7 #define xx(a,b,c,d,e,f,g) f,
8 #include "token.h"
9 };
10 Coordinate src; /* current source coordinate */
11 enum tokencode t;
12 char *token; /* current token */
13 Symbol tsym; /* symbol table entry for current token */
14
15 static struct symbol tval; /* symbol for constants */
16
17 enum { BLANK=01, NEWLINE=02, LETTER=04, DIGIT=010, HEX=020, BAD=040 };
18
19
20 static unsigned char map[256] =
21 {
22 /* 000 nul */ BAD,
23 /* 001 soh */ BAD,
24 /* 002 stx */ BAD,
25 /* 003 etx */ BAD,
26 /* 004 eot */ BAD,
27 /* 005 enq */ BAD,
28 /* 006 ack */ BAD,
29 /* 007 bel */ BAD,
30 /* 010 bs */ BLANK|BAD,
31 /* 011 ht */ BLANK,
32 /* 012 nl */ NEWLINE,
33 /* 013 vt */ BLANK,
34 /* 014 ff */ BLANK,
35 /* 015 cr */ BAD,
36 /* 016 so */ BAD,
37 /* 017 si */ BAD,
38 /* 020 dle */ BAD,
39 /* 021 dc1 */ BAD,
40 /* 022 dc2 */ BAD,
41 /* 023 dc3 */ BAD,
42 /* 024 dc4 */ BAD,
43 /* 025 nak */ BAD,
44 /* 026 syn */ BAD,
45 /* 027 etb */ BAD,
46 /* 030 can */ BAD,
47 /* 031 em */ BAD,
48 /* 032 sub */ BAD,
49 /* 033 esc */ BAD,
50 /* 034 fs */ BAD,
51 /* 035 gs */ BAD,
52 /* 036 rs */ BAD,
53 /* 037 us */ BAD,
54 /* 040 sp */ BLANK,
55 /* 041 ! */ 0,
56 /* 042 " */ 0,
57 /* 043 # */ 0,
58 /* 044 $ */ BAD,
59 /* 045 % */ 0,
60 /* 046 & */ 0,
61 /* 047 ' */ 0,
62 /* 050 ( */ 0,
63 /* 051 ) */ 0,
64 /* 052 * */ 0,
65 /* 053 + */ 0,
66 /* 054 , */ 0,
67 /* 055 - */ 0,
68 /* 056 . */ 0,
69 /* 057 / */ 0,
70 /* 060 0 */ DIGIT,
71 /* 061 1 */ DIGIT,
72 /* 062 2 */ DIGIT,
73 /* 063 3 */ DIGIT,
74 /* 064 4 */ DIGIT,
75 /* 065 5 */ DIGIT,
76 /* 066 6 */ DIGIT,
77 /* 067 7 */ DIGIT,
78 /* 070 8 */ DIGIT,
79 /* 071 9 */ DIGIT,
80 /* 072 : */ 0,
81 /* 073 ; */ 0,
82 /* 074 < */ 0,
83 /* 075 = */ 0,
84 /* 076 > */ 0,
85 /* 077 ? */ 0,
86 /* 100 @ */ BAD,
87 /* 101 A */ LETTER|HEX,
88 /* 102 B */ LETTER|HEX,
89 /* 103 C */ LETTER|HEX,
90 /* 104 D */ LETTER|HEX,
91 /* 105 E */ LETTER|HEX,
92 /* 106 F */ LETTER|HEX,
93 /* 107 G */ LETTER,
94 /* 110 H */ LETTER,
95 /* 111 I */ LETTER,
96 /* 112 J */ LETTER,
97 /* 113 K */ LETTER,
98 /* 114 L */ LETTER,
99 /* 115 M */ LETTER,
100 /* 116 N */ LETTER,
101 /* 117 O */ LETTER,
102 /* 120 P */ LETTER,
103 /* 121 Q */ LETTER,
104 /* 122 R */ LETTER,
105 /* 123 S */ LETTER,
106 /* 124 T */ LETTER,
107 /* 125 U */ LETTER,
108 /* 126 V */ LETTER,
109 /* 127 W */ LETTER,
110 /* 130 X */ LETTER,
111 /* 131 Y */ LETTER,
112 /* 132 Z */ LETTER,
113 /* 133 [ */ 0,
114 /* 134 \ */ 0,
115 /* 135 ] */ 0,
116 /* 136 ^ */ 0,
117 /* 137 _ */ LETTER,
118 /* 140 ` */ BAD,
119 /* 141 a */ LETTER|HEX,
120 /* 142 b */ LETTER|HEX,
121 /* 143 c */ LETTER|HEX,
122 /* 144 d */ LETTER|HEX,
123 /* 145 e */ LETTER|HEX,
124 /* 146 f */ LETTER|HEX,
125 /* 147 g */ LETTER,
126 /* 150 h */ LETTER,
127 /* 151 i */ LETTER,
128 /* 152 j */ LETTER,
129 /* 153 k */ LETTER,
130 /* 154 l */ LETTER,
131 /* 155 m */ LETTER,
132 /* 156 n */ LETTER,
133 /* 157 o */ LETTER,
134 /* 160 p */ LETTER,
135 /* 161 q */ LETTER,
136 /* 162 r */ LETTER,
137 /* 163 s */ LETTER,
138 /* 164 t */ LETTER,
139 /* 165 u */ LETTER,
140 /* 166 v */ LETTER,
141 /* 167 w */ LETTER,
142 /* 170 x */ LETTER,
143 /* 171 y */ LETTER,
144 /* 172 z */ LETTER,
145 /* 173 { */ 0,
146 /* 174 | */ 0,
147 /* 175 } */ 0,
148 /* 176 ~ */ 0,
149 /* 177 del */ BAD,
150 /* 200 */ BAD,
151 /* 201 */ BAD,
152 /* 202 */ BAD,
153 /* 203 */ BAD,
154 /* 204 */ BAD,
155 /* 205 */ BAD,
156 /* 206 */ BAD,
157 /* 207 */ BAD,
158 /* 210 */ BAD,
159 /* 211 */ BAD,
160 /* 212 */ BAD,
161 /* 213 */ BAD,
162 /* 214 */ BAD,
163 /* 215 */ BAD,
164 /* 216 */ BAD,
165 /* 217 */ BAD,
166 /* 220 */ BAD,
167 /* 221 */ BAD,
168 /* 222 */ BAD,
169 /* 223 */ BAD,
170 /* 224 */ BAD,
171 /* 225 */ BAD,
172 /* 226 */ BAD,
173 /* 227 */ BAD,
174 /* 230 */ BAD,
175 /* 231 */ BAD,
176 /* 232 */ BAD,
177 /* 233 */ BAD,
178 /* 234 */ BAD,
179 /* 235 */ BAD,
180 /* 236 */ BAD,
181 /* 237 */ BAD,
182 /* 240 */ BAD,
183 /* 241 */ BAD,
184 /* 242 */ BAD,
185 /* 243 */ BAD,
186 /* 244 */ BAD,
187 /* 245 */ BAD,
188 /* 246 */ BAD,
189 /* 247 */ BAD,
190 /* 250 */ BAD,
191 /* 251 */ BAD,
192 /* 252 */ BAD,
193 /* 253 */ BAD,
194 /* 254 */ BAD,
195 /* 255 */ BAD,
196 /* 256 */ BAD,
197 /* 257 */ BAD,
198 /* 260 */ BAD,
199 /* 261 */ BAD,
200 /* 262 */ BAD,
201 /* 263 */ BAD,
202 /* 264 */ BAD,
203 /* 265 */ BAD,
204 /* 266 */ BAD,
205 /* 267 */ BAD,
206 /* 270 */ BAD,
207 /* 271 */ BAD,
208 /* 272 */ BAD,
209 /* 273 */ BAD,
210 /* 274 */ BAD,
211 /* 275 */ BAD,
212 /* 276 */ BAD,
213 /* 277 */ BAD,
214 /* 300 */ BAD,
215 /* 301 */ BAD,
216 /* 302 */ BAD,
217 /* 303 */ BAD,
218 /* 304 */ BAD,
219 /* 305 */ BAD,
220 /* 306 */ BAD,
221 /* 307 */ BAD,
222 /* 310 */ BAD,
223 /* 311 */ BAD,
224 /* 312 */ BAD,
225 /* 313 */ BAD,
226 /* 314 */ BAD,
227 /* 315 */ BAD,
228 /* 316 */ BAD,
229 /* 317 */ BAD,
230 /* 320 */ BAD,
231 /* 321 */ BAD,
232 /* 322 */ BAD,
233 /* 323 */ BAD,
234 /* 324 */ BAD,
235 /* 325 */ BAD,
236 /* 326 */ BAD,
237 /* 327 */ BAD,
238 /* 330 */ BAD,
239 /* 331 */ BAD,
240 /* 332 */ BAD,
241 /* 333 */ BAD,
242 /* 334 */ BAD,
243 /* 335 */ BAD,
244 /* 336 */ BAD,
245 /* 337 */ BAD,
246 /* 340 */ BAD,
247 /* 341 */ BAD,
248 /* 342 */ BAD,
249 /* 343 */ BAD,
250 /* 344 */ BAD,
251 /* 345 */ BAD,
252 /* 346 */ BAD,
253 /* 347 */ BAD,
254 /* 350 */ BAD,
255 /* 351 */ BAD,
256 /* 352 */ BAD,
257 /* 353 */ BAD,
258 /* 354 */ BAD,
259 /* 355 */ BAD,
260 /* 356 */ BAD,
261 /* 357 */ BAD,
262 /* 360 */ BAD,
263 /* 361 */ BAD,
264 /* 362 */ BAD,
265 /* 363 */ BAD,
266 /* 364 */ BAD,
267 /* 365 */ BAD,
268 /* 366 */ BAD,
269 /* 367 */ BAD,
270 /* 370 */ BAD,
271 /* 371 */ BAD,
272 /* 372 */ BAD,
273 /* 373 */ BAD,
274 /* 374 */ BAD,
275 /* 375 */ BAD,
276 /* 376 */ BAD,
277 /* 377 */ BAD,
278 };
279
280 dclproto(static char *asmargs,(Symbol, Symbol [], int));
281 dclproto(static void assem,(void));
282 dclproto(static int backslash,(int));
283 dclproto(static Symbol fcon,(void));
284 dclproto(static Symbol icon,(unsigned int, int));
285
286 /* asmargs - break out %name in string p, fill in argv, returned edited string */
287 static char *asmargs(p, argv, size) Symbol p, argv[]; {
288 int n = 0;
289 char *s1, *s2, str[MAXLINE];
290
291 if (p->type->size >= MAXLINE) {
292 error("asm string too long\n");
293 return "";
294 }
295 for (s2 = str, s1 = p->u.c.v.p; *s1; )
296 if ((*s2++ = *s1++) == '%' && *s1 && map[*s1]&LETTER) {
297 char *t = s1;
298 while (*t && map[*t]&(LETTER|DIGIT))
299 t++;
300 if ((argv[n] = lookup(stringn(s1, t - s1), identifiers))
301 && argv[n]->sclass != TYPEDEF && argv[n]->sclass != ENUM) {
302 argv[n]->ref += refinc;
303 argv[n]->initialized = 1; /* in case ref overflows */
304 if (++n == size) {
305 error("too many variable references in asm string\n");
306 n = size - 1;
307 } else {
308 *s2++ = n - 1;
309 s1 = t;
310 }
311 }
312 }
313 *s2 = 0;
314 argv[n] = 0;
315 return stringn(str, s2 - str);
316 }
317
318 /* assem - parse asm("assembly code") */
319 static void assem() {
320 if (Aflag >= 2)
321 warning("non-ANSI asm\n");
322 t = gettok();
323 expect('(');
324 if (t == SCON) {
325 char *s;
326 Symbol *argv = (Symbol *)talloc(11*sizeof(Symbol *));
327 s = asmargs(tsym, argv, 11);
328 if (fname) {
329 walk(0, 0, 0);
330 code(Start); /* prevent unreachable code message */
331 code(Asm);
332 codelist->u.acode.code = s;
333 codelist->u.acode.argv = argv;
334 } else
335 asmcode(s, argv);
336 t = gettok();
337 } else
338 error("missing string constant in asm\n");
339 if (t != ')')
340 expect(')');
341 }
342
343 /* backslash - get next character with \'s interpreted in q ... q */
344 static int backslash(q) {
345 int c;
346
347 switch (*cp++) {
348 case 'a': return 7;
349 case 'b': return '\b';
350 case 'f': return '\f';
351 case 'n': return '\n';
352 case 'r': return '\r';
353 case 't': return '\t';
354 case 'v': return '\v';
355 case '\'': case '"': case '\\': case '\?': break;
356 case 'x': {
357 int overflow = 0;
358 if ((map[*cp]&(DIGIT|HEX)) == 0) {
359 if (*cp < ' ' || *cp == 0177)
360 error("ill-formed hexadecimal escape sequence\n");
361 else
362 error("ill-formed hexadecimal escape sequence `\\x%c'\n", *cp);
363 if (*cp != q)
364 cp++;
365 return 0;
366 }
367 for (c = 0; map[*cp]&(DIGIT|HEX); cp++) {
368 if (c&~((unsigned)-1 >> 4))
369 overflow++;
370 if (map[*cp]&DIGIT)
371 c = (c<<4) + *cp - '0';
372 else
373 c = (c<<4) + (*cp&~040) - 'A' + 10;
374 }
375 if (c&~0377 || overflow)
376 warning("overflow in hexadecimal escape sequence\n");
377 return c&0377;
378 }
379 case '0': case '1': case '2': case '3':
380 case '4': case '5': case '6': case '7':
381 c = *(cp-1) - '0';
382 if (*cp >= '0' && *cp <= '7') {
383 c = (c<<3) + *cp++ - '0';
384 if (*cp >= '0' && *cp <= '7')
385 c = (c<<3) + *cp++ - '0';
386 }
387 if (c&~0377)
388 warning("overflow in octal escape sequence\n");
389 return c&0377;
390 default:
391 if (cp[-1] < ' ' || cp[-1] >= 0177)
392 warning("unrecognized character escape sequence\n");
393 else
394 warning("unrecognized character escape sequence `\\%c'\n", cp[-1]);
395 }
396 return cp[-1];
397 }
398
399 #ifdef strtod
400 #define ERANGE 1
401 static int errno;
402 #else
403 #include <errno.h>
404 #endif
405
406 /* fcon - scan for tail of a floating constant, set token, return symbol */
407 static Symbol fcon()
408 {
409 char *s = token;
410 int n = 0;
411
412 //__asm { int 3 };
413
414 while (s < (char *)cp)
415 {
416 n += *s++ - '0';
417 }
418
419 if (*cp == '.')
420 {
421 for (cp++;map[*cp]&DIGIT; cp++)
422 {
423 n += *cp - '0';
424 }
425 }
426
427 if (*cp == 'e' || *cp == 'E')
428 {
429 if (*++cp == '-' || *cp == '+')
430 {
431 cp++;
432 }
433
434 if (map[*cp]&DIGIT)
435 {
436 do
437 {
438 cp++;
439 }
440 while (map[*cp]&DIGIT);
441 }
442 else
443 {
444 error("invalid floating constant\n");
445 }
446 }
447
448 if (n == 0)
449 {
450 tval.u.c.v.d = 0.0;
451 }
452 else
453 {
454 double temp_double;
455 char c = *cp;
456 *cp = 0;
457 errno = 0;
458
459 temp_double=strtod(token, (char **)0);
460 tval.u.c.v.d = temp_double;
461 if (errno == ERANGE)
462 {
463 warning("overflow in floating constant `%s'\n", token);
464 }
465 *cp = c;
466 }
467
468 if (*cp == 'f' || *cp == 'F')
469 {
470 char c = *++cp;
471 *cp = 0;
472
473 //printf("==> Float constant:%g\r\n",tval.u.c.v.d);
474 //__asm { int 3 };
475
476 if (tval.u.c.v.d > FLT_MAX)
477 {
478 warning("overflow in floating constant `%s'\n", token);
479 }
480 tval.type = floattype;
481 tval.u.c.v.f = (float)tval.u.c.v.d;
482 *cp = c;
483 }
484 else
485 if (*cp == 'l' || *cp == 'L')
486 {
487 cp++;
488 tval.type = longdouble;
489 }
490 else
491 {
492 tval.type = doubletype;
493 }
494 return &tval;
495 }
496
497 /* getchr - return next significant character */
498 int getchr() {
499 while (*cp) {
500 while (map[*cp]&BLANK)
501 cp++;
502 if (!(map[*cp]&NEWLINE))
503 return *cp;
504 cp++;
505 nextline();
506 }
507 return EOI;
508 }
509
510 /* gettok - return next token */
511 int gettok() {
512 static char cbuf[BUFSIZE+1];
513
514 while (*cp) {
515 register unsigned char *rcp = cp;
516 while (map[*rcp]&BLANK)
517 rcp++;
518 if (limit - rcp < MAXTOKEN) {
519 cp = rcp;
520 fillbuf();
521 rcp = cp;
522 }
523 src.file = file; /* omit */
524 src.x = (char *)rcp - line;
525 src.y = lineno;
526 switch (*rcp++) {
527 case '\n': case '\v': case '\r': case '\f':
528 cp = rcp;
529 nextline();
530 continue;
531 case '/':
532 if (*rcp == '*') {
533 int c = 0;
534 for (rcp++; *rcp && (*rcp != '/' || c != '*');)
535 if (map[*rcp]&NEWLINE) {
536 if (rcp < limit)
537 c = *rcp;
538 cp = rcp + 1;
539 nextline();
540 rcp = cp;
541 } else
542 c = *rcp++;
543 if (*rcp)
544 rcp++;
545 else
546 error("unclosed comment\n");
547 cp = rcp;
548 continue;
549 }
550 cp = rcp;
551 return '/';
552 case '.':
553 if (rcp[0] == '.' && rcp[1] == '.') {
554 cp = rcp + 2;
555 return ELLIPSIS;
556 }
557 if (!(map[*rcp]&DIGIT)) {
558 cp = rcp;
559 return '.';
560 }
561 cp = rcp - 1;
562 token = (char *)cp;
563 tsym = fcon();
564 return FCON;
565 case '0': case '1': case '2': case '3': case '4':
566 case '5': case '6': case '7': case '8': case '9': {
567 int d, overflow = 0;
568 unsigned int n = 0;
569 token = (char *)rcp - 1;
570 if (*token == '0' && (*rcp == 'x' || *rcp == 'X')) {
571 while (*++rcp) {
572 if (map[*rcp]&DIGIT)
573 d = *rcp - '0';
574 else if (*rcp >= 'a' && *rcp <= 'f')
575 d = *rcp - 'a' + 10;
576 else if (*rcp >= 'A' && *rcp <= 'F')
577 d = *rcp - 'A' + 10;
578 else
579 break;
580 if (n&~((unsigned)-1 >> 4))
581 overflow++;
582 else
583 n = (n<<4) + d;
584 }
585 if ((char *)rcp - token <= 2)
586 error("invalid hexadecimal constant\n");
587 cp = rcp;
588 tsym = icon(n, overflow);
589 return ICON;
590 }
591 else if (*token == '0' && (*rcp == 'b' || *rcp == 'B')) {
592 while (*++rcp) {
593 if (*rcp=='0' || *rcp=='1')
594 d = *rcp - '0';
595 else
596 break;
597 if (n&~((unsigned)-1 >> 1))
598 overflow++;
599 else
600 n = (n<<1) + d;
601 }
602 if ((char *)rcp - token <= 2)
603 error("invalid binary constant\n");
604 cp = rcp;
605 tsym = icon(n, overflow);
606 return ICON;
607 }
608 else if (*token == '0') {
609 int err = 0;
610 for ( ; map[*rcp]&DIGIT; rcp++) {
611 if (*rcp == '8' || *rcp == '9')
612 err = 1;
613 if (n&~((unsigned)-1 >> 3))
614 overflow++;
615 else
616 n = (n<<3) + (unsigned)(*rcp - '0');
617 }
618 if (*rcp != '.' && *rcp != 'e' && *rcp != 'E') {
619 if (err)
620 error("invalid octal constant\n");
621 cp = rcp;
622 tsym = icon(n, overflow);
623 return ICON;
624 }
625 }
626 for (n = *token - '0'; map[*rcp]&DIGIT; ) {
627 d = *rcp++ - '0';
628 if (n > ((unsigned)UINT_MAX - d)/10)
629 overflow++;
630 else
631 n = 10*n + d;
632 }
633 if (*rcp != '.' && *rcp != 'e' && *rcp != 'E') {
634 cp = rcp;
635 tsym = icon(n, overflow);
636 return ICON;
637 }
638 cp = rcp;
639 tsym = fcon();
640 return FCON;
641 }
642 case 'L':
643 if (*rcp == '\'') {
644 int t;
645 cp = rcp;
646 t = gettok();
647 assert(t == ICON);
648 src.x--;
649 tval.type = unsignedchar;
650 tval.u.c.v.uc = tval.u.c.v.i;
651 return t;
652 }
653 if (*rcp != '"')
654 goto id;
655 rcp++;
656 /* fall thru */
657 case '\'': case '"': {
658 char *s = cbuf;
659 int nbad = 0;
660 *s++ = *--rcp;
661 cp = rcp;
662 do {
663 cp++;
664 while (*cp && *cp != cbuf[0]) {
665 int c = *cp++;
666 if (map[c]&NEWLINE) {
667 if (cp <= limit)
668 break;
669 nextline();
670 continue;
671 }
672 if (c == '\\') {
673 if (map[*cp]&NEWLINE) {
674 if (cp < limit)
675 break;
676 cp++;
677 nextline();
678 }
679 if (limit - cp < MAXTOKEN)
680 fillbuf();
681 c = backslash(cbuf[0]);
682 } else if (map[c]&BAD)
683 nbad++;
684 if (s < &cbuf[sizeof cbuf] - 2)
685 *s++ = c;
686 }
687 if (*cp == cbuf[0])
688 cp++;
689 else
690 error("missing %c\n", cbuf[0]);
691 } while (cbuf[0] == '"' && getchr() == '"');
692 *s++ = 0;
693 if (s >= &cbuf[sizeof cbuf])
694 error("%s literal too long\n",
695 cbuf[0] == '"' ? "string" : "character");
696 if (Aflag >= 2 && cbuf[0] == '"' && s - cbuf - 1 > 509)
697 warning("more than 509 characters in a string literal\n");
698 if (Aflag >= 2 && nbad)
699 warning("%s literal contains non-portable characters\n",
700 cbuf[0] == '"' ? "string" : "character");
701 token = cbuf;
702 tsym = &tval;
703 if (cbuf[0] == '"') {
704 tval.type = array(chartype, s - cbuf - 1, STRUCT_ALIGN);
705 tval.u.c.v.p = cbuf + 1;
706 return SCON;
707 } else {
708 if (s - cbuf > 3)
709 warning("excess characters in multibyte character literal ignored\n");
710 else if (s - cbuf <= 2)
711 error("missing '\n");
712 tval.type = inttype;
713 tval.u.c.v.i = cbuf[1];
714 return ICON;
715 }
716 }
717 case '<':
718 if (*rcp == '=') {
719 cp = rcp + 1;
720 return LEQ;
721 }
722 if (*rcp == '<') {
723 cp = rcp + 1;
724 return LSHIFT;
725 }
726 cp = rcp;
727 return '<';
728 case '>':
729 if (*rcp == '=') {
730 cp = rcp + 1;
731 return GEQ;
732 }
733 if (*rcp == '>') {
734 cp = rcp + 1;
735 return RSHIFT;
736 }
737 cp = rcp;
738 return '>';
739 case '=':
740 if (*rcp == '=') {
741 cp = rcp + 1;
742 return EQL;
743 }
744 cp = rcp;
745 return '=';
746 case '!':
747 if (*rcp == '=') {
748 cp = rcp + 1;
749 return NEQ;
750 }
751 cp = rcp;
752 return '!';
753 case '|':
754 if (*rcp == '|') {
755 cp = rcp + 1;
756 return OROR;
757 }
758 cp = rcp;
759 return '|';
760 case '&':
761 if (*rcp == '&') {
762 cp = rcp + 1;
763 return ANDAND;
764 }
765 cp = rcp;
766 return '&';
767 case '+':
768 if (*rcp == '+') {
769 cp = rcp + 1;
770 return INCR;
771 }
772 cp = rcp;
773 return '+';
774 case '-':
775 if (*rcp == '>') {
776 cp = rcp + 1;
777 return DEREF;
778 }
779 if (*rcp == '-') {
780 cp = rcp + 1;
781 return DECR;
782 }
783 cp = rcp;
784 return '-';
785 case ';': case ',': case ':':
786 case '*': case '~': case '%': case '^': case '?':
787 case '[': case ']': case '{': case '}': case '(': case ')':
788 cp = rcp;
789 return *(rcp-1);
790 #include "keywords.h"
791 id:
792 token = (char *)rcp - 1;
793 while (map[*rcp]&(DIGIT|LETTER))
794 rcp++;
795 if (rcp == limit) {
796 char *s = cbuf;
797 while (token < (char *)rcp)
798 *s++ = *token++;
799 while (rcp == limit && *rcp) {
800 cp = rcp + 1;
801 nextline();
802 for (rcp = cp; map[*rcp]&(DIGIT|LETTER); rcp++)
803 if (s < &cbuf[sizeof cbuf])
804 *s++ = *rcp;
805 }
806 token = stringn(cbuf, s - cbuf);
807 if (s == &cbuf[sizeof cbuf])
808 error("identifier is too long\n");
809 } else
810 token = stringn(token, (char *)rcp - token);
811 cp = rcp;
812 tsym = lookup(token, identifiers);
813 return ID;
814 default:
815 cp = rcp;
816 if (map[cp[-1]]&BLANK)
817 continue;
818 if (cp[-1] < ' ' || cp[-1] >= 0177)
819 error("illegal character `\\0%o'\n", cp[-1]);
820 else
821 error("illegal character `%c'\n", cp[-1]);
822 }
823 }
824 return EOI;
825 }
826 /* icon - scan for tail of an integer constant n, set token, return symbol */
827 static Symbol icon(n, overflow) unsigned n; {
828 int u = 0;
829
830 if (*cp == 'u' || *cp == 'U')
831 u = *cp++;
832 if (*cp == 'l' || *cp == 'L')
833 *cp++;
834 if (u == 0 && *cp == 'u' || *cp == 'U')
835 u = *cp++;
836 if (overflow) {
837 char c = *cp;
838 *cp = 0;
839 warning("overflow in constant `%s'\n", token);
840 *cp = c;
841 n = INT_MAX;
842 }
843 if (u || n > (unsigned)INT_MAX) {
844 tval.type = unsignedtype;
845 tval.u.c.v.u = n;
846 } else {
847 tval.type = inttype;
848 tval.u.c.v.i = n;
849 }
850 return &tval;
851 }

  ViewVC Help
Powered by ViewVC 1.1.26