I am creating an infix parser, so I need to create a tokenizer. It works well, except for one thing: I don't understand how to distinguish a negative number from the "-" operator.
For example, if I have:
23 / -23
Tokens should be 23 , / and -23 , but if I have an expression like
23-22
Then the tokens should be 23 , - and 22 .
I found a dirty workaround that is, if I come across a “-” followed by a number, I look at the previous character and if that character is a number or “)”, I consider “-” as an operator and not a number. Besides being kind of ugly, it doesn't work for expressions like
--56
where he receives the following tokens: - and -56 , where he should receive --56
Any suggestion?
source share