mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-11-23 20:33:05 +00:00
More ternary fixes
This commit is contained in:
parent
43c0343755
commit
b966cd4f4d
4 changed files with 19 additions and 2 deletions
3
lexer.h
3
lexer.h
|
@ -253,7 +253,6 @@ static const oper_info fte_operators[] = {
|
|||
{ "!=", 2, opid2('!','='), ASSOC_LEFT, 10, 0 },
|
||||
|
||||
{ "?", 3, opid2('?',':'), ASSOC_RIGHT, 9, 0 },
|
||||
{ ":", 3, opid2(':','?'), ASSOC_RIGHT, 9, 0 },
|
||||
|
||||
{ "=", 2, opid1('='), ASSOC_RIGHT, 8, 0 },
|
||||
{ "+=", 2, opid2('+','='), ASSOC_RIGHT, 8, 0 },
|
||||
|
@ -268,6 +267,8 @@ static const oper_info fte_operators[] = {
|
|||
{ "&&", 2, opid2('&','&'), ASSOC_LEFT, 5, 0 },
|
||||
{ "||", 2, opid2('|','|'), ASSOC_LEFT, 5, 0 },
|
||||
|
||||
{ ":", 0, opid2(':','?'), ASSOC_RIGHT, 3, 0 },
|
||||
|
||||
{ ",", 2, opid1(','), ASSOC_LEFT, 2, 0 }
|
||||
};
|
||||
static const size_t fte_operator_count = (sizeof(fte_operators) / sizeof(fte_operators[0]));
|
||||
|
|
6
parser.c
6
parser.c
|
@ -513,6 +513,10 @@ static bool parser_sy_pop(parser_t *parser, shunt *sy)
|
|||
|
||||
vec_shrinkby(sy->ops, 1);
|
||||
|
||||
/* op(:?) has no input and no output */
|
||||
if (!op->operands)
|
||||
return true;
|
||||
|
||||
vec_shrinkby(sy->out, op->operands);
|
||||
for (i = 0; i < op->operands; ++i) {
|
||||
exprs[i] = sy->out[vec_size(sy->out)+i].out;
|
||||
|
@ -1633,9 +1637,9 @@ static ast_expression* parse_expression_leave(parser_t *parser, bool stopatcomma
|
|||
wantop = false;
|
||||
--ternaries;
|
||||
} else if (op->id == opid2(':','?')) {
|
||||
/* we don't push this operator */
|
||||
if (!parser_close_paren(parser, &sy, false))
|
||||
goto onerr;
|
||||
vec_push(sy.ops, syop(parser_ctx(parser), op));
|
||||
wantop = false;
|
||||
++ternaries;
|
||||
} else {
|
||||
|
|
|
@ -12,6 +12,7 @@ void test(float cond, float v1, float v2, float a) {
|
|||
}
|
||||
|
||||
void main() {
|
||||
float a, b;
|
||||
test(0, -99, 1, 1);
|
||||
test(0, -99, 1, 2);
|
||||
test(0, -99, 1, 3);
|
||||
|
@ -24,4 +25,12 @@ void main() {
|
|||
test(1, 0, -99, 1);
|
||||
test(1, 0, -99, 2);
|
||||
test(1, 0, -99, 3);
|
||||
|
||||
b = 5;
|
||||
a = b ? 5 : 6;
|
||||
print(ftos(a), "\n");
|
||||
b ? a = 9 : a = 10;
|
||||
print(ftos(a), "\n");
|
||||
!b ? a = 9 : a = 10;
|
||||
print(ftos(a), "\n");
|
||||
}
|
||||
|
|
|
@ -14,3 +14,6 @@ M: 1 a=other
|
|||
M: 0 not met
|
||||
M: 0 not met
|
||||
M: 0 not met
|
||||
M: 5
|
||||
M: 9
|
||||
M: 10
|
||||
|
|
Loading…
Reference in a new issue