作者descent (「雄辯是銀,沉默是金」)
看板Programming
標題Re: [問題] 在自製語言中,如何表示函數和物件
時間Mon Apr 24 21:25:17 2017
你目前可以使用變數嗎?
ex:
int c;
c=5;
c+3*2;
這需要使用"環境"
ref:
http://descent-incoming.blogspot.tw/2016/07/compiler-4.html
這篇有點錯誤, 但概念就是那樣。
因為得會處理變數, 才能處理函數,
函數的定義 AST ref:
http://descent-incoming.blogspot.tw/2017/02/compiler-26-variable-function.html
抱歉, 貼錯, 這是 function call
http://descent-incoming.blogspot.tw/2017/03/compiler-39-function-call-ast.html
最後提供我的學習心得以及購買的書籍
http://descent-incoming.blogspot.tw/2017/01/blog-post.html
物件我就沒研究了。
※ 引述《Neisseria (Neisseria)》之銘言:
: 小弟先前沒事寫一個計算機
: 目前寫了 lexer, parser, interpreter
: 有自製的 AST (abstract syntax tree)
: 為了練功,這些功能沒依賴 yacc 或其他外部套件
: 有以下功能:
: - 可處理整數和浮點數
: - 簡易代數運算,像 (123 + 45)**(5 % 3)
: - 常見數學公式,像指對數、三角函數等
: (直接 call host language 的相關功能)
: 卡在函數 (function) 和物件 (class) 不知道如何表示
: 希望板上各位大大提示一些方向
: 目前先以 interpreter 為目標
: 因 compiler 還牽涉到轉機械碼的過程
: 目前對小弟來說太硬了
: 先在這裡謝過各位大大
--
紙上得來終覺淺,絕知此事要躬行。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 101.15.3.13
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Programming/M.1493040325.A.1E7.html
※ 編輯: descent (101.15.3.13), 04/24/2017 22:40:40
1F:推 Neisseria: 我的有變數,細節在我文章中175.182.114.180 04/24 22:44
2F:推 Neisseria: 之前大大的文我有看一下,蠻有意思的175.182.114.180 04/24 22:55
3F:→ Neisseria: 小弟比較喜歡做 interpreter175.182.114.180 04/24 22:56
4F:→ Neisseria: 因為經 parser 處理後,可根據需求再175.182.114.180 04/24 22:57
5F:→ Neisseria: 進一步做自已想做的事情175.182.114.180 04/24 22:57
6F:→ Neisseria: compiler 就留給高手去玩吧175.182.114.180 04/24 22:57
7F:→ Neisseria: 或許有機會大家可以交流一下 XD175.182.114.180 04/24 22:58
8F:→ descent: 我只是想把編譯流程都跑過一次, 101.15.3.13 04/24 23:00
9F:→ descent: 沒特別想做什麼 101.15.3.13 04/24 23:01
10F:→ descent: 我現在產生的組合語言說不定還沒 101.15.3.13 04/24 23:02
11F:→ descent: interpreter 快, 囧 101.15.3.13 04/24 23:02
※ 編輯: descent (101.15.3.13), 04/24/2017 23:04:26
12F:推 Neisseria: 大大畫 AST 的方式很有趣175.182.114.180 04/24 23:07
13F:→ Neisseria: 小弟我都偷懶,直接用 LISP 風格字串175.182.114.180 04/24 23:07
14F:→ Neisseria: 來表示 AST,超方便 der175.182.114.180 04/24 23:07
15F:→ Neisseria: 像 (+ (* 3 2) (/ 7 4))175.182.114.180 04/24 23:08
16F:→ descent: 因為 AST 具象化之後, 才比較容易知道 101.15.3.13 04/25 00:07
17F:→ descent: 自己走到那個 node 101.15.3.13 04/25 00:07
18F:→ descent: 等你有了 function + parameter 後, 101.15.3.13 04/25 00:08
19F:→ descent: 就沒那麼容易看了 101.15.3.13 04/25 00:08
20F:→ descent: lisp 一堆括弧的語法真的很難看, 101.15.3.13 04/25 00:12
21F:→ descent: 要排的好看也很難 101.15.3.13 04/25 00:13