unary minus in shunting yard expression parser

后端 未结 2 1707
孤街浪徒
孤街浪徒 2021-01-12 12:35

here is my expression parser using shunting-yard algorithm it work well as expected except in one situation , when I use unary minus like in -2*3 it wont work (I think it s

2条回答
  •  天涯浪人
    2021-01-12 13:19

    One option is to put a 0 in front if the first character is '-'. You have to do this also when the - is after a (.

    Nicer ones are implementing either the unary minus operator or treating it as part of the number literal.

提交回复
热议问题