diff --git a/.idea/misc.xml b/.idea/misc.xml index eeb80f7..687f0c0 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/prg/test.pins b/prg/test.pins index bf201c5..50c9cdf 100644 --- a/prg/test.pins +++ b/prg/test.pins @@ -1,2 +1,16 @@ -var test = "1234" // hello world -var something = 33 \ No newline at end of file +1234567890 += , && || ! == != > < >= <= + - * / % ^ ( ) +=,&&||!==!=><>=<=+-*/%^() +_a_0_ A0312 asd312 a_132asdnmznkjNAJDKNSJKDF +fun var if then else while do let in end +_fun_ _var_ _if_ _then_ _else_ _while_ _do_ _let_ _in_ _end_ +infun invar inif inthen inelse inwhile indo inlet inin inend +funin varin ifin thenin elsein whilein doin letin endin +// == * 1248129 d8as90d8as9d asdkal // +1234567890='a' // 1+2 +-1/asd*'x'+"" +'a' '\'' '\\' '\0a' "\\ 1231 \n \ff _-ads" +"BESEDNJAKKKK" "0\" 0123" 0=XYZ 123+3+2+1(SSS) 4_bese + + +dica beseder_3456 \ No newline at end of file diff --git a/src/pins25/phase/LexAn.java b/src/pins25/phase/LexAn.java index 853d72b..20d3bff 100644 --- a/src/pins25/phase/LexAn.java +++ b/src/pins25/phase/LexAn.java @@ -240,13 +240,14 @@ public class LexAn implements AutoCloseable { return; case '/': + start = currentLocation(); nextChar(); if (buffChar != '/') { - buffToken = new Token(currentLocation(), Token.Symbol.DIV, null); + buffToken = new Token(start, Token.Symbol.DIV, null); return; } - while (buffChar != '\n') { + while (buffChar != '\n' && buffChar != -1) { nextChar(); } @@ -399,10 +400,24 @@ public class LexAn implements AutoCloseable { nextChar(); while (buffChar != '"') { - if (buffChar == -1) { + if (buffChar == '\n' || buffChar == -1) { throw new Report.Error(currentLocation(), "Unterminated string."); } - if (!isChar()) { + + if (buffChar == '\\') { + lexeme.append((char) buffChar); + nextChar(); + if (buffChar == 'n' || buffChar == '\\' || buffChar == '"') { + } else if (isHex()) { + nextChar(); + lexeme.append((char) buffChar); + if (!isHex()) { + throw new Report.Error(currentLocation(), "Invalid ascii code '" + (char) buffChar + "'."); + } + } else { + throw new Report.Error(currentLocation(), "Invalid escaped character '" + (char) buffChar + "'."); + } + } else if (!isChar()) { throw new Report.Error(currentLocation(), "Invalid character '" + (char) buffChar + "'."); }