scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit fb65fca0b3c45ded10eaac0d5d0b1a83d7ab9c66
parent da0ce9f484c0d744fed1e22af2651734c4830d73
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 15 Apr 2014 17:27:05 +0200

Implement comma operator

This operator was recognized but was not implemented

Diffstat:
cc.h | 1+
code.c | 3++-
expr.c | 13++++++++-----
3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/cc.h b/cc.h @@ -224,6 +224,7 @@ enum { OBAND, OBXOR, OBOR, OASSIGN, OA_MUL, OA_DIV, OA_MOD, OA_ADD, OA_SUB, OA_SHL, OA_SHR, OA_AND, OA_XOR, OA_OR, OADDR,ONEG, OCPL, OEXC, + OCOMMA, /* * Complementary relational operators only differ in less * significant bit diff --git a/code.c b/code.c @@ -43,7 +43,8 @@ char *opcodes[] = { [ONEG] = "_", [OCPL] = "~", [OAND] = "m", - [OOR] = "s" + [OOR] = "s", + [OCOMMA] = "," }; Node * diff --git a/expr.c b/expr.c @@ -707,10 +707,13 @@ error: Node * expr(void) { - register Node *np; + register Node *np1, *np2; - do - np = assign(); - while (yytoken == ','); - return np; + np1 = assign(); + while (accept(',')) { + np2 = assign(); + np1 = bincode(OCOMMA, np2->type, np1, np2); + } + + return np1; }