1 Commits

Author SHA1 Message Date
Gašper Dobrovoljc
de2522c28c Added __LINE__ symbol 2025-06-03 18:07:27 +02:00
5 changed files with 22 additions and 10 deletions

1
.gitignore vendored
View File

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

4
prg/test.pins25 Normal file
View File

@@ -0,0 +1,4 @@
fun putint(n)
fun main() =
putint(__LINE__)

View File

@@ -69,10 +69,6 @@ public record Token(Report.Location location, Symbol symbol, String lexeme) impl
* Kljucna beseda {@code in}. * Kljucna beseda {@code in}.
*/ */
IN, IN,
/**
* Kljucna beseda {@code times}.
*/
TIMES,
/** /**
* Kljucna beseda {@code end}. * Kljucna beseda {@code end}.
*/ */
@@ -152,7 +148,11 @@ 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

@@ -319,7 +319,7 @@ 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 "times" -> Token.Symbol.TIMES; case "__LINE__" -> Token.Symbol.LINE;
default -> null; default -> null;
}; };
} }
@@ -452,6 +452,15 @@ 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,

View File

@@ -360,9 +360,9 @@ public class SynAn implements AutoCloseable {
private AST.AtomExpr parseIntegerConstantMultiplier() { private AST.AtomExpr parseIntegerConstantMultiplier() {
Token token = lexAn.peekToken(); Token token = lexAn.peekToken();
if (token.symbol() == Token.Symbol.TIMES) { if (token.symbol() == Token.Symbol.MUL) {
// intconstmult -> TIMES const // intconstmult -> MUL const
check(Token.Symbol.TIMES); check(Token.Symbol.MUL);
return parseConstant(); return parseConstant();
} }
// intconstmult -> ε // intconstmult -> ε