From 4816f5f44c4806afa8814d6b1781f50359608622 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 26 Feb 2026 17:24:42 +0100 Subject: Right-associate operators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libparser-generate.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'libparser-generate.c') diff --git a/libparser-generate.c b/libparser-generate.c index 47d2ebd..1ec2d6e 100644 --- a/libparser-generate.c +++ b/libparser-generate.c @@ -483,13 +483,11 @@ order_sentences(struct node *node) * higher precedence */ goto push_to_stack; } else if (node->token->s[0] == stack->token->s[0]) { - /* If however our operator is the same as on the top - * of the stack (meaning they have the same precedence), - * we pop the top of the stack onto the queue, and push - * our operator to the stack */ - *head = stack; - head = &stack->next; - stack = stack->next; + /* If our operator is the same as on the top of the + * stack (meaning they have the same precedence), we + * push it to the stack; but we do not pop the stack + * first because we want our operators to be associated + * right to left */ push_to_stack: node->next = stack; stack = node; -- cgit v1.2.3-70-g09d2