shithub: scc

Download patch

ref: ffc846e846ca027ab5ac3a710b2a4269680c5bcb
parent: 5c04cc190d4bd20243bd2da081a6c2e17ed8e6a9
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Jul 3 13:56:34 EDT 2013

Add parsing of initializers

A variable can be initialized with some data in the definition, and
this modification accept this initialzator, but it does nothing with
it.

--- a/decl.c
+++ b/decl.c
@@ -130,6 +130,26 @@
 		pushtype(*bp);
 }
 
+static struct node *
+initializer(register struct ctype *tp)
+{
+	register struct node *np;
+
+	if (accept('{')) {
+		np = nodecomp();
+		addstmt(np, initializer(tp));
+		while (accept(',')) {
+			if (accept('}'))
+				return np;
+			addstmt(np, initializer(tp));
+		}
+		expect('}');
+	} else {
+		np = expr();
+	}
+	return np;
+}
+
 static void
 listdcl(register struct ctype *tp)
 {
@@ -144,6 +164,8 @@
 			function(cursym);
 			return;
 		}
+		if (accept('='))
+			initializer(tp);
 	} while (accept(','));
 	expect(';');
 }
--