柴田妹 2年時間交到貨未

605 回覆
201 Like 4 Dislike
2020-11-01 19:47:43
2020-11-01 23:37:57
自己寫有
2020-11-02 00:23:40
你噏咩鳩
2020-11-02 00:37:10
咩鳩 你真係講緊shunting yard?
2020-11-02 00:41:01
Shunting yard你諗做兩條stack 一條operand stack 一條operator stack
然後while放野入去operator stack個時 有個precedence高啲既野係operator stack到
例如你要放-號 但已經有*號 咁你就pop operator stack to operand stack
2020-11-02 00:42:15
Shunting yard既condition 就係operator stack top precedence > current token precedence
唔知你噏咩鳩list晒所有condition 得個一千零一個condition
2020-11-02 00:44:38
弱閪智 有>唔用 要hard code 2>1 3>1 4>1咁落去
2020-11-02 00:49:40
老實講 你個()係有意義既問題
但係hard code +_*/? 屌你唔撚識lookup table將個operator map做precedence 然後就咁數值比較大細牙?
2020-11-02 00:57:41
Alternative 1
你可以一路build tree 一路浮next token上去
例如1*2+3咁 你首先有個1*2既tree
然後個+你放去last nose = 2既left child到 再浮上去適當既位

Alternative 2
你對每個token mark number of bracket
例如
1+(2+3)-4
就係
111222111
然後拎max number個抽
拎highest precedence operator去fuse做tree
Loop until all token consumed

以上係手巴十五年前想自己寫parser個時所諗既alternative
2020-11-02 00:59:22
Step1
2
Empty

Step2
2
-

(略
2 3
-

2 3
- *

2 3 4
- *

2 3 4 *
-

2 3 4 * -
2020-11-02 01:00:15
藉口 衰on9就衰on9
下次記得唔撚好睇lecture notes 而係搵wiki
2020-11-02 01:07:51
屌 咁做咩撚野唔睇wiki牙
2020-11-02 12:26:40
@柴田妹
2020-11-02 12:29:05
牙柴:google is ok
2020-11-02 18:16:20
點解你可以咁堅持
2020-11-02 19:21:30
係愛 同USD100呀
吹水台自選台熱 門最 新手機台時事台政事台World體育台娛樂台動漫台Apps台遊戲台影視台講故台健康台感情台家庭台潮流台美容台上班台財經台房屋台飲食台旅遊台學術台校園台汽車台音樂台創意台硬件台電器台攝影台玩具台寵物台軟件台活動台電訊台直播台站務台黑 洞