From: Matthias Kruk Date: Sun, 12 Jul 2020 08:23:31 +0000 (+0900) Subject: lex: Parse "..." as separate token X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=1b57fc46c190745095e4e5c24932e8414e91ccd6;p=ccc lex: Parse "..." as separate token --- diff --git a/src/lex.c b/src/lex.c index 9d4738f..2d3a7a7 100644 --- a/src/lex.c +++ b/src/lex.c @@ -31,9 +31,10 @@ #define STATE_SUB 20 #define STATE_MUL 21 #define STATE_DOT 22 -#define STATE_ZERO 23 -#define STATE_NUM 24 -#define STATE_FLT 25 +#define STATE_DOTDOT 23 +#define STATE_ZERO 24 +#define STATE_NUM 25 +#define STATE_FLT 26 #define identifier_firstchr(_c) ((_c) == '_' || \ (_c) >= 'a' && (_c) <= 'z' || \ @@ -558,19 +559,31 @@ struct token *_nexttoken(void) } case STATE_DOT: - _putnextchar(c); - if(c >= '0' && c <= '9') { + _putnextchar(c); + tok = token_new_from_str(TOKEN_FLOAT_LITERAL, _line, _col, "0."); assert(tok); state = STATE_FLT; + } else if(c == '.') { + state = STATE_DOTDOT; } else { + _putnextchar(c); + return(token_new_from_str(TOKEN_MEMBER, _line, _col, ".")); } break; + case STATE_DOTDOT: + if(c == '.') { + return(token_new_from_str(TOKEN_DOTS, _line, _col - 2, "...")); + } + + fprintf(stderr, "Unexpected character `%c' at %d:%d\n", c, _line, _col); + return(NULL); + case STATE_ZERO: if(c == 'x' || c == 'X') { token_append_char(tok, 'x'); diff --git a/src/token.h b/src/token.h index 3b6d02c..ce6fda6 100644 --- a/src/token.h +++ b/src/token.h @@ -40,6 +40,7 @@ typedef enum { TOKEN_LPAREN, TOKEN_LT, TOKEN_MEMBER, + TOKEN_DOTS, TOKEN_MOD, TOKEN_MUL, TOKEN_NEQ,