scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit f29ca15fca80ed1d1f4865e9e7e258cfd3992948
parent ee09d8609cd1439aa67d36c037df65fa92b132ba
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 11 Jul 2014 17:05:16 +0200

Add ELLIPSIS token

This token will be used in the definition of functions with a
unknown number  of parameters.

Diffstat:
Mcc1/lex.c | 28++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/cc1/lex.c b/cc1/lex.c @@ -347,6 +347,23 @@ logic(uint8_t op, uint8_t equal, uint8_t logic) } static uint8_t +dot(void) +{ + int c; + + if ((c = getc(yyin)) != '.') { + ungetc(c, yyin); + return '.'; + } else if ((c = getc(yyin)) != '.') { + error("incorrect token '%s'", yytext); + } else { + yytext[2] = yytext[1] = '.'; + yytext[3] = '\0'; + return ELLIPSIS; + } +} + +static uint8_t operator(void) { register uint8_t c = getc(yyin); @@ -365,6 +382,7 @@ operator(void) case '!': return follow('=', NE, '!'); case '-': return minus(); case '+': return plus(); + case '.': return dot(); default: return c; } } @@ -389,11 +407,7 @@ next(void) ungetc(c = skipspaces(), yyin); - if (c == EOF) { - strcpy(yytext, "EOF"); - yytoken = EOFTOK; - goto ret; - } else if (isalpha(c) || c == '_') { + if (isalpha(c) || c == '_') { yytoken = iden(); } else if (isdigit(c)) { yytoken = number(); @@ -401,10 +415,12 @@ next(void) yytoken = string(); } else if (c == '\'') { yytoken = character(); + } else if (c == EOF) { + strcpy(yytext, "EOF"); + yytoken = EOFTOK; } else { yytoken = operator(); } -ret: return yytoken; }