comparison lwcc/lex.c @ 298:6112c67728ba ccdev

Add stringification and token concatenation Add support for # and ## in macro expansion by the preprocessor (stringification and token concatenation). Totally untested.
author William Astle <lost@l-w.ca>
date Sat, 14 Sep 2013 22:42:53 -0600
parents 83fcc1ed6ad6
children 856caf91ffaa
comparison
equal deleted inserted replaced
297:310df72c641d 298:6112c67728ba
206 retrieved from the unfetch buffer is presumed to have already passed 206 retrieved from the unfetch buffer is presumed to have already passed
207 the backslash-newline filter. */ 207 the backslash-newline filter. */
208 static int fetch_byte(struct preproc_info *pp) 208 static int fetch_byte(struct preproc_info *pp)
209 { 209 {
210 int c; 210 int c;
211
212 if (pp -> lexstr)
213 {
214 if (pp -> lexstr[pp -> lexstrloc])
215 return pp -> lexstr[pp -> lexstrloc++];
216 else
217 return CPP_EOL;
218 }
211 219
212 if (pp -> ungetbufl > 0) 220 if (pp -> ungetbufl > 0)
213 { 221 {
214 pp -> ungetbufl--; 222 pp -> ungetbufl--;
215 c = pp -> ungetbuf[pp -> ungetbufl]; 223 c = pp -> ungetbuf[pp -> ungetbufl];
584 { 592 {
585 strbuf_add(strbuf, '\\'); 593 strbuf_add(strbuf, '\\');
586 c = preproc_lex_fetch_byte(pp); 594 c = preproc_lex_fetch_byte(pp);
587 if (c == CPP_EOF || c == CPP_EOL) 595 if (c == CPP_EOF || c == CPP_EOL)
588 { 596 {
589 preproc_throw_error(pp, "Invalid character constant"); 597 if (!pp -> lexstr)
598 preproc_throw_error(pp, "Invalid character constant");
590 break; 599 break;
591 } 600 }
592 cl++; 601 cl++;
593 strbuf_add(strbuf, c); 602 strbuf_add(strbuf, c);
594 continue; 603 continue;
595 } 604 }
596 strbuf_add(strbuf, c); 605 strbuf_add(strbuf, c);
597 } 606 }
598 if (cl == 0) 607 if (cl == 0 && !pp -> lexstr)
599 preproc_throw_error(pp, "Invalid character constant"); 608 preproc_throw_error(pp, "Invalid character constant");
600 strval = strbuf_end(strbuf); 609 strval = strbuf_end(strbuf);
601 ttype = TOK_CHR_LIT; 610 ttype = TOK_CHR_LIT;
602 goto out; 611 goto out;
603 612
614 { 623 {
615 strbuf_add(strbuf, '\\'); 624 strbuf_add(strbuf, '\\');
616 c = preproc_lex_fetch_byte(pp); 625 c = preproc_lex_fetch_byte(pp);
617 if (c == CPP_EOF || c == CPP_EOL) 626 if (c == CPP_EOF || c == CPP_EOL)
618 { 627 {
619 preproc_throw_error(pp, "Invalid string constant"); 628 if (!pp -> lexstr)
629 preproc_throw_error(pp, "Invalid string constant");
620 break; 630 break;
621 } 631 }
622 cl++; 632 cl++;
623 strbuf_add(strbuf, c); 633 strbuf_add(strbuf, c);
624 continue; 634 continue;