by scythe · 4y ago · 0 comments
The ++ increment operator is even worse, because it leads to statements within statements. Even an experienced C programmer might have trouble understanding what happens when I write `y = x + x++;`. Lua's grammar achieves a simple parse with no statement delimiters because it enforces a distinction between expressions and statements.
switch (x++) {
case ‘+’:
if (x == ‘+’) {
op = OP_INC;
x++;
} else if (x == ‘=‘) {
op = OP_ADDEQ;
x++;
} else {
op = OP_ADD;
}
break;
…
} t.x = t.x + v
Then it is a question to t’s metatable designer either way.