diff --git a/.gitignore b/.gitignore index 585d773..5545717 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ out/ *.zip prg/**/*.ast prg/**/*.out -prg/**/*.pins25 \ No newline at end of file diff --git a/prg/test.pins25 b/prg/test.pins25 new file mode 100644 index 0000000..9b7e0d5 --- /dev/null +++ b/prg/test.pins25 @@ -0,0 +1,4 @@ +fun putint(n) + +fun main() = + putint(__LINE__) \ No newline at end of file diff --git a/src/pins25/common/Token.java b/src/pins25/common/Token.java index 2685303..a4c9d07 100644 --- a/src/pins25/common/Token.java +++ b/src/pins25/common/Token.java @@ -148,7 +148,11 @@ public record Token(Report.Location location, Symbol symbol, String lexeme) impl /** * Simbol {@code )}. */ - RPAREN; + RPAREN, + /** + * Simbol {@code __LINE__}. + */ + LINE } @Override diff --git a/src/pins25/phase/LexAn.java b/src/pins25/phase/LexAn.java index 888f692..46a92ed 100644 --- a/src/pins25/phase/LexAn.java +++ b/src/pins25/phase/LexAn.java @@ -319,6 +319,7 @@ 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; }; } @@ -451,6 +452,15 @@ 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,