From 352085b499950c85d486b4ad347d04c41a05ab5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C5=A1per=20Dobrovoljc?= Date: Wed, 4 Jun 2025 14:14:46 +0200 Subject: [PATCH] Predrok 2025 - Naloga 1 --- .gitignore | 1 - grammar.txt | 26 +++++++++++++++++++++++++- prg/test.pins25 | 5 +++++ src/pins25/phase/LexAn.java | 8 +++++++- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 prg/test.pins25 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/grammar.txt b/grammar.txt index 4de9353..e696064 100644 --- a/grammar.txt +++ b/grammar.txt @@ -69,4 +69,28 @@ restinits -> COMMA initializer restinits | . initializer -> INTCONST intconstmult | CHARCONST | STRINGCONST . intconstmult -> MUL const | . -const -> INTCONST | CHARCONST | STRINGCONST . \ No newline at end of file +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 | . \ No newline at end of file diff --git a/prg/test.pins25 b/prg/test.pins25 new file mode 100644 index 0000000..4cca59b --- /dev/null +++ b/prg/test.pins25 @@ -0,0 +1,5 @@ +// line1 -- +line2 -----x +line3 + +fun main() = 0 \ No newline at end of file diff --git a/src/pins25/phase/LexAn.java b/src/pins25/phase/LexAn.java index 888f692..fb44355 100644 --- a/src/pins25/phase/LexAn.java +++ b/src/pins25/phase/LexAn.java @@ -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(); }