I'm implementing a lexer for a simple programming language (ultimately an interpreter and code generator) as a project to learn C.
I've got my lexer to a pretty good state and am able to parse identifiers, numbers, operators, but one issue I am trying to figure out is how to handle error conditions while 'lexing' the input. For example if I have a token for a number:
237ab
This is not a valid number because it ends with the alpha 'a' and 'b' characters. In this case, I have a couple different options:
1. Immediately error out and let the user know of the line and position of the invalid token.
2. Store the token anyway and allow later steps (such as parser) to actually do the validation
3. Store the error, and return all errors at once at the end of lexing.
Any ideas on which method is generally used or how error handling should be done with lexical analysis?