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
LL法とLR法の違いは?調べてみた!-完全版-/Comparing LL and LR par...
Search
Junichi Kobayashi
November 29, 2023
Programming
2.9k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
LL法とLR法の違いは?調べてみた!-完全版-/Comparing LL and LR parse algorithm -EX Edition-
Junichi Kobayashi
November 29, 2023
Transcript
30 slides
LL 法と LR 法の違いは? 調べてみた! 完全版 ESM アジャイル事業部 構文解析器研究部員 小林純一
(@junk0612) Fukuoka.rb #333 Ninja Talk 大会 オンライン 2023/11/29(Wed.)
Fukuoka.rb 333回目 おめでとう ございます
Fukuoka.rb 333回目 おめでとう ございます • RubyWorld Conference 2023 で行われたスポンサートーク 「ESM
スーパーライトニングトークス」の 私が担当した部分の再演・増補改訂版です • 半分も終わらないうちに時間が来てしまったので 面白いところまでたどり着けませんでした • この内容を 80 秒で話そうとしたのが良くなかった (反省) ◦ いや、終わらないだろうとは思ってたんですけど…… この発表は
LL 法と LR 法の違いは? 調べてみた! 完全版 ESM アジャイル事業部 構文解析器研究部員 小林純一
(@junk0612) Fukuoka.rb #333 Ninja Talk 大会 オンライン 2023/11/29(Wed.)
• 小林純一 • X / GitHub: @junk0612 • 株式会社永和システムマネジメント アジャイル事業部
◦ RubyxAgile グループ ◦ 構文解析器研究部員 • Lrama コントリビューター ◦ Named References の実装 ◦ 内部パーサーの Racc 化 など 自己紹介
None
None
None
世はまさに 大パーサー時代
LL 法 と LR 法
LL法とLR法 LL法 • トップダウン方式 • 左端導出 • 手書きに適している • 先読みによって構文を推測する
• Prism が採用している LR法 • ボトムアップ方式 • 右端導出 • 手書きには適さない • 決定論的に構文木を構築する • Lrama が生成するパーサーが 採用している
LL法とLR法 LL法 • トップダウン方式 • 左端導出 • 手書きに適している • 先読みによって構文を推測する
• Prism が採用している LR法 • ボトムアップ方式 • 右端導出 • 手書きには適さない • 決定論的に構文木を構築する • Lrama が生成するパーサーが 採用している
例: メソッド定義 method_definition def method_name ( args ) method_body end
method_definition def method_name ( args ) = method_body
Fukuoka.rb 333回目 おめでとう ございます • パーサーは自分が今どこを読んでいるかを知っている • 今読んでいるルールにおいて次に何が来るはずかは 文法ファイルからわかる •
次のトークンを先読みし、何であったかによって処理を分岐する ◦ 分岐の決定に必要なトークンの先読み数が k のとき LL(k) と表記する • 来るはずのないトークンが来たら文法エラーとする LL 法の基本的な考え方
method_definition LL法の場合
method_definition def method_name LL法の場合
method_definition def method_name 分岐 • → 引数 • → end-less
メソッド • → メソッド本体 ( = method_body LL法の場合
method_definition def method_name 分岐 • → 引数 • → end-less
メソッド • → メソッド本体 ( = method_body ( LL法の場合
method_definition def method_name ( args ) LL法の場合
method_definition def method_name ( args ) 分岐 • → end-less
メソッド • → メソッド本体 = method_body LL法の場合
method_definition def method_name ( args ) 分岐 • → end-less
メソッド • → メソッド本体 = method_body = LL法の場合
LL法の場合 method_definition def method_name ( args ) = method_body
Fukuoka.rb 333回目 おめでとう ございます • パーサーは自分が何を読んできたかを知っている • 読んできたトークンがどういう並びになったら 上位のトークンに置換可能かは、文法ファイルからわかる •
トークンを読み進んでいき、置換可能なトークンが一意になったら置換す ることを繰り返す • 現在の並びで置換可能なトークンがなくなったら文法エラーとする LR 法の基本的な考え方
LR法の場合 def
LR法の場合 def method_name
LR法の場合 def method_name ( args )
LR法の場合 def method_name ( args ) = method_body
LR法の場合 method_definition def method_name ( args ) = method_body
LL法とLR法 LL法 • トップダウン方式 • 左端導出 • 手書きに適している • 先読みによって構文を推測する
• Prism が採用している LR法 • ボトムアップ方式 • 右端導出 • 手書きには適さない • 決定論的に構文木を構築する • Lrama が生成するパーサーが 採用している
Let's parse everything your favorite algorithm.
More Decks by Junichi Kobayashi
See All by Junichi Kobayashi
XP をバイブルにする事業部で10年働いた新卒が語りたい『Tidy First?』/ Put your understanding into the code
junk0612
0
110
rage against annotate_predecessor
junk0612
0
300
The Implementations of Advanced LR Parser Algorithm
junk0612
3
2.9k
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
6
2.9k
LR で JSON パーサーを作る / Coding LR JSON Parser
junk0612
2
2.1k
「ナントカLR」を整理する / Clarifying LR Algorithms
junk0612
1
750
From LALR to IELR: A Lrama's Next Step
junk0612
2
5.4k
RubyConf Taiwan / Understanding Parser Generators surrounding Ruby with Contributing Lrama
junk0612
2
7.3k
ESM Super LT/Comparing LL and LR parse algorithm
junk0612
1
260
Other Decks in Programming
See All in Programming
AIがコードを書いてくれる時代、我々は何を確かめるのか
yosuke_furukawa
PRO
13
5.9k
LLM 101: Exploring LLMs, Starting with Tokens.
dalinaum
0
110
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
180
Performance Optimization With LLMs
xleitix
0
260
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
750
Distance field of Julia set
kinakomoti321
0
320
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
660
Web3Dライブラリを作ってVue Custom Rendererの仕組みを理解しよう / lets learn vue custom renderer by making 3d library
drumath2237
1
130
AI-Powered Domain-Driven Design
ziobrando
0
440
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
1.7k
PyConTW 2026 - AI Coding 不只是工具升級, 區域醫院醫療資訊系統協作開發與資訊團隊轉型實踐
cclai999
0
250
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
140
Featured
See All Featured
Prompt Engineering for Job Search
mfonobong
0
580
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
350
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
So, you think you're a good person
axbom
PRO
2
2.3k
How to Think Like a Performance Engineer
csswizardry
28
2.9k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
330
30 Presentation Tips
portentint
PRO
1
470
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
750
The Cult of Friendly URLs
andyhume
79
7.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Building AI with AI
inesmontani
PRO
1
1.4k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1.1k