From: Wolfgang Bumiller Date: Sat, 18 Oct 2014 11:47:23 +0000 (+0200) Subject: renaming the length operator to _length and fixing the lexing of that operator, gener... X-Git-Tag: xonotic-v0.8.1~9^2~10 X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=commitdiff_plain;h=2a00b386ba9995ea445c8a19dacb30936fa8942a renaming the length operator to _length and fixing the lexing of that operator, generic names for operators is really a bad idea --- diff --git a/lexer.c b/lexer.c index 7137325..9ed9c39 100644 --- a/lexer.c +++ b/lexer.c @@ -1308,28 +1308,6 @@ int lex_do(lex_file *lex) return (lex->tok.ttype = TOKEN_OPERATOR); } - /* length operator */ - if (ch == 'l') { - if ((nextch = lex_getch(lex)) == 'e') { - if ((nextch = lex_getch(lex)) == 'n') { - if ((nextch = lex_getch(lex)) == 'g') { - if ((nextch = lex_getch(lex)) == 't') { - if ((nextch = lex_getch(lex)) == 'h') { - lex_tokench(lex, 'l'); - lex_tokench(lex, 'e'); - lex_tokench(lex, 'n'); - lex_tokench(lex, 'g'); - lex_tokench(lex, 't'); - lex_tokench(lex, 'h'); - lex_endtoken(lex); - return (lex->tok.ttype = TOKEN_OPERATOR); - } else lex_ungetch(lex, nextch); - } else lex_ungetch(lex, nextch); - } else lex_ungetch(lex, nextch); - } else lex_ungetch(lex, nextch); - } else lex_ungetch(lex, nextch); - } - if (isident_start(ch)) { const char *v; @@ -1361,6 +1339,8 @@ int lex_do(lex_file *lex) } else if (!strcmp(v, "vector")) { lex->tok.ttype = TOKEN_TYPENAME; lex->tok.constval.t = TYPE_VECTOR; + } else if (!strcmp(v, "_length")) { + lex->tok.ttype = TOKEN_OPERATOR; } else { size_t kw; for (kw = 0; kw < GMQCC_ARRAY_COUNT(keywords_qc); ++kw) { diff --git a/lexer.h b/lexer.h index c073c8e..9187dee 100644 --- a/lexer.h +++ b/lexer.h @@ -176,8 +176,8 @@ typedef struct { #define opid3(a,b,c) (((uint8_t)a<<16)|((uint8_t)b<<8)|(uint8_t)c) static const oper_info c_operators[] = { - { "(", 0, opid1('('), ASSOC_LEFT, 99, OP_PREFIX, false}, /* paren expression - non function call */ - { "length", 1, opid3('l','e','n'), ASSOC_RIGHT, 98, OP_PREFIX, true}, + { "(", 0, opid1('('), ASSOC_LEFT, 99, OP_PREFIX, false}, /* paren expression - non function call */ + { "_length", 1, opid3('l','e','n'), ASSOC_RIGHT, 98, OP_PREFIX, true}, { "++", 1, opid3('S','+','+'), ASSOC_LEFT, 17, OP_SUFFIX, false}, { "--", 1, opid3('S','-','-'), ASSOC_LEFT, 17, OP_SUFFIX, false}, diff --git a/tests/length.qc b/tests/length.qc index 5abe769..ba5f01d 100644 --- a/tests/length.qc +++ b/tests/length.qc @@ -4,20 +4,20 @@ float c[5] = { 5, 4, 3, 2, 1 }; // 5 const float d[] = { 1 }; // 1 void main() { - print(ftos(length a), "\n"); // 11 - print(ftos(length b), "\n"); // 3 - print(ftos(length c), "\n"); // 5 - print(ftos(length d), "\n"); // 1 + print(ftos(_length a), "\n"); // 11 + print(ftos(_length b), "\n"); // 3 + print(ftos(_length c), "\n"); // 5 + print(ftos(_length d), "\n"); // 1 - static float al = length(a); - static float bl = length(b); - static float cl = length(c); - static float dl = length(d); + static float al = _length(a); + static float bl = _length(b); + static float cl = _length(c); + static float dl = _length(d); print(ftos(al), "\n"); // 11 print(ftos(bl), "\n"); // 3 print(ftos(cl), "\n"); // 5 print(ftos(dl), "\n"); // 1 - print(ftos(length "hello world"), "\n"); // 11 + print(ftos(_length "hello world"), "\n"); // 11 }