I am creating an infix expression parser, an so I have to create a tokenizer. It works well, except for one thing: I do not now how to differentiate negative number from the
In the first example the tokens should be 23
, /
, -
and 23
.
The solution then is to evaluate the tokens according to the rules of associativity and precedence. -
cannot bind to /
but it can to 23, for example.
If you encounter --56
, is split into -
,-
,56
and the rules take care of the problem. There is no need for special cases.