1 Commits

Author SHA1 Message Date
Gašper Dobrovoljc
352085b499 Predrok 2025 - Naloga 1 2025-06-04 14:14:46 +02:00
4 changed files with 44 additions and 13 deletions

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
@@ -70,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 | .

View File

@@ -1,3 +1,5 @@
// line1 --
line2 -----x
line3
fun main() =
3 - 2 - 1
fun main() = 0

View File

@@ -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();
}

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: