Division/RegExp conflict while tokenizing Javascript [duplicate]
This question already has an answer here: When parsing Javascript, what determines the meaning of a slash? 5 answers I'm writing a simple javascript tokenizer which detects basic types: Word, Number, String, RegExp, Operator, Comment and Newline. Everything is going fine but I can't understand how to detect if the current character is RegExp delimiter or division operator. I'm not using regular expressions because they are too slow. Does anybody know the mechanism of detecting it? Thanks. You can tell by what the preceding token is is in the stream. Go through each token that your lexer emits