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

Racc Introduction

Racc Introduction

201-10-25 Shinjuku.rb #54 言語のしくみ

Hirofumi Wakasugi

October 25, 2017
Tweet

More Decks by Hirofumi Wakasugi

Other Decks in Programming

Transcript

  1. ݴޠॲཧܥʹ͓͚ΔίϯύΠϥͷ࢓ࣄ RACC INTRODUCTION ࣈ۟ղੳ MFYJDBMBOBMZTJT  wೖྗจࣈྻΛτʔΫϯʹ෼ׂ UPLFOJ[F  wࣈ۟ղੳͷػߏΛ୲͏΋ͷΛࣈ۟ղੳث

    MFYFS ͱ͍͏ ߏจղੳ TZOUBYBOBMZTJT  wτʔΫϯ͔Β"45Λߏங͢Δ wߏจղੳͷػߏΛ୲͏΋ͷΛߏจղੳث QBSTFS ͱ͍͏ ҙຯղੳ TFNBOUJDTBOBMZTJT  wʜ ࠷దԽ DPEFPQUJNJ[BUJPO  wʜ όΠφϦίʔυੜ੒ DPEFHFOFSBUJPO  wʜ
  2. ݴޠॲཧܥʹ͓͚ΔίϯύΠϥͷ࢓ࣄ RACC INTRODUCTION ࣈ۟ղੳ MFYJDBMBOBMZTJT  wೖྗจࣈྻΛτʔΫϯʹ෼ׂ UPLFOJ[F  wࣈ۟ղੳͷػߏΛ୲͏΋ͷΛࣈ۟ղੳث

    MFYFS ͱ͍͏ ߏจղੳ TZOUBYBOBMZTJT  wτʔΫϯ͔Β"45Λߏங͢Δ wߏจղੳͷػߏΛ୲͏΋ͷΛߏจղੳث QBSTFS ͱ͍͏ ҙຯղੳ TFNBOUJDTBOBMZTJT  wʜ ࠷దԽ DPEFPQUJNJ[BUJPO  wʜ όΠφϦίʔυੜ੒ DPEFHFOFSBUJPO  wʜ
  3. QBSTFSHFOFSBUPSͱ͸ RACC INTRODUCTION w ͦͷ໊ͷ௨ΓʮQBSTFSΛੜ੒͢Δ΋ͷʯ w QBSTFS΋ϓϩάϥϜͰ͋Δ w QBSTFSΛ։ൃ͢Δͷ͸ Ұൠతʹ

    େม w QBSTFSʹٻΊΒΕΔػೳ ಡΈ΍͘͢نଇԽ͠΍͍͢จ๏ͱ͔-"-3ͱ͔ ͸൚༻త ˣ
 QBSTFSΛࣗಈੜ੒͢ΔϓϩάϥϜ͕͋Δͱศར
  4. QBSTFSHFOFSBUPS RACC INTRODUCTION w ୅දతͳQBSTFSHFOFSBUPSʹɺ:BDD΍ͦͷ্Ґޓ׵ͷ(/6#JTPO͕͋Δ  .3*ͷίϯύΠϥͰ͸#JTPOΛ࢖͍ͬͯΔ 4FFAQBSTFZAGPSEFUBJMT  w

    3BDD͸؆୯ʹݴ͏ͱ:BDDͷ3VCZ൛  จ๏ϑΝΠϧΛॻ͘͜ͱͰίʔυͷʮߏ଄ʯΛղੳ͢Δ εΫϦϓτΛ࡞Δ   ྨࣅͷ΋ͷʹ1ZUIPOͷ1-:ͳͲ͕͋Δ
  5. ࠓ͔ΒSBDDͷ͜ͱ஌ͬͱ͘ཧ༝͋Δʁ RACC INTRODUCTION w SBDDͰάάͬͯ΋͋Μ·Γ࠷ۙͷهࣄ͕ώοτ͠ͳ͍ΑͶʁ  ͍ΖΜͳͱ͜ΖͰ࢖ΘΕͯΔ͔Β͖ͬͱؒ઀తʹ࢖͍ͬͯΔ  QBSTFSHFN 3VCPDPQͱ͔Ͱ࢖ΘΕͯΔ΍ͭ

    ͷQBSTFSੜ੒͸SBDD  SVCFYͱ͔͔ͳΓ৽͍͠HFNͰ΋SBDD͕࢖ΘΕͯΔ w Ͱ΋ݴޠॲཧܥ͍͡Γ͍ͨਓ͔͠ඞཁͳ͍ΑͶʁ  QBSTFS͸ѻ͑ΔΑ͏ʹͳ͓ͬͯ͘ͱศརͰ͢ ޙड़
  6. SBDDͷจ๏ϑΝΠϧ RACC INTRODUCTION DMBTT.Z1BSTFS SVMF JG@TUNU*'FYQSUIFOFYQSFMTF&/% UIFO5)&/ ] FMTF&-4&FYQS ]

    FYQS/6.#&3 ]*%&/5 ]453*/( ǘ FOE : (ίϩϯ) ͸౳ՁͰ͋Δ͜ͱΛࣔ͢ ͭ·Γࠨลͷ if_stmt ͱ ӈลͷ IF expr then expr else END ͸౳ՁͰ͋Δ
  7. SBDDͷจ๏ϑΝΠϧ RACC INTRODUCTION DMBTT.Z1BSTFS SVMF JG@TUNU*'FYQSUIFOFYQSFMTF&/% UIFO5)&/ ] FMTF&-4&FYQS ]

    FYQS/6.#&3 ]*%&/5 ]453*/( ǘ FOE ݴ͍׵͑Δͱ ӈลͷ IF expr then expr else END ͱ͍͏ߏจ͕ݱΕͨΒ ͦΕ͸ if_stmt ͱ͍͏ ʮه߸ʯͰදݱ͞Εͨ΋ͷͱ͞ΕΔ (= ࠨล͸ӈลʹஔ׵Ͱ͖Δ)
  8. SBDDͷจ๏ϑΝΠϧ RACC INTRODUCTION DMBTT.Z1BSTFS SVMF JG@TUNU*'FYQSUIFOFYQSFMTF&/% UIFO5)&/ ] FMTF&-4&FYQS ]

    FYQS/6.#&3 ]*%&/5 ]453*/( ǘ FOE | (ύΠϓ) ͸ʮorʯΛࣔ͢ ͭ·ΓӈลͷTHENͱ͍͏ه߸ ·ͨ͸ Կ΋ͳ͍ʮۭനʯͷ৔߹͸ thenͱ͍͏ه߸ͱ౳ՁͱͳΔ
  9. SBDDͷจ๏ϑΝΠϧ RACC INTRODUCTION DMBTT.Z1BSTFS SVMF JG@TUNU*'FYQSUIFOFYQSFMTF&/% UIFO5)&/ ] FMTF&-4&FYQS ]

    FYQS/6.#&3 ]*%&/5 ]453*/( ǘ FOE ͜͜Ͱɺ ࠨลʹ͋Δه߸ ͱ ӈลʹ͚ͩ͋Δه߸ ͱ͍͏ͷͷ۠ผ͸ॏཁͰ͋Δ
  10. SBDDͷจ๏ϑΝΠϧ RACC INTRODUCTION DMBTT.Z1BSTFS SVMF JG@TUNU*'FYQSUIFOFYQSFMTF&/% UIFO5)&/ ] FMTF&-4&FYQS ]

    FYQS/6.#&3 ]*%&/5 ]453*/( ǘ FOE ࠨลʹ͋Δه߸͸ ඇऴ୺ه߸ͱ͍ͬͯ ෼ׂ͞ΕͨΓଞͷه߸ (ྻ) ʹஔ׵͞ΕΔ ඇऴ୺ه߸͸ҰൠతʹখจࣈͰॻ͘
  11. SBDDͷจ๏ϑΝΠϧ RACC INTRODUCTION DMBTT.Z1BSTFS SVMF JG@TUNU*'FYQSUIFOFYQSFMTF&/% UIFO5)&/ ] FMTF&-4&FYQS ]

    FYQS/6.#&3 ]*%&/5 ]453*/( ǘ FOE ӈลʹ͚ͩ͋Δه߸͸ ऴ୺ه߸ͱ͍ͬͯ ͦΕҎ্෼ׂ͞ΕͨΓ͢Δ͜ͱ͸ͳ͍ ʮ͜ͷྫͰ͸ʯ͢΂ͯେจࣈʹͳ͍ͬͯΔ
  12. SBDDͷจ๏ϑΝΠϧ RACC INTRODUCTION DMBTT.Z1BSTFS SVMF JG@TUNU*'FYQSUIFOFYQSFMTF&/% UIFO5)&/ ] FMTF&-4&FYQS ]

    FYQS/6.#&3 ]*%&/5 ]453*/( ǘ FOE ߏจղੳ͞ΕΔτʔΫϯྻ͸ ྫ͑͹࣍ͷΑ͏ͳऴ୺ه߸ͷྻͰ͋Δ IF IDENT THEN STRING ELSE NUMBER END
  13. SBDDͷจ๏ϑΝΠϧ RACC INTRODUCTION DMBTT.Z1BSTFS SVMF JG@TUNU*'FYQSUIFOFYQSFMTF&/% UIFO5)&/ ] FMTF&-4&FYQS ]

    FYQS/6.#&3 ]*%&/5 ]453*/( ǘ FOE IF IDENT THEN STRING ELSE NUMBER END ͕ IF expr then expr else END ͷه߸ʹ߹க͠ if_stmtͱͯ͠ղऍ͞ΕΔ
  14. SBDDͷจ๏ϑΝΠϧ RACC INTRODUCTION DMBTT.Z1BSTFS SVMF JG@TUNU*'FYQSUIFOFYQSFMTF&/% UIFO5)&/ ] FMTF&-4&FYQS ]

    FYQS/6.#&3 ]*%&/5 ]453*/( ǘ FOE *'*%&/5453*/(&/% ȕ *'FYQSFYQS&/% ȕ *'FYQS UIFO FYQS FMTF &/% ȕ JG@TUNU
  15. RACC INTRODUCTION DMBTT.Z1BSTFS SVMF JG@TUNU*'FYQSUIFOFYQSFMTF&/% \ SFTVMUJGWBM<> WBM<> FOE ^

    ǘ FYQS/6.#&3 \SFTVMUWBM<>UP@J^ ]*%&/5 \SFTVMUWBM<>^ ]453*/( \SFTVMUWBM<>^ ǘ FOE valͱresult͸نఆͷม਺໊
  16. RACC INTRODUCTION ǘ NPEVMF@FWBM    QBSTFSSCZ  

    EFG@SFEVDF@ WBM @WBMVFT SFTVMU  SFTVMUWBM<>UP@J SFTVMU FOE    NPEVMF@FWBM    QBSTFSSCZ   EFG@SFEVDF@ WBM @WBMVFT SFTVMU  SFTVMUWBM<> SFTVMU FOE    NPEVMF@FWBM    QBSTFSSCZ   EFG@SFEVDF@ WBM @WBMVFT SFTVMU  SFTVMUWBM<> SFTVMU FOE    EFG@SFEVDF@OPOF WBM @WBMVFT SFTVMU  WBM<> FOE ǘ େྔͷ module_eval
  17. RACC INTRODUCTION ǘ NPEVMF@FWBM    QBSTFSSCZ  

    EFG@SFEVDF@ WBM @WBMVFT SFTVMU  SFTVMUWBM<>UP@J SFTVMU FOE    NPEVMF@FWBM    QBSTFSSCZ   EFG@SFEVDF@ WBM @WBMVFT SFTVMU  SFTVMUWBM<> SFTVMU FOE    NPEVMF@FWBM    QBSTFSSCZ   EFG@SFEVDF@ WBM @WBMVFT SFTVMU  SFTVMUWBM<> SFTVMU FOE    EFG@SFEVDF@OPOF WBM @WBMVFT SFTVMU  WBM<> FOE ǘ ʮreduce_*ʯͱ͍͏ϝιου໊͕໨ཱ͕ͭɺreduce (ؐݩ) ͱ͍͏ͷ͸τʔΫϯ΍ه߸Λඇऴ୺จࣈʹॱ࣍ ஔ͖׵͍͑ͯ͘͜ͱ
  18. RACC INTRODUCTION DMBTT)T1BSTFS SVMF TUBUFNFOU/6.#&3A*%&/5AMJTU \ FYQ@BSSBZWBMSFKFDU\]F]FA^ IT@GVOD)4'VODUJPOOFX  SFDFJWFSFYQ@BSSBZ<>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ʑָ͍͠ ͔΋   ͨͩ--7.ͷ3VCZCJOEJOH͸͜Εͱ͍ͬͨ΋ͷ͕ͳ͍ MMWN@JS@GJMFQVUT TUS ʜʁ