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
Let’s Create An Interpreter In Go
Search
Kenshi Kamata
November 05, 2017
Programming
160
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Let’s Create An Interpreter In Go
Go Conference 2017 Autumn
Kenshi Kamata
November 05, 2017
More Decks by Kenshi Kamata
See All by Kenshi Kamata
500万ユーザーを支える残高の冪等性 / The idempotency of the balance for 5 million Merpay users
knsh14
0
3k
チャネルの仕組み
knsh14
6
5.6k
Go1.10 strings.Builder の紹介
knsh14
2
1.5k
Go でインタプリタを 書いてみよう
knsh14
0
3.1k
Go Code Review Comment を翻訳した話
knsh14
0
7.7k
tvOS Leaderboard
knsh14
0
1.2k
Other Decks in Programming
See All in Programming
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
980
音楽のための関数型プログラミング言語mimiumにおける多段階計算の活用
tomoyanonymous
1
340
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
510
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
170
20260623_Loop Engineeringで自分の分身の問い合わせBotを作る
ryugen04
0
230
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
150
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.5k
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
320
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
400
OSINT for SRE: 学術論文とポストモーテムから探る システム障害の共通パターン / SRE NEXT 2026
tomoyk
1
3.9k
5分で問診!Composer セキュリティ健康診断
codmoninc
0
420
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
170
Featured
See All Featured
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
WCS-LA-2024
lcolladotor
0
730
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Optimising Largest Contentful Paint
csswizardry
37
3.8k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
350
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
How GitHub (no longer) Works
holman
316
150k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
Transcript
Let’s Create An Interpreter In Go Go Conference 2017 Autumn
Self Introduce • Kenshi Kamata • @knsh14 (twitter, GitHub) •
KLab inc. ◦ Unity3d Editor Extension ◦ Create Facebook Instant Game
What I did? • Read Writing An Interpreter In Go
◦ https://interpreterbook.com/ • Actually Create An Interpreter • Create An Interpreter in about 1400 lines! ◦ Included test code, about 2500 lines
DEMO let x = 0; let array = [0, 10,
20, 30, 40]; array[1]; let fib = fn(x) { if(x == 0) { 0; } else { if (x == 1) { 1;} else { fib(x-1) + fib(x-2);}}}; let loop = fn(i, max, f) { if(i == max){return 0;} f(); loop(i +1, max, f);}; let p = fn() { puts(“hello world”);};
Why I did? • I want to create self-produced Language
• Tried “Writing An Interpreter In C” book ◦ but it was so hard and gave up • I heard good book by Go is released! so I decided to try again.
Specification • Monkey Language • Integer, Boolean, String, Function •
Array, Hash • Able to use if statement ◦ No For loop • No yacc, use self-implemented Lexer and Parser
How long Until Finished • About 1 month • some
finished in one week • Most of people can finish within 1.5 month
Hard Part • Parser logic was hard • Pratt Parser
• google 演算子順位法 in japanese
What I learned • Fun to make Language by myself!
• Understand AST a little through Parser Chapter • Not Following Go Practice in Some part
Understand AST • Build AST in Parser Chapter • Wrote
A tool to check cyclomatic complexity with AST in past but it was poor code • I must be able to write better code after reading Parser chapter
Not Following Go Practice • Return Error ASAP / Return
Error type • Not good practice in Interpreter • Example Code in Monkey • Actually, go/parser has similar code • https://golang.org/src/go/parser/parser.go filter by “p.error”, you can see no handling error
Not following Go practice • Don’t want to stop processing
• For user experience, Parse to End then show all error messages • append to error string list, so not need to handle error at the time
Finally • Great feeling to exec code on my own
interpreter ◦ different feeling to playing my own game • Good for Japanese people ◦ Easy English ◦ Understand by English after Understanding by Code
Next is Your Turn!!