Re: [問題] 要用啥資料結構
使用context free grammer
parse整行文字
變成你的parse tree
然後再針對你的語法樹去處理
parse的方法基本上可分成兩種
bottom up方法與top down的方法
你可以查一下compiler的書
或上google查一下相關的資訊
※ 引述《horngsh (dotNetProgrammer)》之銘言:
: 各位好:
: 我想作一個類似運算式分析並運算的命令列, 如以下:
: ? 1+3
: 4
: ? 2*6
: 12
: ? 1+3 + 2*6
: 16
: ? (1+5) * 6 + 2*4
: 44
: 請問我要如何去parse使用者可能輸入的算式並算出答案?
: 感恩您!
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.109.169.200
※ 編輯: seagal 來自: 140.109.169.200 (08/21 10:54)
討論串 (同標題文章)
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章