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

Menhir is here!

ydah
November 29, 2023

Menhir is here!

Fukuoka.rb #333 Ninja Talk 大会『Menhir is here!』のスライド
https://fukuokarb.connpass.com/event/302318/

ydah

November 29, 2023
Tweet

More Decks by ydah

Other Decks in Programming

Transcript

  1. ɾ Name: Yudai Takada ɾ GitHub: @ydah / X: @ydah_

    ɾ Software Engineer at ANDPAD, Inc. ɾ Member of RuboCop RSpec team ɾ Contributor of Lrama ɾ Implementation of Parameterizing rules ɾ Optimization of Lexer, etc. self.inspect
  2. • Highly functional LR(1) parser generator for the OCaml •

    OCaml also has a parser generator called ocamlyacc, Menhir is 90% compatible with ocamlyacc • Designed and implemented by François Pottier and Yann Régis-Gianas What is Menhir?
  3. • Single, upright megalithic monument • The word menhir was

    adopted by 19th century archaeologists via the French • There is also famous menhir in Japan. There are many in Gifu By the Way
  4. • LALR (1) parser generator written in Ruby • Created

    as a CRuby parser generator to replace GNU Bison. • The author is Yuichiro Kaneko • Ref: https://yui-knk.hatenablog.com/entry/2023/03/13/101951 • Ref: https://youtu.be/IhfDsLx784g?si=I3DG-ccG2rxbqxHd What is Lrama?
  5. • Before replacing it with Lrama, Ruby had to support

    multiple Bison • It is not easy to maintain for multiple version • New features are added, but they are not available One of reasons replaced Bison
  6. • Can break away from multiple versions of maintenance! •

    It will can use new features in Bison! (If we implement it) • Parser generator features other than Bison may be used! (if we implement it) The world after replacing Lrama
  7. • Can break away from multiple versions of maintenance! •

    It will can use new features in Bison! (If we implement it) • Parser generator features other than Bison may be used! (if we implement it) The world after replacing Lrama
  8. • We have the goal of making parse.y more readable

    • We need richer DSL for Lrama grammar fi les Provide rich syntax extensions
  9. So

  10. • Parameterizing rules • Rules can be parameterized with any

    number of symbols, called formal parameters • The standard library • A library of standard parameterization de fi nitions • Inlining • The %inline keyword helps avoid or resolve con fl icts without arti fi cially changing the grammar Useful Menhir Features
  11. Useful Menhir Features • Parameterizing rules • Rules can be

    parameterized with any number of symbols, called formal parameters • The standard library • A library of standard parameterization de fi nitions • Inlining • The %inline keyword helps avoid or resolve con fl icts without arti fi cially changing the grammar
  12. • The de fi nition of a non-terminal symbol can

    be parameterized with other (terminal or non-terminal) symbols • Provide syntax sugar for common pattern for grammar rules Parameterizing rules
  13. Parameterizing rules args : arg | args ',' arg ;

    args : separated_list(',', arg) ;
  14. Parameterizing rules Name Recognizes Alias option(X) є | X X?

    list(X) a possibly empty sequence of X’s X* nonempty_list(X) a nonempty sequence of X’s X+ separated_list(sep, X) a possibly empty sequence of X’s separated with sep’s separated_nonempty_list(sep, X) a nonempty sequence of X’s   separated with sep’s
  15. Tag for Parameterizing rules %union { int i; char *str;

    } % t oken <i> NUMBER % t oken <str> S T RING
  16. program: option(foo) { $$ = $ 1 } program: option_foo

    { $$ = $ 1 } option_foo: ε option_foo: foo Tag for Parameterizing rules
  17. %union { int i; } program : option(foo) <i> ;

    Tag for Parameterizing rules
  18. • Support for users to de fi ne rules •

    Support for nesting of parameterizing rules. e.g. `option(list(arg))` • Support for %inline Future Vision of Parameterizing rules
  19. end