Added for.

This commit is contained in:
Marvin Blum
2015-09-21 17:28:16 +02:00
parent 1f0730b984
commit e3b8ddc0f9
6 changed files with 44 additions and 8 deletions

View File

@@ -25,6 +25,8 @@ func parseBlock() {
parseWhile()
} else if accept("switch") {
parseSwitch()
} else if accept("for") {
parseFor()
} else if accept("func") {
parseFunction()
} else {
@@ -121,6 +123,30 @@ func parseSwitchBlock() {
parseSwitchBlock()
}
func parseFor() {
expect("for")
appendOut("for [{")
// var in first assignment is optional
if accept("var") {
next()
}
parseExpression()
expect(";")
appendOut("}, {")
parseExpression()
expect(";")
appendOut("}, {")
parseExpression()
expect(";")
appendOut("}] do {\n")
expect("{")
parseBlock()
expect("}")
appendOut("};\n")
}
func parseFunction() {
expect("func")
appendOut(get().token+" = {\n")

View File

@@ -27,6 +27,7 @@ var keywords = []string{"var",
"if",
"while",
"switch",
"for",
"func",
"true",
"false",