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
We Have a Design System, Now What?
morganepeng
54
8k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
320
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
117
110k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
750
Between Models and Reality
mayunak
1
190
Un-Boring Meetings
codingconduct
0
200
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Faster Mobile Websites
deanohume
310
31k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
Amusing Abliteration
ianozsvald
0
100
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を紹介しました