ref: f29ca15fca80ed1d1f4865e9e7e258cfd3992948
parent: ee09d8609cd1439aa67d36c037df65fa92b132ba
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Jul 11 13:05:16 EDT 2014
Add ELLIPSIS token This token will be used in the definition of functions with a unknown number of parameters.
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -347,6 +347,23 @@
}
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 @@
case '!': return follow('=', NE, '!');
case '-': return minus();
case '+': return plus();
+ case '.': return dot();
default: return c;
}
}
@@ -389,11 +407,7 @@
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 @@
yytoken = string();
} else if (c == '\'') {
yytoken = character();
+ } else if (c == EOF) {
+ strcpy(yytext, "EOF");
+ yytoken = EOFTOK;
} else {
yytoken = operator();
}
-ret:
return yytoken;
}