commit ba47ba8ffc19b3f386bbc01989dda5e0dd1d644d
parent d1e3fef8d6f06929405d377a1cb39eca367da123
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 21 Aug 2012 22:34:46 +0200
Added switch parsing
Diffstat:
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/flow.c b/flow.c
@@ -73,12 +73,13 @@ do_if(void)
static struct node *
do_switch(void)
{
+ register struct node *e1;
+
expect(SWITCH);
expect('(');
- expr();
+ e1 = expr();
expect(')');
- stmt();
- return NULL;
+ return node2(OSWITCH, e1, stmt());
}
static struct node *
diff --git a/syntax.h b/syntax.h
@@ -3,14 +3,14 @@
extern unsigned char curctx;
-enum {
+enum opcode {
OARY, OCALL, OFIELD, OPTR, OPOSTINC, OPOSTDEC,
OPREINC, OPREDEC, OADDR, OINDIR, OMINUS, OPLUS,
OCPL, ONEG, OMUL, ODIV, OMOD, OADD, OSUB, OSHL,
OSHR, OLT, OGT, OGE, OLE, OEQ, ONE, OBAND, OBXOR,
OBOR, OAND, OOR, OTERN, OASSIGN, OA_MUL, OA_DIV,
OA_MOD, OA_ADD, OA_SUB, OA_SHL, OA_SHR, OA_AND,
- OA_XOR, OA_OR, OSYM, OCOMP
+ OA_XOR, OA_OR, OSYM, OCOMP, OSWITCH
};
struct node;
diff --git a/tree.c b/tree.c
@@ -172,7 +172,8 @@ prtree(register struct node *np)
[OA_XOR] = {2, "^="},
[OA_OR] = {2, "|="},
[OSYM] = {0, "sym"},
- [OCOMP] = {255, "comp"}
+ [OCOMP] = {255, "comp"},
+ [OSWITCH] = {2, "switch"}
};
assert(np && np->op < ARRAY_SIZE(optab));