commit 87dab1114c64c72d7a40b5f9c048c4e1a7541607
Author:     Roberto E. Vargas Caballero <k...@shike2.com>
AuthorDate: Tue Jun 7 08:41:37 2016 +0200
Commit:     Roberto E. Vargas Caballero <k...@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
@@ -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();
@@ -280,6 +280,7 @@ ternary(char *token, union tokenop u)
 
        ask->type = *tp;
        ask->left = pop();
+       ask->right = colon;
        push(ask);
 }
 

Reply via email to