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.4k
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
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
590
AI時代のUIはどこへ行く?その2!
yusukebe
22
7.5k
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
560
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
160
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.4k
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.6k
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.6k
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.4k
AIで効率化できた業務・日常
ochtum
0
150
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
190
1B+ /day規模のログを管理する技術
broadleaf
0
120
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
780
Featured
See All Featured
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
1.8k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
340
The Curious Case for Waylosing
cassininazir
1
400
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
Un-Boring Meetings
codingconduct
0
320
Typedesign – Prime Four
hannesfritz
42
3.1k
Are puppies a ranking factor?
jonoalderson
1
3.6k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
Everyday Curiosity
cassininazir
0
240
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
140
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!!