scc

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

commit 1886809da90d62f4c4929fa78f89f445348fe8a4
parent bce263baaa569ae0a2eaa83e6483e456e172e56d
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 11 Apr 2014 16:16:51 +0200

Add bit logical xor

Diffstat:
cc.h | 3++-
code.c | 3++-
expr.c | 15++++++++++++++-
3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/cc.h b/cc.h @@ -220,7 +220,8 @@ typedef void (*Inst)(Node *); enum { OCAST, OPTR, OADD, OARY, OSIZE, OMUL, OSUB, OINC, ODEC, OPINC, OPDEC, ODIV, OMOD, OSHL, - OSHR, OLT, OGT, OGE, OLE, OEQ, ONE, OBAND + OSHR, OLT, OGT, OGE, OLE, OEQ, ONE, OBAND, + OBXOR }; extern void diff --git a/code.c b/code.c @@ -24,7 +24,8 @@ char *opcodes[] = { [OLE] = "[", [OEQ] = "=", [ONE] = "!", - [OBAND] = "&" + [OBAND] = "&", + [OBXOR] = "^" }; Node * diff --git a/expr.c b/expr.c @@ -390,13 +390,26 @@ bit_and(void) return np; } +static Node * +bit_xor(void) +{ + register Node *np; + + np = bit_and(); + while (yytoken == '^') { + next(); + np = bitlogic(OBXOR, np, bit_and()); + } + return np; +} + Node * expr(void) { register Node *np; do - np = bit_and(); + np = bit_xor(); while (yytoken == ','); return np; }