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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Kenshi Kamata
November 05, 2017
Programming
170
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
承認済みなのに差戻しできてしまうバグ、型で潰せます
shinchit
0
130
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
280
業務時間外もAIに働いてもらう話
colorful12
3
9.4k
Go 1.27からのGODEBUG / Go 1.27 リリースパーティ #go127party
mazrean
0
270
30年振りにコンパイラの定数整数除算を改善した
herumi
9
4.4k
不幸な GC
chencmd
0
840
tsc.rip を支える技術 / Kyoto.なんか #8
susisu
0
4.1k
ハーネス設計入門 〜プロンプト、コンテキストの次〜
kinopeee
47
30k
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
550
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
260
T3DD26: From RAGs to Riches
martinhelmich
0
130
VibeCodingからAgenticWorkflowへ
starfish719
0
1k
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
Accessibility Awareness
sabderemane
1
190
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
830
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
New Earth Scene 8
popppiees
3
2.5k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
2
3.8k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
430
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!!