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

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

View File

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

View File

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