shithub: scc

Download patch

ref: 0214edbad28232ca828f44aa43dd413fe18edaa9
parent: eea2c0f08a760a15a6b117b317c2dcb0f97555c5
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Apr 23 17:46:55 EDT 2014

Allow nedted compound statements

compound is only a type of stmt, so it is better do all
the checks about the kind of statement in stmt() and not
in compound().

--- a/stmt.c
+++ b/stmt.c
@@ -1,6 +1,7 @@
 
 #include <stddef.h>
 #include <stdint.h>
+#include <stdio.h>
 
 #include "cc1.h"
 
@@ -7,6 +8,7 @@
 Symbol *curfun;
 
 extern Node *convert(Node *np, Type *tp1, char iscast);
+static void stmt(Symbol *lbreak, Symbol *lcont, Symbol *lswitch);
 
 static Node *
 stmtexp(void)
@@ -38,16 +40,29 @@
 compound(Symbol *lbreak, Symbol *lcont, Symbol *lswitch)
 {
 	expect('{');
-	while (!accept('}')) {
+	for (;;) {
 		switch (yytoken) {
+		case '}':
+			next();
+			return;
+		case '{':
+			compound(lbreak, lcont, lswitch);
+			break;
 		case TYPE: case SCLASS: case TQUALIFIER:
 			decl();
 			break;
-		case RETURN:
-			Return();
-			break;
 		default:
-			emitexp(stmtexp());
+			stmt(lbreak, lcont, lswitch);
 		}
 	}
 }
+
+static void
+stmt(Symbol *lbreak, Symbol *lcont, Symbol *lswitch)
+{
+	switch (yytoken) {
+	case '{': compound(lbreak, lcont, lswitch); break;
+	case RETURN: Return(); break;
+	default: emitexp(stmtexp()); break;
+	}
+}
\ No newline at end of file