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 37 additions and 20 deletions

View File

@@ -70,3 +70,27 @@ initializer -> INTCONST intconstmult | CHARCONST | STRINGCONST .
intconstmult -> MUL const | .
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,4 +1,5 @@
fun putint(n)
// line1 --
line2 -----x
line3
fun main() =
putint(__LINE__)
fun main() = 0

View File

@@ -148,11 +148,7 @@ public record Token(Report.Location location, Symbol symbol, String lexeme) impl
/**
* Simbol {@code )}.
*/
RPAREN,
/**
* Simbol {@code __LINE__}.
*/
LINE
RPAREN;
}
@Override

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();
}
@@ -319,7 +325,6 @@ public class LexAn implements AutoCloseable {
case "let" -> Token.Symbol.LET;
case "in" -> Token.Symbol.IN;
case "end" -> Token.Symbol.END;
case "__LINE__" -> Token.Symbol.LINE;
default -> null;
};
}
@@ -452,15 +457,6 @@ public class LexAn implements AutoCloseable {
symbol = Token.Symbol.IDENTIFIER;
}
if (symbol == Token.Symbol.LINE) {
buffToken = new Token(
new Report.Location(startLocation, endLocation),
Token.Symbol.INTCONST,
Integer.toString(startLocation.begLine())
);
return;
}
buffToken = new Token(
new Report.Location(startLocation, endLocation),
symbol,