shithub: scc

Download patch

ref: 0806fd87e7bb0f60a0acc1600b84d1a74351f5d1
parent: ea6318d7167e507432111818013945f99074978b
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Aug 25 10:05:13 EDT 2012

Added tree struct for for statement

--- a/flow.c
+++ b/flow.c
@@ -41,19 +41,18 @@
 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 *
--- a/syntax.h
+++ b/syntax.h
@@ -10,7 +10,8 @@
 	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;
--- a/tree.c
+++ b/tree.c
@@ -179,6 +179,8 @@
 		[OCOMP] = {255, "comp"},
 		[OSWITCH] = {2, "switch"},
 		[OIF] = {3, "if"},
+		[OFOR] = {2, "for"},
+		[OFEXP] = {3, "efor"}
 	};
 	if (!np) {
 		fputs(" nil", stdout);
--