※ [本文轉錄自 LinuxDev 看板]
作者: dozer (piercing buddy?) 看板: LinuxDev
標題: Re: [問題] 引用直譯語言的parser?
時間: Fri Jan 9 16:22:21 2009
※ 引述《dozer (rezod)》之銘言:
: 比如說 我想要在一個類似resource file裡面給expression
: e.g.
: [resource.rc]
: alpha = foo
: beta = alpha*10+300
: EOF
: 我希望我的程式在讀這個input的時候
: 可以evaluate這個expression
: 也就是beta最後應該是 'foo*10+300' 計算後的結果
: 但是如果要自己寫parser又覺得像是重新發明輪子
: 有沒有人知道怎麼把python之類的直譯語言
: 的parser直接拿來用呀? 還是這樣其實會更麻煩?
自己回。
現在是用embedded Python,非常的簡單好用!!!
Python的C API非常完整(如果你用的是C Python,整個interpreter
本來就是用C寫的,對C的支援度當然好)之前有試著自己用Flex/Bison
寫parser,雖然寫的出來,但改起來真的很花時間;加上本身沒有實做
程式語言直譯器/編譯器的經驗,幾乎是矇著眼睛在做。直接引用現成的
interpreter的好處就是彈性大,好學,而且extend起來也真的容易
很多(我現在整個app是C/Python混著寫,超方便!)
有興趣可以參考官方文件
Python/C API Reference Manual
http://docs.python.org/c-api/index.html
Extending and Embedding the Python Interpreter
http://docs.python.org/extending/index.html
--
Westheimer's Discovery:
A couple of months in the laboratory can frequently save a
couple of hours in the library.
--
作者: dozer (piercing buddy?) 看板: LinuxDev
標題: Re: [問題] 引用直譯語言的parser?
時間: Fri Jan 9 16:22:21 2009
※ 引述《dozer (rezod)》之銘言:
: 比如說 我想要在一個類似resource file裡面給expression
: e.g.
: [resource.rc]
: alpha = foo
: beta = alpha*10+300
: EOF
: 我希望我的程式在讀這個input的時候
: 可以evaluate這個expression
: 也就是beta最後應該是 'foo*10+300' 計算後的結果
: 但是如果要自己寫parser又覺得像是重新發明輪子
: 有沒有人知道怎麼把python之類的直譯語言
: 的parser直接拿來用呀? 還是這樣其實會更麻煩?
自己回。
現在是用embedded Python,非常的簡單好用!!!
Python的C API非常完整(如果你用的是C Python,整個interpreter
本來就是用C寫的,對C的支援度當然好)之前有試著自己用Flex/Bison
寫parser,雖然寫的出來,但改起來真的很花時間;加上本身沒有實做
程式語言直譯器/編譯器的經驗,幾乎是矇著眼睛在做。直接引用現成的
interpreter的好處就是彈性大,好學,而且extend起來也真的容易
很多(我現在整個app是C/Python混著寫,超方便!)
有興趣可以參考官方文件
Python/C API Reference Manual
http://docs.python.org/c-api/index.html
Extending and Embedding the Python Interpreter
http://docs.python.org/extending/index.html
--
Westheimer's Discovery:
A couple of months in the laboratory can frequently save a
couple of hours in the library.
--
All Comments