renaming the length operator to _length and fixing the lexing of that operator, generic names for operators is really a bad idea

This commit is contained in:
Wolfgang Bumiller 2014-10-18 13:47:23 +02:00
parent 15b31e7dc5
commit 2a00b386ba
3 changed files with 13 additions and 33 deletions

24
lexer.c
View file

@ -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) {

View file

@ -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},

View file

@ -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
}