From 49f5e15e1772d91e8a9589eaa7704d62121e7b62 Mon Sep 17 00:00:00 2001 From: omdxp Date: Sun, 8 Sep 2024 23:37:25 +0100 Subject: [PATCH] impl preprocessing tenaries --- preprocessor/preprocessor.c | 8 +++++++- test.c | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/preprocessor/preprocessor.c b/preprocessor/preprocessor.c index e856cc0..c4272ca 100644 --- a/preprocessor/preprocessor.c +++ b/preprocessor/preprocessor.c @@ -1330,7 +1330,13 @@ int preprocessor_evaluate_exp(struct compile_process *compiler, long left_operand = preprocessor_evaluate(compiler, node->exp.left); if (node->exp.right->type == PREPROCESSOR_TENARY_NODE) { -#warning "handle ternary" + if (left_operand) { + return preprocessor_evaluate(compiler, + node->exp.right->tenary_node.true_node); + } else { + return preprocessor_evaluate(compiler, + node->exp.right->tenary_node.false_node); + } } long right_operand = preprocessor_evaluate(compiler, node->exp.right); diff --git a/test.c b/test.c index ce0a656..599fe87 100644 --- a/test.c +++ b/test.c @@ -1,3 +1,3 @@ -#define ABC (1 + 2 * (9 - 3)) +#define ABC 0 ? 2 : 3 int main() { return ABC; }