shithub: scc

Download patch

ref: eea2c0f08a760a15a6b117b317c2dcb0f97555c5
parent: b1bd61b5a79e46e298759723f528a4e025a5c6f5
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Apr 23 17:07:41 EDT 2014

Add stmtexp()

This function implements the rule: 'stmt-exp: expr ;' which
is going to be used a lot in stmt.c

--- a/decl.c
+++ b/decl.c
@@ -447,6 +447,7 @@
 			emitdcl(sym);
 		} while (accept(','));
 	}
+	expect(';');
 }
 
 Type *
--- a/stmt.c
+++ b/stmt.c
@@ -8,6 +8,14 @@
 
 extern Node *convert(Node *np, Type *tp1, char iscast);
 
+static Node *
+stmtexp(void)
+{
+	Node *np = expr();
+	expect(';');
+	return np;
+}
+
 static void
 Return(void)
 {
@@ -15,7 +23,7 @@
 	Type *tp = curfun->type->type;
 
 	expect(RETURN);
-	np = expr();
+	np = stmtexp();
 	if (np->type != tp) {
 		if (tp == voidtype)
 			warn(1, "function returning void returns a value");
@@ -39,8 +47,7 @@
 			Return();
 			break;
 		default:
-			emitexp(expr());
+			emitexp(stmtexp());
 		}
-		expect(';');
 	}
 }
--