scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 87dab1114c64c72d7a40b5f9c048c4e1a7541607
parent 19f5c0a15f0e21510092ded91507a7a6e5feb9cf
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  7 Jun 2016 08:41:37 +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 :

Diffstat:
Mcc2/parser.c | 3++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git 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); }