commit 0806fd87e7bb0f60a0acc1600b84d1a74351f5d1
parent ea6318d7167e507432111818013945f99074978b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sat, 25 Aug 2012 14:05:13 +0200
Added tree struct for for statement
Diffstat:
3 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/flow.c b/flow.c
@@ -41,19 +41,18 @@ do_do(void)
static struct node *
do_for(void)
{
+ register struct node *exp1, *exp2, *exp3;
+
expect(FOR);
expect('(');
- if (yytoken != ';')
- expr();
+ exp1 = (yytoken != ';') ? expr() : NULL;
expect(';');
- if (yytoken != ';')
- expr();
+ exp2 = (yytoken != ';') ? expr() : NULL;
expect(';');
- if (yytoken != ')')
- expr();
+ exp3 = (yytoken != ')') ? expr() : NULL;
expect(')');
- stmt();
- return NULL;
+
+ return node2(OFOR, node3(OFEXP, exp1, exp2, exp3), stmt());
}
static struct node *
diff --git a/syntax.h b/syntax.h
@@ -10,7 +10,8 @@ enum opcode {
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, OSWITCH, OIF
+ OA_XOR, OA_OR, OSYM, OCOMP, OSWITCH, OIF, OFOR,
+ OFEXP
};
struct node;
diff --git a/tree.c b/tree.c
@@ -179,6 +179,8 @@ prtree_helper(register struct node *np)
[OCOMP] = {255, "comp"},
[OSWITCH] = {2, "switch"},
[OIF] = {3, "if"},
+ [OFOR] = {2, "for"},
+ [OFEXP] = {3, "efor"}
};
if (!np) {
fputs(" nil", stdout);