1 Commits

Author SHA1 Message Date
Gašper Dobrovoljc
30fbde8c31 Added multiline comments 2025-06-03 17:45:56 +02:00
5 changed files with 39 additions and 13 deletions

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@ out/
*.zip
prg/**/*.ast
prg/**/*.out
prg/**/*.pins25

View File

@@ -39,9 +39,8 @@ restcmp -> EQU addexpr
| .
addexpr -> multexpr restadd .
restadd -> ADD addexpr
| SUB addexpr
| .
restadd -> ADD multexpr restadd
| SUB multexpr restadd | .
multexpr -> prefixexpr restmult .
restmult -> MUL prefixexpr restmult

View File

@@ -1,3 +0,0 @@
fun main() =
3 - 2 - 1

View File

@@ -247,9 +247,38 @@ public class LexAn implements AutoCloseable {
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) {
nextChar();
}
}
nextToken();
return;

View File

@@ -540,20 +540,20 @@ public class SynAn implements AutoCloseable {
Token token = lexAn.peekToken();
switch (token.symbol()) {
case ADD: {
// restadd -> ADD addexpr
// restadd -> ADD multexpr restadd
check(Token.Symbol.ADD);
AST.Expr right = parseAdditionExpression();
AST.Expr right = parseMultiplicationExpression();
AST.Expr binExpr = new AST.BinExpr(AST.BinExpr.Oper.ADD, left, right);
attrLoc.put(binExpr, new Report.Location(attrLoc.get(left), attrLoc.get(right)));
return binExpr;
return parseRestAdditionExpressions(binExpr);
}
case SUB: {
// restadd -> ADD addexpr
// restadd -> SUB multexpr restadd
check(Token.Symbol.SUB);
AST.Expr right = parseAdditionExpression();
AST.Expr right = parseMultiplicationExpression();
AST.Expr binExpr = new AST.BinExpr(AST.BinExpr.Oper.SUB, left, right);
attrLoc.put(binExpr, new Report.Location(attrLoc.get(left), attrLoc.get(right)));
return binExpr;
return parseRestAdditionExpressions(binExpr);
}
default: