mirror of
https://github.com/Kugelschieber/asl.git
synced 2026-01-18 12:00:25 +00:00
Added for.
This commit is contained in:
@@ -22,3 +22,14 @@ if (_a+_b)/2 > 10 {
|
|||||||
|
|
||||||
myFunc(_a, _b);
|
myFunc(_a, _b);
|
||||||
myFunc(_a, _b);
|
myFunc(_a, _b);
|
||||||
|
|
||||||
|
var _x = 3;
|
||||||
|
|
||||||
|
switch _x {
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
somefunc(2);
|
||||||
|
default:
|
||||||
|
somefunc(3);
|
||||||
|
_x = -1;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
var _x = 3;
|
for var _x = 5; _x < 5; _x = _x+1; {
|
||||||
|
printSomething("nice");
|
||||||
switch _x {
|
printSomething("nice");
|
||||||
case 1:
|
printSomething("nice");
|
||||||
case 2:
|
printSomething("nice");
|
||||||
somefunc(2);
|
printSomething("nice");
|
||||||
default:
|
|
||||||
somefunc(3);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -25,6 +25,8 @@ func parseBlock() {
|
|||||||
parseWhile()
|
parseWhile()
|
||||||
} else if accept("switch") {
|
} else if accept("switch") {
|
||||||
parseSwitch()
|
parseSwitch()
|
||||||
|
} else if accept("for") {
|
||||||
|
parseFor()
|
||||||
} else if accept("func") {
|
} else if accept("func") {
|
||||||
parseFunction()
|
parseFunction()
|
||||||
} else {
|
} else {
|
||||||
@@ -121,6 +123,30 @@ func parseSwitchBlock() {
|
|||||||
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() {
|
func parseFunction() {
|
||||||
expect("func")
|
expect("func")
|
||||||
appendOut(get().token+" = {\n")
|
appendOut(get().token+" = {\n")
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ var keywords = []string{"var",
|
|||||||
"if",
|
"if",
|
||||||
"while",
|
"while",
|
||||||
"switch",
|
"switch",
|
||||||
|
"for",
|
||||||
"func",
|
"func",
|
||||||
"true",
|
"true",
|
||||||
"false",
|
"false",
|
||||||
|
|||||||
Reference in New Issue
Block a user