Closed Origami404 closed 3 years ago
Oh how stupid I am. The substr
method in Java uses left-closed and right-opened interval. I am trying to implement the lox interpreter following the book by C++ and have ignored the difference between each languages' APIs.
Hello, you book is amazing and I enjoy it very much. But the function
string()
in Scanning/String literals makes me a little confused.If the code run to
Point A
, that meanspeek() == '"'
is statisfied, thecurrent
will reference to the character'"'
like that:And then there is a
advance()
, which will change thecurrent
to the next character after'"'
:Now if I use
source.substring(start + 1, current - 1)
to get the literal, I will get"ABCD";
as lexeme andABCD"
as literal, which to my understanding is NOT what the code is designed to do.I suggest to change the
substring(start + 1, current - 1)
tosubstring(start + 1, current - 2)
, so that I could get"ABCD"
as lexeme andABCD
as literal. If I just moveadvance()
to the end of the function I will get"ABCD
as lexeme.Sorry for any mistakes. English is not my native language.