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

たのしいRubyの構文解析ツアー

 たのしいRubyの構文解析ツアー

鹿児島Ruby会議02

More Decks by Misaki Shioi(塩井美咲/しおい)

Other Decks in Programming

Transcript

  1. 3VCZ͕ίʔυΛ࣮ߦ͢Δ·ͰͷྲྀΕ ϓϩάϥϜΛ࣮ࡍʹ࣮ߦ͢Δ໋ྩྻ ߏจղੳ ίϯύΠϧ ιʔείʔυ :"37όΠτίʔυ ࣈ۟ղੳ 1 + 2

    == disasm: #<ISeq:<main>@-e:1 (1,0)-(1,5)> (catch: false) 0000 putobject 1 ( 1)[Li] 0002 putobject 2 0004 send <calldata!mid:+, argc:1, ARGS_SIMPLE>, nil 0007 leave (OPCALL@1:0-1:5 (LIT@1:0-1:1 1) :+ (LIST@1:4-1:5 (LIT@1:4-1:5 2) nil))) ߏจ໦
  2. 3VCZ͕ίʔυΛ࣮ߦ͢Δ·ͰͷྲྀΕ ߏจղੳ ίϯύΠϧ ιʔείʔυ :"37όΠτίʔυ ࣈ۟ղੳ :"37্Ͱ࣮ߦ 1 + 2

    == disasm: #<ISeq:<main>@-e:1 (1,0)-(1,5)> (catch: false) 0000 putobject 1 ( 1)[Li] 0002 putobject 2 0004 send <calldata!mid:+, argc:1, ARGS_SIMPLE>, nil 0007 leave (OPCALL@1:0-1:5 (LIT@1:0-1:1 1) :+ (LIST@1:4-1:5 (LIT@1:4-1:5 2) nil))) ߏจ໦
  3. ߏจղੳ ίϯύΠϧ ιʔείʔυ :"37όΠτίʔυ ࣈ۟ղੳ :"37্Ͱ࣮ߦ ࣮ߦ݁Ռ > 3 1

    + 2 3VCZ͕ίʔυΛ࣮ߦ͢Δ·ͰͷྲྀΕ == disasm: #<ISeq:<main>@-e:1 (1,0)-(1,5)> (catch: false) 0000 putobject 1 ( 1)[Li] 0002 putobject 2 0004 send <calldata!mid:+, argc:1, ARGS_SIMPLE>, nil 0007 leave (OPCALL@1:0-1:5 (LIT@1:0-1:1 1) :+ (LIST@1:4-1:5 (LIT@1:4-1:5 2) nil))) ߏจ໦
  4. ᶅ௥ՃͰͲΜͳॲཧΛߦ͏͔ Φϓγϣϯ  ؐݩʹϑοΫͯ͠௥ՃͰ೚ҙͷॲཧΛߦ͏͜ͱ͕Ͱ͖Δ ͜ͷॲཧͷ͜ͱΛʮΞΫγϣϯʯͱݺͿ  .3*Ͱ͸ΞΫγϣϯΛར༻ͯ͠ߏจ໦Λ૊Έཱ͍ͯͯΔ /0%&@-*5 ਺஋ /0%&@-*5

    ਺஋ b ` Ճࢉه߸ ύʔαͷ͘͠Έߏจنଇ ΞΫγϣϯ  ߏจنଇྫᶅ ௥Ճͷॲཧ ؐݩʹϑοΫͯ͠ߏจ໦Λ૊ΈཱͯΔ ߏจ໦ ه߸ͷ஋
  5. .3*ͷ࣮ࡍͷߏจنଇ͸.3*ͷιʔείʔυʹؚ·ΕΔ QBSTFZʹఆٛ͞Ε͍ͯΔ /********************************************************************** parse.y - $Author$ created at: Fri May

    28 18:02:42 JST 1993 Copyright (C) 1993-2007 Yukihiro Matsumoto **********************************************************************/ // … %% // … %% // … IUUQTHJUIVCDPNSVCZSVCZCMPCW@@QBSTFZ Ͱғ·Ε͍ͯΔ෦෼ʹߏจنଇ͕ఆٛ͞Ε͍ͯΔ ߏจղੳศརπʔϧ  QBSTFZϑΝΠϧ
  6. ߏจղੳศརπʔϧ  QBSTFZϑΝΠϧ method_call : primary_value call_op operation2 opt_paren_args {

    $$ = new_qcall(p, $2, $1, $3, $4, &@3, &@$); nd_set_line($$, @3.end_pos.lineno); } ߏจنଇͷಡΈํɹྫQBSTFZ- ؆ུԽ͍ͯ͠·͢
  7. ߏจղੳศརπʔϧ  QBSTFZϑΝΠϧ method_call : primary_value call_op operation2 opt_paren_args {

    $$ = new_qcall(p, $2, $1, $3, $4, &@3, &@$); nd_set_line($$, @3.end_pos.lineno); } ؐݩޙͷه߸ ؐݩલͷه߸ྻ ΞΫγϣϯ Φϓγϣφϧ ߏจنଇͷಡΈํɹྫQBSTFZ- ؆ུԽ͍ͯ͠·͢
  8. method_call : primary_value call_op operation2 opt_paren_args { $$ = new_qcall(p,

    $2, $1, $3, $4, &@3, &@$); nd_set_line($$, @3.end_pos.lineno); } ߏจղੳศརπʔϧ  QBSTFZϑΝΠϧ  ҙຯ ᶃQSJNBSZ@WBMVF DBMM@PQ PQFSBUJPO PQU@QBSFO@BSHT͕ฒΜͩΒ ɹNFUIPE@DBMM΁ؐݩ͢Δ ᶄؐݩʹϑοΫͯ͠OFX@RDBMMؔ਺ͱOE@TFU@MJOFؔ਺Λݺͼग़͢ ؐݩޙͷه߸ ؐݩલͷه߸ྻ ΞΫγϣϯ Φϓγϣφϧ ߏจنଇͷಡΈํɹྫQBSTFZ- ؆ུԽ͍ͯ͠·͢
  9. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ add_delayed_token:7062 (0: 0|0|0)

    Starting parse Entering state 0 Stack now 0 Reducing stack by rule 1 (line 1580): lex_state: NONE -> BEG at line 1581 vtable_alloc:13130: 0x00006000034e9b40 vtable_alloc:13131: 0x00006000034e9b60 cmdarg_stack(push): 0 at line 13144 cond_stack(push): 0 at line 13145 -> $$ = nterm $@1 (1.0-1.0: ) QBSTFZͷߦ໨ʹఆٛ͞Ε͍ͯΔ ߏจنଇʹैͬͯؐݩΛ։࢝
  10. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ add_delayed_token:7062 (0: 0|0|0)

    Starting parse Entering state 0 Stack now 0 Reducing stack by rule 1 (line 1580): lex_state: NONE -> BEG at line 1581 vtable_alloc:13130: 0x00006000034e9b40 vtable_alloc:13131: 0x00006000034e9b60 cmdarg_stack(push): 0 at line 13144 cond_stack(push): 0 at line 13145 -> $$ = nterm $@1 (1.0-1.0: ) ߏจنଇ͸ࠓ͔Βߏจղੳ͢Δ४උΛ ߦ͏ͨΊͷಛघͳنଇͳͷͰ ࠓճ͸ৄࡉΛׂѪ͠·͢
  11. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    2 Stack now 0 2 Reading a token ͦͷ͙͢ޙɺύʔα͸εΩϟφΛ࢖ͬͯ ιʔείʔυ͔Βه߸ΛಡΈࠐΉ ه߸ΛಡΈࠐΉ
  12. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    2 Stack now 0 2 Reading a token lex_state: BEG -> END at line 9005 lex_state: END -> END at line 8282 parser_dispatch_scan_event:10499 (1: 0|1|5) Next token is token "integer literal" (1.0-1.1: 1) Shifting token "integer literal" (1.0-1.1: 1) ࣍ͷه߸͸JOUFHFSMJUFSBMzͩͬͨ  ͷͷ෦෼ JOUFHFSMJUFSBMz U*/5&(&3 Λγϑτ ˞lJOUFHFSMJUFSBMz͸ ɹߏจنଇ্U*/5&(&3ͱදݱ͞ΕΔ U*/5&(&3 ύʔαͷελοΫ
  13. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    41 Stack now 0 2 41 Reducing stack by rule 645 (line 5383): $1 = token "integer literal" (1.0-1.1: 1) -> $$ = nterm simple_numeric (1.0-1.1: NODE_LIT) ߏจنଇʹैͬͯؐݩΛ։࢝ U*/5&(&3ΛTJNQMF@OVNFSJDʹؐݩ // parse.y: L5383 simple_numeric : tINTEGER ύʔαͷελοΫ TJNQMF@OVNFSJD
  14. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    120 Stack now 0 2 120 Reducing stack by rule 643 (line 5372): $1 = nterm simple_numeric (1.0-1.1: NODE_LIT) -> $$ = nterm numeric (1.0-1.1: NODE_LIT) ߏจنଇʹैͬͯؐݩΛ։࢝ TJNQMF@OVNFSJDΛOVNFSJDʹؐݩ // parse.y: L5372 numeric : simple_numeric ύʔαͷελοΫ OVNFSJD
  15. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    119 Stack now 0 2 119 Reducing stack by rule 595 (line 4998): $1 = nterm numeric (1.0-1.1: NODE_LIT) -> $$ = nterm literal (1.0-1.1: NODE_LIT) // parse.y: L4998 literal : numeric ߏจنଇʹैͬͯؐݩΛ։࢝ OVNFSJDΛMJUFSBMʹؐݩ ύʔαͷελοΫ MJUFSBM
  16. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    106 Stack now 0 2 106 Reducing stack by rule 310 (line 3220): $1 = nterm literal (1.0-1.1: NODE_LIT) -> $$ = nterm primary (1.0-1.1: NODE_LIT) // parse.y: L3220 primary : literal ߏจنଇʹैͬͯؐݩΛ։࢝ MJUFSBMΛQSJNBSZʹؐݩ ύʔαͷελοΫ QSJNBSZ
  17. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    106 Stack now 0 2 106 Reducing stack by rule 310 (line 3220): $1 = nterm literal (1.0-1.1: NODE_LIT) -> $$ = nterm primary (1.0-1.1: NODE_LIT) ɾ͜͜·ͰͰ ͷΛ ɹه߸QSJNBSZͱͯ͠ղੳͰ͖ͨ ɾه߸QSJNBSZ͸ɺ͜ͷޙ ɹͲΜͳه߸ͱ૊Έ߹ΘͤΔ͔ʹΑͬͯ ɹద༻͢Δߏจنଇͱؐݩઌͷه߸͕ ɹมΘΔ ɾύʔα͸ɺ͜ͷޙͷ ɹιʔείʔυʹ ͕ଓ͘͜ͱΛ ɹࠓͷ࣌఺Ͱ͸·ͩ஌Βͳ͍ ύʔαͷελοΫ QSJNBSZ ߏจղੳͷݱࡏ஍఺
  18. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    90 Stack now 0 2 90 Reading a token ࣍ͷه߸ΛಡΈࠐΉ ࣍ͷه߸Λ֬ೝ͢ΔͨΊɺ ύʔα͸εΩϟφΛ࢖ͬͯ ιʔείʔυ͔Βه߸ΛಡΈࠐΉ
  19. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    90 Stack now 0 2 90 Reading a token parser_dispatch_scan_event:9833 (1: 1|1|4) lex_state: END -> BEG at line 10181 parser_dispatch_scan_event:10499 (1: 2|1|3) Next token is token '+' (1.2-1.3: ) ࣍ͷه߸͸b `ͩͬͨ ύʔαͷελοΫ QSJNBSZ ύʔα͸࣍ͷه߸͕b `Ͱ͋Δͱ͖ ه߸QSJNBSZʹରͯ͠ ͲΜͳߏจنଇΛద༻͢Δ΂͖͔൑அ͢Δ
  20. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Reading a

    token parser_dispatch_scan_event:9833 (1: 1|1|4) lex_state: END -> BEG at line 10181 parser_dispatch_scan_event:10499 (1: 2|1|3) Next token is token '+' (1.2-1.3: ) Reducing stack by rule 263 (line 2906): $1 = nterm primary (1.0-1.1: NODE_LIT) -> $$ = nterm arg (1.0-1.1: NODE_LIT) QSJNBSZΛBSHʹؐݩ // parse.y: 2906 arg : primary ߏจنଇʹैͬͯؐݩΛ։࢝ ύʔαͷελοΫ BSH ˞؆ུԽ͍ͯ͠·͢
  21. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    88 Stack now 0 2 88 Next token is token '+' (1.2-1.3: ) Shifting token '+' (1.2-1.3: ) b `Λγϑτ ύʔαͷελοΫ BSH b ` ղੳΛଓ͚ΔͨΊʹύʔα͸ ઌ΄Ͳ֬ೝͨ࣍͠ͷه߸b `Λ ελοΫʹγϑτ͢Δ
  22. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    88 Stack now 0 2 88 Next token is token '+' (1.2-1.3: ) Shifting token '+' (1.2-1.3: ) ɾ͜ͷ࣌఺ͰελοΫ಺ʹ͋Δ ɹ<BSHb `>ͱ͍͏ه߸ͷฒͼͰ ɹؐݩͰ͖Δߏจنଇ͸ଘࡏ͠ͳ͍ ύʔαͷελοΫ BSH b ` ߏจղੳͷݱࡏ஍఺
  23. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    367 Stack now 0 2 88 367 Reading a token ࣍ͷه߸ΛಡΈࠐΉ ࣍ʹؐݩͰ͖ΔنଇΛݟ͚ͭΔͨΊɺ ύʔα͸εΩϟφΛ࢖ͬͯ ࣍ͷه߸ΛಡΈࠐΉ
  24. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    367 Stack now 0 2 88 367 Reading a token parser_dispatch_scan_event:9833 (1: 3|1|2) lex_state: BEG -> END at line 9005 lex_state: END -> END at line 8282 parser_dispatch_scan_event:10499 (1: 4|1|1) Next token is token "integer literal" (1.4-1.5: 2) Shifting token "integer literal" (1.4-1.5: 2) ࣍ͷه߸͸lJOUFHFSMJUFSBMzͩͬͨ  ͷͷ෦෼ lJOUFHFSMJUFSBMz U*/5&(&3 Λγϑτ ύʔαͷελοΫ BSH b ` U*/5&(&3
  25. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    41 Stack now 0 2 88 367 41 Reducing stack by rule 645 (line 5383): $1 = token "integer literal" (1.4-1.5: 2) -> $$ = nterm simple_numeric (1.4-1.5: NODE_LIT) ߏจنଇʹैͬͯؐݩΛ։࢝ U*/5&(&3ΛTJNQMF@OVNFSJDʹؐݩ // parse.y: L5383 simple_numeric : tINTEGER ύʔαͷελοΫ BSH b ` TJNQMF@OVNFSJD
  26. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    120 Stack now 0 2 88 367 120 Reducing stack by rule 643 (line 5372): $1 = nterm simple_numeric (1.4-1.5: NODE_LIT) -> $$ = nterm numeric (1.4-1.5: NODE_LIT) ߏจنଇʹैͬͯؐݩΛ։࢝ TJNQMF@OVNFSJDΛOVNFSJDʹؐݩ // parse.y: L5372 numeric : simple_numeric ύʔαͷελοΫ BSH b ` OVNFSJD
  27. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    119 Stack now 0 2 88 367 119 Reducing stack by rule 595 (line 4998): $1 = nterm numeric (1.4-1.5: NODE_LIT) -> $$ = nterm literal (1.4-1.5: NODE_LIT) // parse.y: L4998 literal : numeric ߏจنଇʹैͬͯؐݩΛ։࢝ OVNFSJDΛMJUFSBMʹؐݩ ύʔαͷελοΫ BSH b ` MJUFSBM
  28. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    106 Stack now 0 2 88 367 106 Reducing stack by rule 310 (line 3220): $1 = nterm literal (1.4-1.5: NODE_LIT) -> $$ = nterm primary (1.4-1.5: NODE_LIT) // parse.y: L3220 primary : literal ߏจنଇʹैͬͯؐݩΛ։࢝ MJUFSBMΛQSJNBSZʹؐݩ ύʔαͷελοΫ BSH b ` QSJNBSZ
  29. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    106 Stack now 0 2 88 367 106 Reducing stack by rule 310 (line 3220): $1 = nterm literal (1.4-1.5: NODE_LIT) -> $$ = nterm primary (1.4-1.5: NODE_LIT) ɾ ઌ΄Ͳͱಉ͘͡  ɾه߸QSJNBSZ͸ɺ͜ͷޙ ɹͲΜͳه߸ͱ૊Έ߹ΘͤΔ͔ʹΑͬͯ ɹద༻͢Δߏจنଇͱؐݩઌͷه߸͕ ɹมΘΔ ɾύʔα͸ɺ͜ͷޙ ɹιʔείʔυ͕ऴྃ͢Δ͜ͱΛ ɹࠓͷ࣌఺Ͱ͸·ͩ஌Βͳ͍ ύʔαͷελοΫ BSH b ` QSJNBSZ ߏจղੳͷݱࡏ஍఺
  30. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    90 Stack now 0 2 88 367 90 Reading a token ࣍ͷه߸ΛಡΈࠐΉ ͦΕΛ֬ೝ͢ΔͨΊɺύʔα͸ εΩϟφΛ࢖ͬͯ࣍ͷه߸ΛಡΈࠐΉ
  31. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    90 Stack now 0 2 88 367 90 Reading a token lex_state: END -> BEG at line 9900 parser_dispatch_scan_event:10499 (1: 5|1|0) Next token is token '\n' (1.5-1.6: ) ࣍ͷه߸͸baO վߦίʔυ ͩͬͨ ύʔαͷελοΫ BSH b ` QSJNBSZ ύʔα͸࣍ͷه߸͕baO`Ͱ͋Δͱ͖ ه߸QSJNBSZʹରͯ͠ͲΜͳߏจنଇΛ ద༻͢Δ΂͖͔൑அ͢Δ
  32. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    90 Stack now 0 2 88 367 90 Reading a token lex_state: END -> BEG at line 9900 parser_dispatch_scan_event:10499 (1: 5|1|0) Next token is token '\n' (1.5-1.6: ) Reducing stack by rule 263 (line 2906): $1 = nterm primary (1.4-1.5: NODE_LIT) -> $$ = nterm arg (1.4-1.5: NODE_LIT) QSJNBSZΛBSHʹؐݩ // parse.y: 2906 arg : primary ߏจنଇʹैͬͯؐݩΛ։࢝ ύʔαͷελοΫ BSH b ` BSH ελοΫʹ BSH b ` BSH͕ฒΜͩ ˞؆ུԽ͍ͯ͠·͢
  33. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    602 Stack now 0 2 88 367 602 Next token is token '\n' (1.5-1.6: ) Reducing stack by rule 231 (line 2745): $1 = nterm arg (1.0-1.1: NODE_LIT) $2 = token '+' (1.2-1.3: ) $3 = nterm arg (1.4-1.5: NODE_LIT) -> $$ = nterm arg (1.0-1.5: NODE_OPCALL) // parse.y: L2745 arg : arg ‘+’ arg BSHb `BSHΛBSHʹؐݩ ߏจنଇʹैͬͯؐݩΛ։࢝ ύʔαͷελοΫ BSH ˞؆ུԽ͍ͯ͠·͢
  34. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    602 Stack now 0 2 88 367 602 Next token is token '\n' (1.5-1.6: ) Reducing stack by rule 231 (line 2745): $1 = nterm arg (1.0-1.1: NODE_LIT) $2 = token '+' (1.2-1.3: ) $3 = nterm arg (1.4-1.5: NODE_LIT) -> $$ = nterm arg (1.0-1.5: NODE_OPCALL) // parse.y: L2745 BSHBSHb `BSH \  DBMM@CJO@PQ Q  b   ! !  ^ ˞؆ུԽ͍ͯ͠·͢ ͜ͷߏจنଇʹ͸ ߏจ໦Λ૊ΈཱͯΔͨΊͷ ΞΫγϣϯ͕ఆٛ͞Ε͍ͯΔ
  35. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    602 Stack now 0 2 88 367 602 Next token is token '\n' (1.5-1.6: ) Reducing stack by rule 231 (line 2745): $1 = nterm arg (1.0-1.1: NODE_LIT) $2 = token '+' (1.2-1.3: ) $3 = nterm arg (1.4-1.5: NODE_LIT) -> $$ = nterm arg (1.0-1.5: NODE_OPCALL) ˞؆ུԽ͍ͯ͠·͢ ߏจ໦Λ૊ΈཱͯΔؔ਺͕ ݺͼग़͞Ε͍ͯΔ // parse.y: L2745 BSHBSHb `BSH \  DBMM@CJO@PQ Q  b   ! !  ^
  36. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    602 Stack now 0 2 88 367 602 Next token is token '\n' (1.5-1.6: ) Reducing stack by rule 231 (line 2745): $1 = nterm arg (1.0-1.1: NODE_LIT) $2 = token '+' (1.2-1.3: ) $3 = nterm arg (1.4-1.5: NODE_LIT) -> $$ = nterm arg (1.0-1.5: NODE_OPCALL) BSHBSHb `BSH \  DBMM@CJO@PQ Q  b   ! !  ^ ˞؆ུԽ͍ͯ͠·͢ Ҿ਺ʹه߸ͷ஋Λ౉͍ͯ͠Δ ʜࠨͷBSHͷ஋ ਺஋  b `ʜՃࢉه߸ ʜӈͷBSHͷ஋ ਺஋ // parse.y: L2745
  37. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    602 Stack now 0 2 88 367 602 Next token is token '\n' (1.5-1.6: ) Reducing stack by rule 231 (line 2745): $1 = nterm arg (1.0-1.1: NODE_LIT) $2 = token '+' (1.2-1.3: ) $3 = nterm arg (1.4-1.5: NODE_LIT) -> $$ = nterm arg (1.0-1.5: NODE_OPCALL) ˞؆ུԽ͍ͯ͠·͢ ͜ͷؔ਺Λ࣮ߦ͢Δͱ ૊ΈཱͯΒΕͨߏจ໦͕ฦͬͯ͘Δ // parse.y: L2745 BSHBSHb `BSH \  DBMM@CJO@PQ Q  b   ! !  ^
  38. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    602 Stack now 0 2 88 367 602 Next token is token '\n' (1.5-1.6: ) Reducing stack by rule 231 (line 2745): $1 = nterm arg (1.0-1.1: NODE_LIT) $2 = token '+' (1.2-1.3: ) $3 = nterm arg (1.4-1.5: NODE_LIT) -> $$ = nterm arg (1.0-1.5: NODE_OPCALL) ˞؆ུԽ͍ͯ͠·͢ ૊ΈཱͯΒΕͨߏจ໦͕ ؐݩޙͷه߸BSHʹඥͮ͘஋Λද͢ ʹ୅ೖ͞ΕΔ BSHBSHb `BSH \  DBMM@CJO@PQ Q  b   ! !  ^ // parse.y: L2745
  39. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    602 Stack now 0 2 88 367 602 Next token is token '\n' (1.5-1.6: ) Reducing stack by rule 231 (line 2745): $1 = nterm arg (1.0-1.1: NODE_LIT) $2 = token '+' (1.2-1.3: ) $3 = nterm arg (1.4-1.5: NODE_LIT) -> $$ = nterm arg (1.0-1.5: NODE_OPCALL) ύʔαͷελοΫ BSH /0%&@01$"--  /0%&@-*5 ਺஋ /0%&@-*5 ਺஋ ߏจ໦ ͜ΕʹΑͬͯؐݩޙͷه߸BSHʹ ߏจ໦͕ඥ͍ͮͨঢ়ଶʹͳΔ
  40. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    88 Stack now 0 2 88 Next token is token '\n' (1.5-1.6: ) Reducing stack by rule 65 (line 2051): $1 = nterm arg (1.0-1.5: node_opcall) -> $$ = nterm expr (1.0-1.5: node_opcall) // parse.y: 2051 expr : arg BSHΛFYQSʹؐݩ ߏจنଇʹैͬͯؐݩΛ։࢝ ύʔαͷελοΫ FYQS ˞؆ུԽ͍ͯ͠·͢
  41. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    75 Stack now 0 2 75 Next token is token '\n' (1.5-1.6: ) Reducing stack by rule 37 (line 1853): $1 = nterm expr (1.0-1.5: NODE_OPCALL) -> $$ = nterm stmt (1.0-1.5: NODE_OPCALL) // parse.y: 1853 stmt : expr FYQSΛTUNUʹؐݩ ߏจنଇʹैͬͯؐݩΛ։࢝ ύʔαͷελοΫ TUNU ˞؆ུԽ͍ͯ͠·͢
  42. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    73 Stack now 0 2 73 Next token is token '\n' (1.5-1.6: ) Reducing stack by rule 7 (line 1635): $1 = nterm stmt (1.0-1.5: NODE_OPCALL) -> $$ = nterm top_stmt (1.0-1.5: NODE_OPCALL) // parse.y: 1635 top_stmt : stmt TUNUΛUPQ@TUNUʹؐݩ ߏจنଇʹैͬͯؐݩΛ։࢝ ύʔαͷελοΫ UPQ@TUNU ˞؆ུԽ͍ͯ͠·͢
  43. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    72 Stack now 0 2 72 Reducing stack by rule 5 (line 1619): $1 = nterm top_stmt (1.0-1.5: NODE_OPCALL) -> $$ = nterm top_stmts (1.0-1.5: NODE_OPCALL) // parse.y: 1619 top_stmts : top_stmt UPQ@TUNUΛUPQ@TUNUTʹؐݩ ߏจنଇʹैͬͯؐݩΛ։࢝ ύʔαͷελοΫ UPQ@TUNUT ˞؆ུԽ͍ͯ͠·͢
  44. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    72 Stack now 0 2 72 Reducing stack by rule 5 (line 1619): $1 = nterm top_stmt (1.0-1.5: NODE_OPCALL) -> $$ = nterm top_stmts (1.0-1.5: NODE_OPCALL) ɾ͜͜·ͰͰ ɹ ΛղੳͰ͖ͨ ɾ͋ͱ͸վߦίʔυaOΛ ɹಡΈࠐΜͰ͜ͷߦΛऴ୺ͤ͞Δ ɹඞཁ͕͋Δ ύʔαͷελοΫ UPQ@TUNUT ߏจղੳͷݱࡏ஍఺ ˞վߦޙʹϝιουݺͼग़͠ͷAA υοτ ͕ ɹଓ͘έʔε͸εΩϟφͰରԠ͍ͯ͠·͕͢ ɹࠓճ͸ղઆΛׂѪ͠·͢
  45. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    71 Stack now 0 2 71 Next token is token '\n' (1.5-1.6: ) Shifting token '\n' (1.5-1.6: ) baOΛγϑτ ࣍ͷه߸͸aO ߦ຤ ͩͬͨ ύʔαͷελοΫ UPQ@TUNUT baO`
  46. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    310 Stack now 0 2 71 310 Reducing stack by rule 778 (line 6115): $1 = token '\n' (1.5-1.6: ) -> $$ = nterm term (1.5-1.5: ) // parse.y: 6115 term : ‘\n’ baO`ΛUFSNʹؐݩ ߏจنଇʹैͬͯؐݩΛ։࢝ ύʔαͷελοΫ UPQ@TUNUT UFSN
  47. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    312 Stack now 0 2 71 312 Reducing stack by rule 779 (line 6122): $1 = nterm term (1.5-1.5: ) -> $$ = nterm terms (1.5-1.5: ) // parse.y: 6122 terms : term UFSNΛUFSNTʹؐݩ ߏจنଇʹैͬͯؐݩΛ։࢝ ύʔαͷελοΫ UPQ@TUNUT UFSNT
  48. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    312 Stack now 0 2 71 312 Reducing stack by rule 779 (line 6122): $1 = nterm term (1.5-1.5: ) -> $$ = nterm terms (1.5-1.5: ) ɾ͜͜·ͰͰ ɹ aOΛղੳͰ͖ͨ ɾύʔα͸͜ͷίʔυ͕ ɹ͜͜ͰऴΘΔͷ͔ɺ ɹ͜ͷޙ͞ΒʹߦҎ্ଓ͍͍ͯ͘ͷ͔Λ ɹࠓͷ࣌఺Ͱ͸·ͩ஌Βͳ͍ ύʔαͷελοΫ UPQ@TUNUT UFSNT ߏจղੳͷݱࡏ஍఺
  49. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    313 Stack now 0 2 71 313 Reading a token ͦΕΛ֬ೝ͢ΔͨΊɺύʔα͸ εΩϟφΛ࢖ͬͯ࣍ͷه߸ΛಡΈࠐΉ ࣍ͷه߸ΛಡΈࠐΉ
  50. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    313 Stack now 0 2 71 313 Reading a token Now at end of input. ͔͠͠ɺ͜ͷίʔυ͸͜ͷҰߦͰ ऴ͍ྃͯ͠ΔͷͰ࣍ͷߦ͸ଘࡏ͠ͳ͍ ࣍ͷೖྗ͸ͳ͍
  51. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    313 Stack now 0 2 71 313 Reading a token Now at end of input. ࣍ͷೖྗ͸ͳ͍ ύʔαͷελοΫ UPQ@TUNUT UFSNT ύʔα͸࣍ͷه߸͕ଘࡏ͠ͳ͍ͱ͖ ه߸UFSNTʹରͯ͠ͲΜͳߏจنଇΛ ద༻͢Δ΂͖͔൑அ͢Δ
  52. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    313 Stack now 0 2 71 313 Reading a token Now at end of input. Reducing stack by rule 769 (line 6094): $1 = nterm terms (1.5-1.5: ) -> $$ = nterm opt_terms (1.5-1.5: ) // parse.y: 6094 opt_terms : terms UFSNTΛPQU@UFSNTʹؐݩ ߏจنଇʹैͬͯؐݩΛ։࢝ ύʔαͷελοΫ UPQ@TUNUT PQU@UFSNT ελοΫʹ UPQ@TUNUT PQU@UFSNT͕ฒΜͩ
  53. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    311 Stack now 0 2 71 311 Reducing stack by rule 3 (line 1606): $1 = nterm top_stmts (1.0-1.5: NODE_OPCALL) $2 = nterm opt_terms (1.5-1.5: ) -> $$ = nterm top_compstmt (1.0-1.5: NODE_OPCALL) // parse.y: 1606 top_compstmt : top_stmts opt_terms UPQ@TUNUT PQU@UFSNTΛ UPQ@DPNQTUNUʹؐݩ ߏจنଇʹैͬͯؐݩΛ։࢝ ύʔαͷελοΫ UPQ@DPNQTUNUT
  54. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    70 Stack now 0 2 70 Reducing stack by rule 2 (line 1580): $1 = nterm $@1 (1.0-1.0: ) $2 = nterm top_compstmt (1.0-1.5: NODE_OPCALL) … cmdarg_stack(pop): 0 at line 13166 cond_stack(pop): 0 at line 13167 -> $$ = nterm program (1.0-1.5: ) // parse.y: 1580 program : top_compstmt UPQ@DPNQTUNUΛQSPHSBNʹؐݩ ύʔαͷελοΫ QSPHSBN ߏจنଇʹैͬͯؐݩΛ։࢝ 
  55. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    70 Stack now 0 2 70 Reducing stack by rule 2 (line 1580): $1 = nterm $@1 (1.0-1.0: ) $2 = nterm top_compstmt (1.0-1.5: NODE_OPCALL) … cmdarg_stack(pop): 0 at line 13166 cond_stack(pop): 0 at line 13167 -> $$ = nterm program (1.0-1.5: ) ύʔαͷελοΫ QSPHSBN ɾه߸QSPHSBN΁ ɹؐݩ͢Δ͜ͱ͕Ͱ͖ͨͨΊ ɹύʔα͸͜͜·ͰͰ ɹߏจղੳΛऴྃ͢Δ ߏจղੳͷݱࡏ஍఺
  56. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    1 Stack now 0 1 Now at end of input. Shifting token "end-of-input" (1.6-1.6: ) Entering state 3 Stack now 0 1 3 Stack now 0 1 3 Cleanup: popping token "end-of-input" (1.6-1.6: ) Cleanup: popping nterm program (1.0-1.5: ) ελοΫΛۭʹͯ͠ ਖ਼ৗʹೖྗ͕ऴΘͬͨ͜ͱΛ֬ೝ͠ɺ ॲཧΛऴྃ ޙॲཧͷͨΊɺ ೖྗͷऴྃΛදݱ͢Δه߸Λ ελοΫʹγϑτ
  57. ͨͷ͍͠3VCZͷߏจղੳπΞʔ $ ruby -ye ‘1 + 2’ … Entering state

    1 Stack now 0 1 Now at end of input. Shifting token "end-of-input" (1.6-1.6: ) Entering state 3 Stack now 0 1 3 Stack now 0 1 3 Cleanup: popping token "end-of-input" (1.6-1.6: ) Cleanup: popping nterm program (1.0-1.5: )  a໨త஍΁౸ண ߏจղੳͷݱࡏ஍఺