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
Proglrの紹介
Search
tkob
March 31, 2018
0
510
Proglrの紹介
tkob
March 31, 2018
Tweet
Share
Featured
See All Featured
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
210
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
0
110
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.2k
What does AI have to do with Human Rights?
axbom
PRO
0
2k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
270
Technical Leadership for Architectural Decision Making
baasie
1
240
A Modern Web Designer's Workflow
chriscoyier
698
190k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Faster Mobile Websites
deanohume
310
31k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
0
200
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Transcript
Proglrの紹介 tkob https://github.com/tkob/proglr
SMLと私 • ML-MessagePack https://github.com/tkob/mlmsgpack • UXML https://github.com/tkob/uxml – XML Parser
• SMLZIP https://github.com/tkob/smlzip – Access to ZIP files • 最近の活動 – SMLでsyslogdを作っています
Proglrの紹介 • SML向けのパーサージェネレーター – 私が作りました • BNFC互換のLBNFからパーサーとASTを生成 • Generalized LR
• 生成したパーサーが多くのSML処理系で使える
BNFC互換のLabelled BNF文法定義 token Add "+" ; … token Integer of
int; EAdd. Exp ::= Exp "+" Exp1 ; ESub. Exp ::= Exp "-" Exp1 ; EMul. Exp1 ::= Exp1 "*" Exp2 ; EDiv. Exp1 ::= Exp1 "/" Exp2 ; EInt. Exp2 ::= Integer ; coercions Exp 2 ;
生成されるAST structure Ast = struct datatype exp = EAdd of
Lex.span * exp * exp | ESub of Lex.span * exp * exp | EMul of Lex.span * exp * exp | EDiv of Lex.span * exp * exp | EInt of Lex.span * int …
生成されるパーサー(概略イメージ) fun go … = … and state15 … =
… … (* stateNが続く *) and state0 … = … fun parse sourcemap strm = … (* go を呼ぶ *) • 相互末尾再帰関数で状態を表現する – 読めなくもない気分のコード
parseの型 val parse : sourcemap -> strm -> Ast.exp list
• 何故Ast.expでなくAst.exp listなのか – 多義的な文法かもしれない(文脈自由文法) – ProglrはGeneralized LRを使用
なぜGLRなのか • あまり深い理由は… – 自分のパーサージェネレーターがほしい! – 教科書を読みながらまずはLR(0)まで作成 • 面倒くさくなってきた –
手っ取り早く表現力をあげられないか? – LR(0)ベースのGLRにするのが一番はやい(と思った)
Q: Proglrは私のSMLコンパイラで使えますか? • A: きっと… – 対応処理系: • SML/NJ, MLton,
Poly/ML, Alice ML, MLKit, Moscow ML, SML# – Proglr自体はMLtonかPoly/MLでビルドするのがおすすめ
Proglrの利用方法(MLton) $ proglr -m mlton -o parse.sml -l scan.ulex calc.cf
$ mlton main.mlb $ ./main sample.txt • -mオプションで処理系を指定するとプロジェクト一式 (MakefileやMLBやCM)が全部生成される • 用意するのは文法だけ
おわり • 大体全部の現存SML処理系で使えるパーサージェネレー ターのProglrを紹介しました