Compare commits
1 Commits
until
...
2025-predr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
352085b499 |
26
grammar.txt
26
grammar.txt
@@ -69,4 +69,28 @@ restinits -> COMMA initializer restinits | .
|
||||
initializer -> INTCONST intconstmult | CHARCONST | STRINGCONST .
|
||||
intconstmult -> MUL const | .
|
||||
|
||||
const -> INTCONST | CHARCONST | STRINGCONST .
|
||||
const -> INTCONST | CHARCONST | STRINGCONST .
|
||||
|
||||
|
||||
--------------------------------------------------------------------
|
||||
|
||||
//LEFT ASOC.
|
||||
exp0 = exp0 op other | other
|
||||
|
||||
|
|
||||
v
|
||||
|
||||
exp0 = other exp0'
|
||||
exp0' = op other exp0' | .
|
||||
|
||||
|
||||
|
||||
|
||||
//RIGHT ASOC.
|
||||
exp0 = other op exp0 | other
|
||||
|
||||
|
|
||||
v
|
||||
|
||||
exp0 = other exp0'
|
||||
exp0' = op exp0 | .
|
||||
@@ -1,10 +1,5 @@
|
||||
var i = 0
|
||||
// line1 --
|
||||
line2 -----x
|
||||
line3
|
||||
|
||||
fun main() =
|
||||
until i >= 10 do
|
||||
putint(i),
|
||||
i = i + 1
|
||||
end,
|
||||
0
|
||||
|
||||
fun putint(n)
|
||||
fun main() = 0
|
||||
@@ -57,10 +57,6 @@ 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}.
|
||||
*/
|
||||
|
||||
@@ -247,7 +247,13 @@ public class LexAn implements AutoCloseable {
|
||||
return;
|
||||
}
|
||||
|
||||
while (buffChar != '\n' && buffChar != -1) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
while (buffChar != -1) {
|
||||
if (buffChar == '\n' && !builder.toString().endsWith("--")) {
|
||||
break;
|
||||
}
|
||||
builder.append((char) buffChar);
|
||||
nextChar();
|
||||
}
|
||||
|
||||
@@ -315,7 +321,6 @@ 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,21 +227,6 @@ 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);
|
||||
|
||||
Reference in New Issue
Block a user