diff graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Parser.java @ 13836:64c77f0577bb

More documentation and improvements of Simple Language
author Christian Wimmer <christian.wimmer@oracle.com>
date Thu, 30 Jan 2014 17:53:27 -0800
parents b16ec83edc73
children 915ebb306fcc
line wrap: on
line diff
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Parser.java	Thu Jan 30 17:52:24 2014 -0800
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/parser/Parser.java	Thu Jan 30 17:53:27 2014 -0800
@@ -145,17 +145,17 @@
 			}
 		}
 		Expect(7);
-		SLStatementNode body = Block();
+		SLStatementNode body = Block(false);
 		factory.finishFunction(body); 
 	}
 
-	SLStatementNode  Block() {
+	SLStatementNode  Block(boolean inLoop) {
 		SLStatementNode  result;
 		factory.startBlock();
 		List<SLStatementNode> body = new ArrayList<>(); 
 		Expect(8);
 		while (StartOf(1)) {
-			SLStatementNode s = Statement();
+			SLStatementNode s = Statement(inLoop);
 			body.add(s); 
 		}
 		Expect(9);
@@ -163,7 +163,7 @@
 		return result;
 	}
 
-	SLStatementNode  Statement() {
+	SLStatementNode  Statement(boolean inLoop) {
 		SLStatementNode  result;
 		result = null; 
 		switch (la.kind) {
@@ -173,18 +173,18 @@
 		}
 		case 10: {
 			Get();
-			result = factory.createBreak(t); 
+			if (inLoop) { result = factory.createBreak(t); } else { SemErr("break used outside of loop"); } 
 			Expect(11);
 			break;
 		}
 		case 12: {
 			Get();
-			result = factory.createContinue(t); 
+			if (inLoop) { result = factory.createContinue(t); } else { SemErr("continue used outside of loop"); } 
 			Expect(11);
 			break;
 		}
 		case 14: {
-			result = IfStatement();
+			result = IfStatement(inLoop);
 			break;
 		}
 		case 16: {
@@ -208,23 +208,23 @@
 		Token whileToken = t; 
 		SLExpressionNode condition = Expression();
 		Expect(7);
-		SLStatementNode body = Block();
+		SLStatementNode body = Block(true);
 		result = factory.createWhile(whileToken, condition, body); 
 		return result;
 	}
 
-	SLStatementNode  IfStatement() {
+	SLStatementNode  IfStatement(boolean inLoop) {
 		SLStatementNode  result;
 		Expect(14);
 		Expect(5);
 		Token ifToken = t; 
 		SLExpressionNode condition = Expression();
 		Expect(7);
-		SLStatementNode thenPart = Block();
+		SLStatementNode thenPart = Block(inLoop);
 		SLStatementNode elsePart = null; 
 		if (la.kind == 15) {
 			Get();
-			elsePart = Block();
+			elsePart = Block(inLoop);
 		}
 		result = factory.createIf(ifToken, condition, thenPart, elsePart); 
 		return result;