mirror of
https://github.com/Kugelschieber/asl.git
synced 2026-01-18 12:00:25 +00:00
Added for.
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -27,6 +27,7 @@ var keywords = []string{"var",
|
||||
"if",
|
||||
"while",
|
||||
"switch",
|
||||
"for",
|
||||
"func",
|
||||
"true",
|
||||
"false",
|
||||
|
||||
Reference in New Issue
Block a user