Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Goでインタプリタつくった
Search
vortispy
March 05, 2017
Programming
0
290
Goでインタプリタつくった
"Writing An Interpreter In Go"
https://interpreterbook.com/
をよんでインタプリタつくった。ただそれだけの話。
vortispy
March 05, 2017
Tweet
Share
Other Decks in Programming
See All in Programming
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
7.4k
AI & Enginnering
codelynx
0
110
今から始めるClaude Code超入門
448jp
8
8.8k
AIによる高速開発をどう制御するか? ガードレール設置で開発速度と品質を両立させたチームの事例
tonkotsuboy_com
7
2.3k
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
21
7.2k
CSC307 Lecture 08
javiergs
PRO
0
670
CSC307 Lecture 09
javiergs
PRO
1
840
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
6.1k
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
2.5k
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
730
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
280
Featured
See All Featured
Abbi's Birthday
coloredviolet
1
4.7k
Building Applications with DynamoDB
mza
96
6.9k
Docker and Python
trallard
47
3.7k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.6k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.2k
Stop Working from a Prison Cell
hatefulcrawdad
273
21k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.7k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
210
Design in an AI World
tapps
0
140
Evolving SEO for Evolving Search Engines
ryanjones
0
120
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.2k
Transcript
Goでインタプリタつくった @vortispy
概要 • “Writing An Interpreter In Go”を読んでインタプ リタつくった • Go言語しか使わない
• GotoutineやChannelは使わない • 難しいことは気にせずとりあえず作ってみる
なにやった • 字句解析(Lexing) • 構文解析(Parsing) • 評価(Evaluation)
字句解析 • 文字列をTokenに変換する • “let a = 1;” → <LET><IDENT><ASSIGN><INT><SEMICOLO
N>
構文解析 • ここが山場 • TokenからAST(Abstract syntax tree)をつくる
let a = 1; if (a > 10) { return
a; } <LET><IDENT><ASSING><INT><SEMICOLON> <IF><IDENT><GT><INT><LBRACE> <RETURN><IDENT><SEMICOLON> <RBRACE>
None
• 使うアルゴリズムは“Top Down Operator Precedence”(Pratt parser)
評価 • ASTを解釈して実行する • どのように解釈させるか? • 例: “foo” * 3
• Python: “foofoofoo” • Go: cannot convert "foo" to type int invalid operation: "foo" * 3
• 自作インタプリタがプログラムを実行できるよ うになるので楽しい
まとめ • たのしい