Compare commits
1 Commits
until
...
multiline-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30fbde8c31 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ out/
|
|||||||
*.zip
|
*.zip
|
||||||
prg/**/*.ast
|
prg/**/*.ast
|
||||||
prg/**/*.out
|
prg/**/*.out
|
||||||
|
prg/**/*.pins25
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
var i = 0
|
|
||||||
|
|
||||||
fun main() =
|
|
||||||
until i >= 10 do
|
|
||||||
putint(i),
|
|
||||||
i = i + 1
|
|
||||||
end,
|
|
||||||
0
|
|
||||||
|
|
||||||
fun putint(n)
|
|
||||||
@@ -57,10 +57,6 @@ public record Token(Report.Location location, Symbol symbol, String lexeme) impl
|
|||||||
* Kljucna beseda {@code while}.
|
* Kljucna beseda {@code while}.
|
||||||
*/
|
*/
|
||||||
WHILE,
|
WHILE,
|
||||||
/**
|
|
||||||
* Kljucna beseda {@code until}.
|
|
||||||
*/
|
|
||||||
UNTIL,
|
|
||||||
/**
|
/**
|
||||||
* Kljucna beseda {@code do}.
|
* Kljucna beseda {@code do}.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -247,9 +247,38 @@ public class LexAn implements AutoCloseable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nextChar();
|
||||||
|
if (buffChar == '{') {
|
||||||
|
int depth = 1;
|
||||||
|
|
||||||
|
nextChar();
|
||||||
|
while (depth > 0) {
|
||||||
|
switch (buffChar) {
|
||||||
|
case '}':
|
||||||
|
nextChar();
|
||||||
|
if (buffChar != '/') continue;
|
||||||
|
nextChar();
|
||||||
|
if (buffChar != '/') continue;
|
||||||
|
depth--;
|
||||||
|
break;
|
||||||
|
case '/':
|
||||||
|
nextChar();
|
||||||
|
if (buffChar != '/') continue;
|
||||||
|
nextChar();
|
||||||
|
if (buffChar != '{') continue;
|
||||||
|
depth++;
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
throw new Report.Error(currentLocation(), "Unterminated multiline comment");
|
||||||
|
default:
|
||||||
|
nextChar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
while (buffChar != '\n' && buffChar != -1) {
|
while (buffChar != '\n' && buffChar != -1) {
|
||||||
nextChar();
|
nextChar();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nextToken();
|
nextToken();
|
||||||
return;
|
return;
|
||||||
@@ -315,7 +344,6 @@ public class LexAn implements AutoCloseable {
|
|||||||
case "then" -> Token.Symbol.THEN;
|
case "then" -> Token.Symbol.THEN;
|
||||||
case "else" -> Token.Symbol.ELSE;
|
case "else" -> Token.Symbol.ELSE;
|
||||||
case "while" -> Token.Symbol.WHILE;
|
case "while" -> Token.Symbol.WHILE;
|
||||||
case "until" -> Token.Symbol.UNTIL;
|
|
||||||
case "do" -> Token.Symbol.DO;
|
case "do" -> Token.Symbol.DO;
|
||||||
case "let" -> Token.Symbol.LET;
|
case "let" -> Token.Symbol.LET;
|
||||||
case "in" -> Token.Symbol.IN;
|
case "in" -> Token.Symbol.IN;
|
||||||
|
|||||||
@@ -227,21 +227,6 @@ public class SynAn implements AutoCloseable {
|
|||||||
return whileStmt;
|
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: {
|
case LET: {
|
||||||
// statement -> let definition reststmtdefs in statements end
|
// statement -> let definition reststmtdefs in statements end
|
||||||
Token let = check(Token.Symbol.LET);
|
Token let = check(Token.Symbol.LET);
|
||||||
|
|||||||
Reference in New Issue
Block a user