Closed dbarisakkurt closed 7 years ago
I think the lexer is correctly scanning the tokens, but you're right that lox should report an error. However, I also think that it is the parser's job to report the issue and not the lexer.
Here's a repl.it example using Javascript. Running the example will cause a SyntaxError.
@iwatakeshi is right. From the lexer's perspective, the code is fine. You get two tokens, a number followed by an identifier. The lexer doesn't know that's wrong any more than it would complain on, say, )(
. The parser will take care of ensuring an error is reported in this case.
I was studying your book and while I was reading code, i typed "54hello", the lexer of the language accepted it and the lexer returned:
Shouldn't it reject these kind of strings since they are against our identifier rule ([a-zA-Z_][a-zA-Z_0-9]*) or number rule?
I copied your Lox, Scanner,Token and TokenType classes into my workspace. It was against my expectation and i think it should conclude in error.