Upgrade to Pro — share decks privately, control downloads, hide ads and more …

LALR parser generatorの作り方

yui-knk
January 20, 2024

LALR parser generatorの作り方

BuriKaigi 2024
https://burikaigi.dev/

yui-knk

January 20, 2024
Tweet

More Decks by yui-knk

Other Decks in Programming

Transcript

  1. About me • Yuichiro Kaneko • yui-knk (GitHub) / spikeolaf

    (Twitter) • Treasure Data • Engineering Manager of Applications Backend • The author of ruby/lrama LALR parser generator • CRuby committer, mainly develop parser related features
  2. ͍·RubyͰParser͕೤͍ • Bison͕ਏ͍ • Bisonͷversion͸؀ڥʹΑͬͯҟͳΔ • ෳ਺ͷBisonͷversionΛαϙʔτ͢ΔͨΊʹɺ৽͍͠ػೳ͕࢖͑ͳ͍ • Rubyͷparser͸ෳࡶͰɺϝϯςφϯεੑ͕௕Β͘໰୊ࢹ͞Ε͖ͯͨ •

    Language Server Protocolͷ୆಄ • RubyͰ͸RBS(ܕ)΍RubyCop(੩తղੳث)ͱ͍ͬͨπʔϧ͕׆ൃʹ։ൃ ͞Ε͍ͯΔ • ͦͷ݁ՌɺϢʔβʔͷೖྗதͷϓϩάϥϜͱ͍͏ෆ׬શͳೖྗΛύʔε͢ Δඞཁ͕Ͱ͖ͯͨ (ΤϥʔτϨϥϯτͳύʔαʔ) • ͜ΕΒΛղܾ͢ΔͨΊʹParserʹେن໛ͳվળΛ͍Ε͍ͯΔ
  3. LALRҎ֎ͷΞϧΰϦζϜ • ߏจղੳͷͨΊͷΦʔτϚτϯͷ࡞Γํ͸͍Ζ͍Ζ͋Δ • LR(0), SLR(1), LALR(1), LR(1), IELR(1) ͳͲͷΞϧΰϦζϜ͕͋Δ

    • ղੳՄೳͳݴޠ΍ඞཁͳϝϞϦ͕ͦΕͧΕҟͳΔ • Rule͔ΒΦʔτϚτϯΛ࡞ΔͷͰɺΞϧΰϦζϜͷબ୒͕จ๏ϑΝΠϧͷ γϯλοΫεͱಠཱ͍ͯ͠Δ
  4. ߴ଎ͳLook-Aheadू߹ͷܭࢉ • LALR(1)Λ࣮૷͢Δͱ͖ʹ໰୊ʹͳΔͷ͕ɺޮ཰తʹLook-Aheadू߹Λ ܭࢉ͢Δ͜ͱ • “Ef fi cient Computation of

    LALR(1) Look-Ahead Sets” ͱ͍͏࿦จͷΞ ϧΰϦζϜΛ࢖༻͢ΔͱΑ͍ • https://dl.acm.org/doi/pdf/10.1145/69622.357187
  5. ·ͱΊ • LR parser͸͍͍ͧ • LR parser generator͸3ͭͷίϯϙʔωϯτ͔ΒͳΓɺݴޠॲཧܥʹߏ଄͕ࣅ ͍ͯΔ •

    ෼ׂ͞Ε͍ͯΔͨΊػೳ௥Ճͷࡍʹඞཁͳίϯϙʔωϯτ͚ͩΛมߋ͢Ε͹͍͍ • Lrama parser generator͸ΨϯΨϯ։ൃத • ͔Ͷ͜ʹ͖ͬͰRubyͷparserͷ։ൃঢ়گΛ·ͱΊ͍ͯΔ • https://yui-knk.hatenablog.com/ • ruby-jpͱ͍͏slackͷ #lr-parser νϟωϧʹීஈ͍Δ