diff options
| author | Mattias Andrée <m@maandree.se> | 2026-02-26 17:24:42 +0100 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-02-26 17:24:52 +0100 |
| commit | 4816f5f44c4806afa8814d6b1781f50359608622 (patch) | |
| tree | 2545775b0930cc8555e120035c5c1c3793e10f72 | |
| parent | cleanup (diff) | |
| download | libparser-4816f5f44c4806afa8814d6b1781f50359608622.tar.gz libparser-4816f5f44c4806afa8814d6b1781f50359608622.tar.bz2 libparser-4816f5f44c4806afa8814d6b1781f50359608622.tar.xz | |
Right-associate operators
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to '')
| -rw-r--r-- | libparser-generate.c | 12 |
1 files changed, 5 insertions, 7 deletions
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; |
