[hackers] [scc] [cc2] Fix parsing of ternary operators || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 7 Jun 2016 08:42:56 +0200 (CEST)

commit 87dab1114c64c72d7a40b5f9c048c4e1a7541607
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Jun 7 08:41:37 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Jun 7 08:41:37 2016 +0200

    [cc2] Fix parsing of ternary operators
    
    The parser was correct, but the generated tree was not
    correct, because the names of ask and colon were interchanged
    and we were not joint the ? with the :

diff --git a/cc2/parser.c b/cc2/parser.c
index f76f09c..9d7ff0d 100644
--- a/cc2/parser.c
+++ b/cc2/parser.c
_AT_@ -272,7 +272,7 @@ assign(char *token, union tokenop u)
 static void
 ternary(char *token, union tokenop u)
 {
- Node *ask = newnode(OCOLON), *colon = newnode(OASK);
+ Node *ask = newnode(OASK), *colon = newnode(OCOLON);
         Type *tp = gettype(token+1);
 
         colon->right = pop();
_AT_@ -280,6 +280,7 @@ ternary(char *token, union tokenop u)
 
         ask->type = *tp;
         ask->left = pop();
+ ask->right = colon;
         push(ask);
 }
 
Received on Tue Jun 07 2016 - 08:42:56 CEST

This archive was generated by hypermail 2.3.0 : Tue Jun 07 2016 - 08:48:16 CEST