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);
|
||||
|
||||
var _x = 3;
|
||||
|
||||
switch _x {
|
||||
case 1:
|
||||
case 2:
|
||||
somefunc(2);
|
||||
default:
|
||||
somefunc(3);
|
||||
_x = -1;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
var _x = 3;
|
||||
|
||||
switch _x {
|
||||
case 1:
|
||||
case 2:
|
||||
somefunc(2);
|
||||
default:
|
||||
somefunc(3);
|
||||
for var _x = 5; _x < 5; _x = _x+1; {
|
||||
printSomething("nice");
|
||||
printSomething("nice");
|
||||
printSomething("nice");
|
||||
printSomething("nice");
|
||||
printSomething("nice");
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -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