Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Parser_の面白さを探ってみた_BNF編
Search
Sena
November 24, 2026
Programming
29
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Parser_の面白さを探ってみた_BNF編
仙台 Ruby 会議 #03 の Gaji-Labo のスポンサーLT で発表した資料です。
Sena
November 24, 2026
Transcript
19 slides
Parser の⾯⽩さを 探ってみた @BNF編 2026.11.21 仙台 Ruby 会議 03 株式会社
Gaji-Labo Sena(村上 世南)
⾃⼰紹介 Sena Gaji-Labo フロントエンドエンジニア • Ruby 初⼼者 • 最近 Parser
に興味あり 2
⾃⼰紹介 Sena Gaji-Labo フロントエンドエンジニア • Ruby 初⼼者 • 最近 Parser
に興味あり なぜ⾯⽩いのか、⾔語化できないことに気がついた 3
⾃分が思う Parser の⾯⽩さを 探ってみよう 4
Parser とは ⽂字列に隠れた構造を、⽂法に従って⾒つけ出すもの + "1 + 2 * 3" 1
* ←2*3が ひとかたまり 2 3 この構造で、計算の順番が決まる 5
BNF とは • プログラミング⾔語の構⽂をわかりやすく記述するための記法の⼀つ。 • 左辺に⽂法規則の名称、右辺にそれを構成する要素を記述し、 構⽂を表現する。 • <名称> は置き換え可能、
| は「または」 <ラーメン > ::= <味> "ラーメン " <味> ::= "味噌" | "醤油" | "塩" 6
題材:四則演算 四則演算の BNF を書いてみて、 その中で感じた⾃分の⾯⽩ポイントを話します 想定される⼊⼒ 1 + 2 +
3 10 - 3 - 2 1 + 2 * 3 2 * 3 + 1 8 / 4 / 2 # => 6 # => 5 # => 7 # => 7 # => 1 7
⾜し算、引き算の BNF <式> ::= <number> | <式> "+" <number> |
<式> "-" <number> <number> ::= 整数 8
1 + 2 + 3 で確かめる <式> ::= <number> |
<式> "+" <number> | <式> "-" <number> <式> "+" <number> 1 + 2 + 3 <式> "+" <number> 1 + 2 9
ふとした疑問:逆ではダメなのか <式> ::= <number> | <number> "+" <式> | <number>
"-" <式> ⾜し算の 1 + 2 + 3 は、逆の形でも読めて、答えも 6 のまま <number> "+" <式> 1 + 2 + 3 1 + 5 = 1 10
10 - 3 - 2 で⽐べる 逆の形:<式> が右 <式> ::=
<number> | <number> "+" <式> | <number> "-" <式> 10 - 3 - 2 10 - 1 = 9 間違い 11
10 - 3 - 2 で⽐べる 逆の形:<式> が右 元の形:<式> が左
<式> ::= <number> | <number> "+" <式> | <number> "-" <式> 10 - 3 - 2 10 - 1 <式> ::= <number> | <式> "+" <number> | <式> "-" <number> 10 - 3 - 2 = 9 間違い 7 -2 = 5 正しい 11
10 - 3 - 2 で⽐べる 逆の形:<式> が右 元の形:<式> が左
<式> ::= <number> | <number> "+" <式> | <number> "-" <式> <式> ::= <number> | <式> "+" <number> | <式> "-" <number> 10 - 3 - 2 = 9 間違い 10 - 3 - 2 = 5 正しい 左から先に計算されるようにしたいので、 左がかたまりになってほしい 11
掛け算‧割り算 さっきの⾜し算‧引き算 <式> ::= <number> | <式> "+" <number> |
<式> "-" <number> 掛け算‧割り算 <項> ::= <number> | <項> "*" <number> | <項> "/" <number> 掛け算‧割り算も、左から先に計算されてほしい 12
完成! ⼀緒にする <式> から <項> を呼ぶ形にした <式> ::= <項> |
<式> "+" <項> | <式> "-" <項> <項> ::= <number> | <項> "*" <number> | <項> "/" <number> <number> ::= 整数 ◦1 + 2 + 3 ◦ 10 - 3 - 2 (この四則演算の BNF は簡易的に表現しています。) ◦1 + 2 * 3 ◦2 * 3 + 1 ◦8 / 4 / 2 13
1 + 2 * 3 で確かめる + "1 + 2
* 3" 1 ← 呼ぶ側(⾜し算の <式>) * ← 呼ばれる側 (掛け算の <項>) 2 3 掛け算を先に計算したいので、 掛け算がかたまりになってほしい 14
⾃分が思う Parser の⾯⽩さとは 15
⾃分が思う Parser の⾯⽩さ ⼈間が頭でやっている、 構造化の作業を ルールとして落とし込める 16
プロダクトの課題を⼀緒に解決します。 最適な技術と、適切な⼿段で。 Gaji-Laboはフロントエンド開発者と UI デザイナーが チームメンバーとして参画するスタートアップ⽀援の会社です。 フロントエンド開発や UI デザインなどの専⾨技術の提供を軸に、 成⻑⽀援のためのチームワークの提供を⼀番⼤切にしています。
17
Other Decks in Programming
See All in Programming
ローカルLLMの基本と近況 2611 / Local LLM basics and recent situation 2611
kishida
3
690
SODA - FACT BOOK(JP)
sodainc
1
40k
imagewebp()の向こう側: WebPはなぜ JPEG・PNGより軽いのか
yuzneri
0
160
エラーチャンネルのボールを拾い続けて鍛えるエンジニアの地力 / phpcon-niigata2026
meihei3
1
620
正解の無い問題を 「できるだけ上手く」解く ヒューリスティックで感性を磨こう。〜現実課題をプログラミングで解きあうコミュニティについて〜
allegrogiken
0
120
なぜ私たちは「現時点では」KMPの導入を見送ったのか
chigichan24
1
650
地方こそサーバーレス — 10年続けた、顔が見えるチームで確かな基盤を / Serverless Matters Most in Regional Areas — 10 Years of Building Reliable Foundations with Close-Knit Teams
seike460
PRO
2
530
数行の変更でDockerビルドを最大91%高速化~GitLab CIの実行基盤を社内40リポジトリに展開するまで~
picopico
4
1.3k
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
3
360
仕様駆動開発入門 (何を作るかを先に決めて渡す) | 目指せ Kiro マスター 05
inariku
PRO
3
270
Spec-driven Development with AI
simas
PRO
0
2.3k
Proxmox x Talos Linux x Terraform で実現するなんかいい感じの Kubernetes クラスタ / A Sleek Kubernetes Cluster Powered by Proxmox, Talos Linux, and Terraform
nnaka2992
0
320
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Practical Orchestrator
shlominoach
192
12k
Discover your Explorer Soul
emna__ayadi
2
1.4k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
480
Building Applications with DynamoDB
mza
96
7.3k
A Tale of Four Properties
chriscoyier
163
24k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
560
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
970
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
610
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.3k