Added until statement
This commit is contained in:
parent
1b45d6a0f9
commit
018a80b0f7
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,4 +3,3 @@ out/
|
||||
*.zip
|
||||
prg/**/*.ast
|
||||
prg/**/*.out
|
||||
prg/**/*.pins25
|
10
prg/test.pins25
Normal file
10
prg/test.pins25
Normal file
@ -0,0 +1,10 @@
|
||||
var i = 0
|
||||
|
||||
fun main() =
|
||||
until i >= 10 do
|
||||
putint(i),
|
||||
i = i + 1
|
||||
end,
|
||||
0
|
||||
|
||||
fun putint(n)
|
@ -57,6 +57,10 @@ public record Token(Report.Location location, Symbol symbol, String lexeme) impl
|
||||
* Kljucna beseda {@code while}.
|
||||
*/
|
||||
WHILE,
|
||||
/**
|
||||
* Kljucna beseda {@code until}.
|
||||
*/
|
||||
UNTIL,
|
||||
/**
|
||||
* Kljucna beseda {@code do}.
|
||||
*/
|
||||
|
@ -315,6 +315,7 @@ public class LexAn implements AutoCloseable {
|
||||
case "then" -> Token.Symbol.THEN;
|
||||
case "else" -> Token.Symbol.ELSE;
|
||||
case "while" -> Token.Symbol.WHILE;
|
||||
case "until" -> Token.Symbol.UNTIL;
|
||||
case "do" -> Token.Symbol.DO;
|
||||
case "let" -> Token.Symbol.LET;
|
||||
case "in" -> Token.Symbol.IN;
|
||||
|
@ -227,6 +227,21 @@ public class SynAn implements AutoCloseable {
|
||||
return whileStmt;
|
||||
}
|
||||
|
||||
case UNTIL: {
|
||||
// statement -> until expression do statements end
|
||||
Token untilT = check(Token.Symbol.UNTIL);
|
||||
AST.Expr cond = parseExpression();
|
||||
check(Token.Symbol.DO);
|
||||
List<AST.Stmt> stmts = parseStatements();
|
||||
Token end = check(Token.Symbol.END);
|
||||
|
||||
AST.Expr negCond = new AST.UnExpr(AST.UnExpr.Oper.NOT, cond);
|
||||
|
||||
AST.WhileStmt whileStmt = new AST.WhileStmt(negCond, stmts);
|
||||
attrLoc.put(whileStmt, new Report.Location(untilT, end));
|
||||
return whileStmt;
|
||||
}
|
||||
|
||||
case LET: {
|
||||
// statement -> let definition reststmtdefs in statements end
|
||||
Token let = check(Token.Symbol.LET);
|
||||
|
Loading…
x
Reference in New Issue
Block a user