Problems with a shunting yard algorithm

前端 未结 4 1180
陌清茗
陌清茗 2020-12-10 07:02

I have successfully implemented a shunting yard algorithm in java. The algorithm itself was simple however I am having trouble with the tokenizer. Currently the algorithm wo

4条回答
  •  攒了一身酷
    2020-12-10 07:27

    The answers to this question might be helpful.

    In particular, one of those answers references a solution in C that handles unary minus.

    Basically, you have to recognize a unary minus based on the appearance of the minus sign in positions where a binary operator can't be, and make a different token for it, as it has different precedence.

    Dijkstra's original paper doesn't too clearly explain how he dealt with this, but the unary minus was listed as a separate operator.

提交回复
热议问题