How to differentiate '-' operator from a negative number for a tokenizer

后端 未结 1 1580
后悔当初
后悔当初 2021-01-12 16:16

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

相关标签:
1条回答
  • 2021-01-12 16:43

    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.

    0 讨论(0)
提交回复
热议问题