Slide 1

Slide 1 text

*NQMFNFOUJOHPQFSBUPS TUFQQJOHJOUPQBSTFZ .JTBLJ4IJPJ !TIJPJNN!DPF@ .BZ 3VCZ,BJHJ

Slide 2

Slide 2 text

"CPVUNF (JU)VC!TIJPJNN 5XJUUFS!DPF@ 8FCBQQMJDBUJPOEFWFMPQFSBU4.4$P -UE .FNCFSPG"TBLVTBSC'VLVPLBSC "NJOUFSFTUFEJOOFUXPSLJOHBOEQBSTJOH

Slide 3

Slide 3 text

)BWFZPVFWFSXJTIFE 3VCZIBEJODSFNFOUEFDSFNFOUPQFSBUPST i = 0 while i < 100 i++ puts "FizzBuzz" if i % 15 == 0 puts "Fizz" if i % 3 == 0 puts "Buzz" if i % 5 == 0 end 'PSFYBNQMF

Slide 4

Slide 4 text

8IZEPFTOU3VCZIBWFBOJODSFNFOUPQFSBUPS .PTUQFPQMFIBWFQSPCBCMZXPOEFSFEBCPVUUIJT BUMFBTUPODF

Slide 5

Slide 5 text

.BU[TUBUFTUIFSFBTPOGPSUIJT :PVDBOUEF fi OFPCKFDUPSJFOUFETFNBOUJDT GPSJODSFNFOUEFDSFNFOUPQFSBUJPOT SFGIUUQTCVHTSVCZMBOHPSHJTTVFT

Slide 6

Slide 6 text

4PXJUIUIFDVSSFOU.3* JGXFUSZUPFYFDVUFBTDSJQUMJLFAJA # test.rb i = 0 i++

Slide 7

Slide 7 text

ʜJUDBVTFTBTZOUBYFSSPSBUQBSTJOH # test.rb i = 0 i++ SVCZUFTUSC J J UFTUSCTZOUBYFSSPS VOFYQFDUFEFOEPGJOQVU 4ZOUBY&SSPS

Slide 8

Slide 8 text

8IZJTUIJTIBQQFOJOH 5IFQBSTJOHMPHTIPXTUIFSFBTPO

Slide 9

Slide 9 text

SVCZZFJJ 5IFQBSTJOHMPHTIPXTXIZ 1BSTJOHMPHTDBOCFFBTJMZPCUBJOFECZSVOOJOH UIFTDSJQUXJUIAZAPQUJPOUPUIFASVCZADPNNBOE TPMFUTHJWFJUBUSZXJUIBTDSJQUAJJA 3VOUIFTDSJQU JJ XJUIASVCZZADPNNBOE ˞5IJTJTSVOOJOHPO3VCZ

Slide 10

Slide 10 text

SVCZZFJJ BEE@EFMBZFE@UPLFO cc 4UBSUJOHQBSTF ʜ &OUFSJOHTUBUF 4UBDLOPX 3FEVDJOHTUBDLCZSVMF MJOF OUFSNMIT /0%&@-"4(/ UPLFO OUFSNMFY@DUYU OUFSNBSH@SIT /0%&@-*5 OUFSNBSH /0%&@-"4(/ ʜ 5IFQBSTJOHMPHTIPXTXIZ "DDPSEJOHUPJU JUXPSLT fi OFVQUPAJA AJATFFNTUPCFQBSTFEKVTU fi OF

Slide 11

Slide 11 text

SVCZZFJJ ʜ &OUFSJOHTUBUF 4UBDLOPX /FYUUPLFOJTUPLFO 4IJGUJOHUPLFO &OUFSJOHTUBUF 4UBDLOPX 3FEVDJOHTUBDLCZSVMF MJOF UPLFO OUFSNUFSN &OUFSJOHTUBUF 4UBDLOPX 3FEVDJOHTUBDLCZSVMF MJOF OUFSNUFSN OUFSNUFSNT 5IFQBSTJOHMPHTIPXTXIZ 5IFOUIF fi STUFYQSFTTJPOJTQSPQFSMZFOEFEXJUIAA 5IJTFYQSFTTJPOJTTVDDFTTGVMMZFOEFE AABMTPTFFNTUPCFQBSTFEDPSSFDUMZ

Slide 12

Slide 12 text

SVCZZFJJ ʜ &OUFSJOHTUBUF 4UBDLOPX 3FBEJOHBUPLFO QBSTFS@EJTQBUDI@TDBO@FWFOU cc MFY@TUBUF#&($.%"3(BUMJOF MFY@TUBUF$.%"3(&/%c-"#&-BUMJOF QBSTFS@EJTQBUDI@TDBO@FWFOU cc /FYUUPLFOJTUPLFOMPDBMWBSJBCMFPSNFUIPE J 4IJGUJOHUPLFOMPDBMWBSJBCMFPSNFUIPE J 5IFQBSTJOHMPHTIPXTXIZ *OUIFMBUFSQBSU UIFWBSJBCMFAJAJT fi STUSFBE 5IFWBSJBCMFAJAJTSFBE

Slide 13

Slide 13 text

SVCZZFJJ ʜ &OUFSJOHTUBUF 4UBDLOPX /FYUUPLFOJTUPLFO 4IJGUJOHUPLFO &OUFSJOHTUBUF 4UBDLOPX 3FBEJOHBUPLFO MFY@TUBUF#&(#&(BUMJOF QBSTFS@EJTQBUDI@TDBO@FWFOU cc /FYUUPLFOJTUPLFOVOBSZ 4IJGUJOHUPLFOVOBSZ 5IFQBSTJOHMPHTIPXTXIZ 5XPAATBSFUIFOSFBE5IJT TFDPOEAAJT EFUFSNJOFEBTUIFAAPGBVOBSZPQFSBUPS 'JSTUAA 4FDPOEAA *UTEFUFSNJOFEUIBUBVOBSZPQFSBUPS

Slide 14

Slide 14 text

SVCZZFJJ ʜ &OUFSJOHTUBUF 4UBDLOPX 3FBEJOHBUPLFO QBSTFS@EJTQBUDI@TDBO@FWFOU cc /PXBUFOEPGJOQVU FTZOUBYFSSPS VOFYQFDUFEFOEPGJOQVU JJ 5IFQBSTJOHMPHTIPXTXIZ .3*FYQFDUTTPNFOVNFSJDUPCFSFBEBGUFS BVOBSZPQFSBUPSJOUIJTDPOUFYU )PXFWFS JOSFBMJUZ UIFMJOFFOETBCSVQUMZIFSF 5IJTJTBOVOFYQFDUFEFOEPGJOQVU "TZOUBYFSSPSIBTPDDVSSFE 5IFMJOFFOEFEVOFYQFDUFEMZ

Slide 15

Slide 15 text

5IJTJTXIZXFHFUBTZOUBYFSSPS XIFOXFUSZUPVTFAAJOUIFDVSSFOU.3*

Slide 16

Slide 16 text

#VUUIFO JGXFSFBMMZ SFBMMZXBOUPQFSBUPS IPXEPXFEPʜ

Slide 17

Slide 17 text

5BLFPOUIFDIBMMFOHFPGBEEJOH OFXTZOUBYJO3VCZ

Slide 18

Slide 18 text

4P JOUIJTUBML *XPVMEMJLFUPTIBSFXJUIQSPHSBNNFSTMJLFNF XIPJTOPUBQBSTFSFYQFSU XIBUJUUBLFTUPBEEOFXTZOUBYUP.3* CBTFEPONZEPDVNFOUBSZ

Slide 19

Slide 19 text

*OBEEJUJPO .3*TQBSTFSIBTCFFOBDUJWFMZEFWFMPQFEBOE TFWFSBMUBMLTXJMMCFHJWFOBUUIJTZFBST3VCZ,BJHJ 5IJTUBMLXJMMCFCBTFEPOUIFTPVSDFDPEFPG .3*XBTSFMFBTFEUIJT.BSDI

Slide 20

Slide 20 text

5PVSJOH.3*`TQBSTFS

Slide 21

Slide 21 text

/PX -FUTUBLFBRVJDLMPPL BUIPX.3*QBSTFT3VCZTDSJQUT CFGPSFXFUSZUPBEEBOFXTZOUBYUP3VCZ

Slide 22

Slide 22 text

"3VCZTDSJQUDPOTJTUTPGBTFRVFODFPGUPLFOT UIBUBSFWBMJEBT3VCZTZOUBY 5PLFOTDPOTUJUVUFB3VCZTDSJQU 5IJTTDSJQUDPOTJTUTPG QVUT )FMMP puts "Hello"

Slide 23

Slide 23 text

.3*SFBETUIFTFUPLFOTPOFCZPOF GSPNMFGUUPSJHIU VTJOHBGVODUJPODBMMFETDBOOFS )PXTDBOOFSXPSLT SFBETUIFUPLFOJT puts "Hello" QVUT 4DBOOFS /PUF4DBOOFSJTBMTPDBMMFEMFYJDBMBOBMZ[FSPSMFYFS CVUKVTUDBMMJUTDBOOFSJOUIJTTMJEF

Slide 24

Slide 24 text

5IFTDBOOFSUIFOEFUFSNJOFTUIFLJOEPGUPLFOJUSFBET 5IFLJOEPGUPLFOJTDBMMFEBTZNCPM )PXTDBOOFSXPSLT EFUFSNJOFTUIFUPLFOQVUTJT U*%&/5*'*&3 puts "Hello" QVUT 5PLFO 4DBOOFS

Slide 25

Slide 25 text

5IFTDBOOFSTFUTUIFWBMVFPGUIFUPLFOUPBTZNCPM 5IJTWBMVFDBOCFBOJE BO3/PEF PSTPNFUIJOHFMTF )PXTDBOOFSXPSLT TFUTU*%&/5*'*&3UPBNFUIPEJE QVUT puts "Hello" U*%&/5*'*&3 QVUT 4ZNCPM 5PLFO /PUF4PNFUPLFOTIBWFOPWBMVF /PUF7BMVFJTDBMMFETFNBOUJDWBMVF CVUKVTUDBMMJUWBMVFJOUIJTTMJEF 4DBOOFS

Slide 26

Slide 26 text

'JOBMMZ UIFTDBOOFSSFUVSOTUIJTTZNCPMXJUIUIFWBMVF UPBGVODUJPODBMMFEBQBSTFS )PXTDBOOFSXPSLT puts "Hello" SFUVSOTUIFTZNCPMXJUIUIFWBMVFUPBQBSTFS U*%&/5*'*&3 QVUT QVUT 7BMVF 4ZNCPM 5PLFO 4DBOOFS

Slide 27

Slide 27 text

)PXQBSTFSXPSLT 5IFQBSTFSJTBGVODUJPOUIBUSFDFJWFTBTZNCPMGSPNUIF TDBOOFS DIFDLTTZOUBY DSFBUFT3/PEFT BOETPPO 5IFSFBSFNBOZHSBNNBSSVMFTEF fi OFEJOUIFQBSTFS QBSTFS U*%&/5*'*&3 QVUT 7BMVF 4ZNCPM 3/PEF 7$"-- QVUT SFDFJWF DSFBUF .BOZHSBNNBSSVMFT

Slide 28

Slide 28 text

)PXQBSTFSXPSLT 5IFTZOUBYSVMFTMPPLMJLFUIJT )FSFUIFSJHIUBOEMFGUIBOETJEFTBSFEF fi OFE // An example of a grammar rule operation : tIDENTIFIER | tCONSTANT | tFID ; 5IFMFGUIBOETJEF 5IFSJHIUIBOETJEF 5IFMFGUIBOETJEFEF fi OFTTZNCPMTUIBUNBLFTZNCPMTNPSFBCTUSBDU 5IFSJHIUIBOETJEFEF fi OFTUIFPSJHJOBMTZNCPMT

Slide 29

Slide 29 text

)PXQBSTFSXPSLT 4ZNCPMTBSFUVSOFEJOUPNPSFBCTUSBDUTZNCPM XIFOUIFZNBUDIUIFSJHIUIBOETJEFPGUIFTZOUBYSVMFT 5IJTDIBOHFJTDBMMFESFEVDUJPO // An example of a grammar rule operation : tIDENTIFIER | tCONSTANT | tFID ; .PSFBCTUSBDUTZNCPM 0SJHJOBMTZNCPMTBSFUVSOFEJOUP NPSFBCTUSBDUTZNCPM

Slide 30

Slide 30 text

)PXQBSTFSXPSLT 5IFWBMVFTFUGPSUIFTZNCPMCFGPSFSFEVDUJPOXJMMCF DBSSJFEPWFSUPUIFTZNCPMBGUFSSFEVDUJPO 6OMFTTBOBDUJPOUIBUXJMMCFEJTDVTTFEMBUFSJTEF fi OFE // An example of a grammar rule operation : tIDENTIFIER | tCONSTANT | tFID ; 5IFNFUIPEJEQVUT UIFWBMVFPGU*%&/5*'*&3 JT TFUUPPQFSBUJPOBGUFSSFEVDUJPO

Slide 31

Slide 31 text

)PXQBSTFSXPSLT "MUIPVHIPQUJPOBM XIBUUPCFQFSGPSNFEXIFOB SFEVDUJPOIBTPDDVSSFEDBOCFEF fi OFEJOBHSBNNBSSVMF 5IJTJTDBMMFEBTFNBOUJDBDUJPO /PUF4JNQMZDBMMJUBOBDUJPOJOUIJTTMJEF // An example of a grammar rule fcall : operation { $$ = NEW_FCALL($1, 0, &@$); nd_set_line($$, p->tokline); } 5IJTBDUJPOJTFYFDVUFE XIFOPQFSBUJPOJTSFEVDFEUPGDBMM

Slide 32

Slide 32 text

)PXBQBSTFSXPSLT 8JUIJOUIFBDUJPO FBDIWBMVFPGTZNCPMTDBOCFBDDFTTFE "WBSJBCMF5IFOVNCFSPGUIFPSEFSPGUIFTZNCPMTCFGPSFSFEVDUJPO TUPSFTFBDIWBMVF "WBSJBCMFNFBOTUIFTZNCPMTWBMVFBGUFSSFEVDUJPO // An example of a grammar rule fcall : operation { // $1 // $$ } 5IFWBMVFPGPQFSBUJPO5IFNFUIPEJEQVUT 5IFWBMVFPGGDBMM

Slide 33

Slide 33 text

)PXQBSTFSXPSLT *ONBOZDBTFT UIFBDUJPOEF fi OFTBQSPDFTTUPDSFBUFBO 3/PEFGSPNUIFWBMVFTFUJOUIFTZNCPMCFGPSFSFEVDUJPO 5IF3/PEFDSFBUFEJOUIJTXBZJTTFUUPUIFTZNCPMBGUFS SFEVDUJPO // An example of a grammar rule fcall : operation { $$ = NEW_FCALL($1, 0, &@$); nd_set_line($$, p->tokline); } $SFBUFBO3/PEFGSPN BOETFUJUUP

Slide 34

Slide 34 text

)PXQBSTFSXPSLT 4PNFUJNFTUXPPSNPSFTZNCPMTBSFSFEVDFEBUPODF *OTVDIDBTFT HSBNNBSSVMFTWFSJGZUIBUUIFTFRVFODFPG TZNCPMTJTDPSSFDU *GUIFTFRVFODFPGTZNCPMTJTJODPSSFDU UIFSFEVDUJPOXJMM OPUCFFYFDVUFE BOEBTZOUBYFSSPSXJMMPDDVS // An example of a grammar rule command : fcall command_args // ... 7FSJGZJOHGDBMMBOEDPNNBOE@BSHTBSF JOBSPXBOEPSEFSGSPNMFGUUPSJHIU

Slide 35

Slide 35 text

"MMPGUIFTZNCPMT HSBNNBSSVMFT BOEUIFTDBOOFSBSF EF fi OFEJOUIF fi MFQBSTFZJOUIF.3*TPVSDF SVCZQBSTFZ

Slide 36

Slide 36 text

/PX CBTFEPOUIJT -FUT fi HVSFPVUIPXUPJNQMFNFOUAAJO.3*

Slide 37

Slide 37 text

$BMMJOHBNFUIPEXJUIAA

Slide 38

Slide 38 text

5IF fi STUJEFBJT3FQMBDFAAXJUI*OUFHFSTVDD XIFOAAJTSFBEGSPNUIFTPVSDFDPEF i = 0 i++ # => Call Integer#succ and return 1 *OUFHFSTVDDSFUVSOTUIFWBMVFPGUIFSFTVMU XIJDIJTJODSFNFOUFECZUIFSFDFJWFS*OUFHFSPCKFDU i = 0 i.succ # => 1 $BMMJOHBNFUIPEXJUIAA AABDUTMJLFBOBMJBTGPS*OUFHFSTVDDJOUIJTJEFB

Slide 39

Slide 39 text

5IFSFBSFUXPOFDFTTBSZUIJOHTUPJNQMFNFOUUIJT $BMMJOHBNFUIPEXJUIAA

Slide 40

Slide 40 text

5IFSFBSFUXPOFDFTTBSZUIJOHTUPJNQMFNFOUUIJT "OFXTZNCPMGPS 4ZNCPM i++ $BMMJOHBNFUIPEXJUIAA 5PLFO %F fi OFBOFXTZNCPMGPSUIFUPLFO BOENBLFUIF TDBOOFSSFUVSOTUIFTZNCPMXIFOJUJTSFBEUPLFO

Slide 41

Slide 41 text

5IFSFBSFUXPOFDFTTBSZUIJOHTUPJNQMFNFOUUIJT "EEHSBNNBSSVMFTUPQBSTFBTDSJQUMJLFAJA BOEDBMM*OUFHFSTVDDJOTJEFPGUIFBDUJPO -FUTHFUUPJU ⬇︎ i = 0 i++ # Call Integer#succ internally $BMMJOHBNFUIPEXJUIAA %F fi OFBOFXTZNCPMGPSUIFUPLFO BOENBLFUIF TDBOOFSSFUVSOTUIFTZNCPMXIFOJUJTSFBEUPLFO

Slide 42

Slide 42 text

// ruby/parse.y // ... %token tIDENTIFIER "local variable or method" %token tFID "method" %token tGVAR "global variable" %token tIVAR "instance variable" %token tCONSTANT "constant" %token tCVAR "class variable" %token tLABEL "label" %token tINTEGER "integer literal" %token tFLOAT "float literal" %token tRATIONAL "rational literal" // ... %F fi OFBOFXTZNCPM *OQBSTFZ TZNCPMTBSFEF fi OFEMJLFUIJT

Slide 43

Slide 43 text

// ruby/parse.y // ... %token tINCOP "increment operator" %token tIDENTIFIER "local variable or method" %token tFID "method" %token tGVAR "global variable" %token tIVAR "instance variable" %token tCONSTANT "constant" %token tCVAR "class variable" %token tLABEL "label" %token tINTEGER "integer literal" %token tFLOAT "float literal" %token tRATIONAL "rational literal" // ... /PXMFU`TBEEBOFXTZNCPMU*/$01IFSF GPSUIFUPLFO %F fi OFBOFXTZNCPM %F fi OFBOFXTZNCPM

Slide 44

Slide 44 text

// ruby/parse.y static enum yytokentype parser_yylex(struct parser_params *p) { // ... .BLFUIFTDBOOFSSFUVSOU*/$01 5IFO NPEJGZUIFTDBOOFSUPSFUVSOU*/$01 XIFOJTSFBE *O.3* BGVODUJPOQBSTFS@ZZMFY EPFTNBOZPGXIBU BTDBOOFSEPFTGPSMFYJDBMBOBMZTJT

Slide 45

Slide 45 text

// ruby/parse.y static enum yytokentype parser_yylex(struct parser_params *p) { // ... switch (c = nextc(p)) { // ... .BLFUIFTDBOOFSSFUVSOU*/$01 5IFSFJTBIVHFTXJUDITUBUFNFOUJOJU 5IJTJTUPSFBEUIFDIBSBDUFSTJOUIFTDSJQUPOFBUB UJNFBOEEPTPNFUIJOHEFQFOEJOH POUIFDIBSBDUFSSFBE %PTPNFUIJOHEFQFOEJOHPOUIFDIBSBDUFSTSFBE

Slide 46

Slide 46 text

// ruby/parse.y static enum yytokentype parser_yylex(struct parser_params *p) { // ... switch (c = nextc(p)) { // ... case '+': // ... .BLFUIFTDBOOFSSFUVSOU*/$01 *OUIJTTXJUDITUBUFNFOU JUJTBMSFBEZEF fi OFE XIBUUPEPJGUIFDIBSBDUFSSFBEJT *GUIFDIBSBDUFSSFBEJT

Slide 47

Slide 47 text

// ruby/parse.y static enum yytokentype parser_yylex(struct parser_params *p) { // ... switch (c = nextc(p)) { // ... case '+': c = nextc(p); if (IS_AFTER_OPERATOR()) // ... if (c == '=') // ... .BLFUIFTDBOOFSSFUVSOU*/$01 *OJU BOBQQSPQSJBUFTZNCPMJTSFUVSOFEEFQFOEJOHPO UIFDIBSBDUFSCFGPSFBOEBGUFSUIF 3FBEUIFOFYUDIBSBDUFSPGUIF 3FUVSOTPNFUPLFOJGUIFQSFWJPVTDIBSBDUFSJT 3FUVSOTPNFUPLFOJGUIFOFYUDIBSBDUFSJT "OEPUIFS

Slide 48

Slide 48 text

// ruby/parse.y static enum yytokentype parser_yylex(struct parser_params *p) { // ... switch (c = nextc(p)) { // ... case '+': c = nextc(p); if (c == '+') .BLFUIFTDBOOFSSFUVSOU*/$01 -FUTBEEBOFXDPOEJUJPOIFSF *GUIFOFYUDIBSBDUFSBGUFSJTBHBJO 3FBEUIFOFYUDIBSBDUFSPGUIF *GUIFOFYUDIBSBDUFSJTBHBJO

Slide 49

Slide 49 text

// ruby/parse.y static enum yytokentype parser_yylex(struct parser_params *p) { // ... switch (c = nextc(p)) { // ... case '+': c = nextc(p); if (c == '+') { return tINCOP; } // ... .BLFUIFTDBOOFSSFUVSOU*/$01 SFUVSOU*/$01 UIFOFXTZNCPMEF fi OFEFBSMJFS 5IFTDBOOFSNPEJ fi DBUJPOJTOPXDPNQMFUF 3FBEUIFOFYUDIBSBDUFSPGUIF *GUIFOFYUDIBSBDUFSJTBHBJO 3FUVSOU*/$01

Slide 50

Slide 50 text

// ruby/parse.y method_call : fcall paren_args // ... | primary_value call_op operation2 opt_paren_args // ... | primary_value tCOLON2 operation2 paren_args // ... | primary_value tCOLON2 operation3 // ... | primary_value call_op paren_args // ... %F fi OFBOFXHSBNNBSSVMF /FYU MFU`TEF fi OFBOFXHSBNNBSSVMFUPUIFQBSTFS GPSUIFTZOUBYMJLFAJA QBSTFZEF fi OFTNBOZHSBNNBSSVMFTMJLFUIJTUP TVQQPSUWBSJPVTQBUUFSOTPGNFUIPEDBMMT

Slide 51

Slide 51 text

// ruby/parse.y method_call : fcall paren_args // ... | primary_value call_op operation2 opt_paren_args // ... | primary_value tCOLON2 operation2 paren_args // ... | primary_value tCOLON2 operation3 // ... | primary_value call_op paren_args // ... | ???? %F fi OFBOFXHSBNNBSSVMF *UTFFNTBHPPEJEFBUPEF fi OFBOFXHSBNNBSSVMF IFSFGPSBNFUIPEDBMM %F fi OFBOFXHSBNNBSSVMF

Slide 52

Slide 52 text

// ruby/parse.y method_call : // ... | primary_value tINCOP %F fi OFBOFXHSBNNBSSVMF )FSFJTUIFHSBNNBSSVMFUPCFBEEFE 5IFOFXHSBNNBSSVMFDIFDLTUIBUUIFTZNCPMT QSJNBSZ@WBMVFBOEU*/$01BSFJOBSPX %F fi OFBOFXHSBNNBSSVMF

Slide 53

Slide 53 text

// ruby/parse.y method_call : // ... | primary_value tINCOP QSJNBSZ@WBMVFJTUIFTZNCPMGPSUIFSFDFJWFSPGUIJT FYQSFTTJPO BOEU*/$01JTGPSAA 5IJTNBLFTFYQSFTTJPOTMJLFAJAWBMJEBTBTZOUBY 5IFTFTZNCPMTNFBOTʜ J # In a Ruby script i++ %F fi OFBOFXHSBNNBSSVMF

Slide 54

Slide 54 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { // ... %F fi OFBOFXBDUJPOUPDBMM*OUFHFSTVDD /FYU EF fi OFBOBDUJPO XIJDIDBMMT*OUFHFSTVDD XIFOSFEVDUJPOIBTPDDVSSFEGPSUIJTHSBNNBSSVMF

Slide 55

Slide 55 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { SET_LEX_STATE(EXPR_END); %F fi OFBOFXBDUJPOUPDBMM*OUFHFSTVDD 5IF fi STUXFOFFEUPEPJTUPUFMMUIFTDBOOFSUIBUUIJT FYQSFTTJPOFOETXIFOJTSFBE 5IJTJTOFFEFEUPQSFWFOUUIFTDBOOFSSFBETUIFOFYU UPLFOBGUFSBOEDBVTJOHBTZOUBYFSSPS5PEPTP DBMMUIFNBDSP4&5@-&9@45"5&XJUI&913@&/% 5FSNJOBUFUIJTFYQSFTTJPO /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF

Slide 56

Slide 56 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { SET_LEX_STATE(EXPR_END); ??? %F fi OFBOFXBDUJPOUPDBMM*OUFHFSTVDD /FYU MFUT fi OBMMZDBMM*OUFHFSTVDD )PXDBOXFEPUIBU /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF

Slide 57

Slide 57 text

// ruby/parse.y static NODE * new_qcall(struct parser_params* p, ID atype, NODE *recv, ID mid, NODE *args, const YYLTYPE *op_loc, const YYLTYPE *loc) OFX@RDBMM .3*QSPWJEFTOFX@RDBMM UPDSFBUFBO3/PEF UPDBMMBNFUIPE -FUTVTFUIJTGVODUJPOUPEPXIBUJTUIFTBNF BTUIFNFUIPEDBMMJOUIFBDUJPO

Slide 58

Slide 58 text

// ruby/parse.y static NODE * new_qcall(struct parser_params* p, ID atype, NODE *recv, ID mid, NODE *args, const YYLTYPE *op_loc, const YYLTYPE *loc) OFX@RDBMM 4PNFBSHVNFOUTBSFSFRVJSFEUPDBMMUIJTGVODUJPO "O3/PEFUIBUJTUIFSFDFJWFSPGUIFNFUIPE 5IFNFUIPEJE "O3/PEFUIBUJTUIFBSHVNFOUTPGUIFNFUIPE

Slide 59

Slide 59 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { SET_LEX_STATE(EXPR_END); new_qcall(p, $2, ???, ???, ???, &@2, &@$); $BMMOFX@RDBMM UPDBMM*OUFHFSTVDD 4PMFUTQSFQBSFUIFBSHVNFOUTUPDBMMOFX@RDBMM OFX@RDBMM OFFETBSHVNFOUT /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF

Slide 60

Slide 60 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { SET_LEX_STATE(EXPR_END); new_qcall(p, $2, ???, ???, ???, &@2, &@$); $BMMOFX@RDBMM UPDBMM*OUFHFSTVDD 'JSTU OFX@RDBMM OFFETBO3/PEFUIBUJTUIFSFDFJWFS BTUIFUIJSEBSHVNFOU "O3/PEFUIBUJTUIFSFDFJWFS /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF

Slide 61

Slide 61 text

// ruby/parse.y method_call : // ... | primary_value tINCOP $BMMOFX@RDBMM UPDBMM*OUFHFSTVDD "TNFOUJPOFEFBSMJFS QSJNBSZ@WBMVFJTUIFTZNCPM UIBUJTUIFSFDFJWFSPGUIJTFYQSFTTJPO 5IJTTZNCPMIBTBO3/PEFPGUIFSFDFJWFSBTJUTWBMVF QSJNBSZ@WBMVF ʹUIFSFDFJWFS IBT BO3/PEFPGUIFSFDFJWFSPCKFDUBTJUTWBMVF /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF

Slide 62

Slide 62 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { // ... $1; $BMMOFX@RDBMM UPDBMM*OUFHFSTVDD 3FNFNCFS XFDBOHFUUIFTZNCPMTWBMVFXJUI BOVNCFSPGUIFPSEFSPGUIFTZNCPMT JOBOBDUJPO 5IFWBMVFPGQSJNBSZ@WBMVF JF UIF3/PEFUIBUJT UIFSFDFJWFSJTTUPSFEGPS 5IFWBMVFPGQSJNBSZ@WBMVF /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF

Slide 63

Slide 63 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { SET_LEX_STATE(EXPR_END); new_qcall(p, $2, $1, ???, ???, &@2, &@$); $BMMOFX@RDBMM UPDBMM*OUFHFSTVDD 4PDBOCFQBTTFEBTJTBTUIFUIJSEBSHVNFOUPG OFX@RDBMM /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF 5IFWBMVFPGQSJNBSZ@WBMVF 5IF3/PEFUIBUJTUIFSFDFJWFS

Slide 64

Slide 64 text

$BMMOFX@RDBMM UPDBMM*OUFHFSTVDD // ruby/parse.y method_call : // ... | primary_value tINCOP { SET_LEX_STATE(EXPR_END); new_qcall(p, $2, $1, ???, ???, &@2, &@$); /FYU UIFGPVSUIBSHVNFOUPGOFX@RDBMM JT BNFUIPEJEPGUIFDBMMJOHNFUIPE /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF 5IFNFUIPEJE

Slide 65

Slide 65 text

$BMMOFX@RDBMM UPDBMM*OUFHFSTVDD // ruby/parse.y method_call : // ... | primary_value tINCOP { SET_LEX_STATE(EXPR_END); ID succ = rb_intern("succ"); new_qcall(p, $2, $1, succ, ???, &@2, &@$); (FUUIFNFUIPEJEPG*OUFHFSTVDDBOEQBTTJU UPOFX@RDBMM (FUUIFNFUIPEJEPG*OUFHFSTVDD /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF 1BTTUIFNFUIPEJE

Slide 66

Slide 66 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { SET_LEX_STATE(EXPR_END); ID succ = rb_intern("succ"); new_qcall(p, $2, $1, succ, ???, &@2, &@$); // ... } $BMMOFX@RDBMM UPDBMM*OUFHFSTVDD 5IF fi GUIBSHVNFOUJTBO3/PEFXIJDIJT UIFDBMMJOHNFUIPEBSHVNFOU /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF 5IFBSHVNFOUTPGUIFDBMMJOHNFUIPE

Slide 67

Slide 67 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { SET_LEX_STATE(EXPR_END); ID succ = rb_intern("succ"); new_qcall(p, $2, $1, succ, Qnull, &@2, &@$); // ... } $BMMOFX@RDBMM UPDBMM*OUFHFSTVDD )PXFWFS *OUFHFSTVDDOPBSHVNFOU -FUTQBTTOJMIFSF /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF 1BTTOJM

Slide 68

Slide 68 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { SET_LEX_STATE(EXPR_END); ID succ = rb_intern("succ"); $$ = new_qcall(p, $2, $1, succ, Qnull, &@2, &@$); $BMMOFX@RDBMM UPDBMM*OUFHFSTVDD 'JOBMMZ TFUUIF3/PEFPGUIFNFUIPEDBMM UIFSFUVSO WBMVFPGOFX@RDBMM UPUIFTZNCPMBGUFSSFEVDUJPO 5IJTDPNQMFUFTUIFWJUBMQBSUPGUIFJNQMFNFOUBUJPO "TTJHOUIFSFUVSOWBMVFUPUIFTZNCPMBGUFSSFEVDUJPO /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF

Slide 69

Slide 69 text

*TJUXPSLJOH NBLFSVO 3VOUIFDPNQJMFDPNNBOE # ruby/test.rb i = 0 i++ 8JUIUIJTJNQMFNFOUBUJPO XSJUFBTDSJQUDPOUBJOJOH AA UIFOSVOUIFDPNQJMFDPNNBOE

Slide 70

Slide 70 text

*UMPPLTXPSLJOH NBLFSVO HFOFSBUJOHQBSTFD DPNQJMJOHQBSTFD MJOLJOHNJOJSVCZ NJOJSVCZ*SVCZMJC*a *FYUDPNNPOa SBSNEBSXJOGBLF SVCZUFTUSC # ruby/test.rb i = 0 i++ *USFUVSOTBOJODSFNFOUFEWBMVFXJUIPVUBOZ TZOUBYFSSPS 5IFJNQMFNFOUBUJPOPGJTTVDDFTTGVM *USFUVSOTJODSFNFOUFEWBMVF

Slide 71

Slide 71 text

)PXFWFSʜ

Slide 72

Slide 72 text

*GPVOEBQSPCMFNXJUIUIJTJNQMFNFOUBUJPO i = 0 i++ # => It returns 1 i # => But i is still 0... *UJTUIBU*OUFHFSTVDDEPFTOPUBTTJHOJUTSFUVSOWBMVF UPUIFSFDFJWFSWBSJBCMF

Slide 73

Slide 73 text

0, MFU`TUIJOLPGBOPUIFSXBZ

Slide 74

Slide 74 text

$BMMJOHBNFUIPEXJUIAA SFWJTFE

Slide 75

Slide 75 text

*OUIFQSFWJPVTJNQMFNFOUBUJPO UIFSFJTBQSPCMFNUIBU*OUFHFSTVDDEJEOPUBTTJHO UIFSFUVSOWBMVFUPUIFSFDFJWFS i = 0 i++ # => Call Integer#succ, then i is still 0 4P JOTUFBEPG*OUFHFSTVDD MFUTDBMMTPNFPUIFS UIBUDBOBTTJHOUIFJODSFNFOUFEWBMVFUPUIFSFDFJWFS i = 0 i++ # => Call some other method, then i becomes 1 $BMMJOHBNFUIPEXJUIAA SFWJTFE NFUIPE

Slide 76

Slide 76 text

5IFSFBSFUXPOFDFTTBSZUIJOHTUPJNQMFNFOUUIJT $BMMJOHBNFUIPEXJUIAA SFWJTFE

Slide 77

Slide 77 text

5IFSFBSFUXPOFDFTTBSZUIJOHTUPJNQMFNFOUUIJT "EEBOFXNFUIPE*OUFHFS@@QMVTQMVT@@UPBTTJHO BOJODSFNFOUFEWBMVFUPUIFSFDFJWFS i = 0 i.__plusplus__ p i # => 1 $BMMJOHBNFUIPEXJUIAA SFWJTFE

Slide 78

Slide 78 text

5IFSFBSFUXPOFDFTTBSZUIJOHTUPJNQMFNFOUUIJT "EEBOFXNFUIPE*OUFHFS@@QMVTQMVT@@UPBTTJHO BOJODSFNFOUFEWBMVFUPUIFSFDFJWFS $BMM*OUFHFS@@QMVTQMVT@@JOTUFBEPG*OUFHFSTVDD JOUIFBDUJPO -FUTHFUUPJU ⬇︎ i = 0 i++ # Call i.__plusplus__ internally $BMMJOHBNFUIPEXJUIAA SFWJTFE

Slide 79

Slide 79 text

# ruby/numeric.rb class Integer def __plusplus__(name, b) b.local_variable_set(name, self.succ) end # ... %F fi OF*OUFHFS@@QMVTQMVT@@ ,FSOFMMPDBM@WBSJBCMF@TFUPSTPNFUIJOH %FUFSNJOFUIFUZQFPGUIFWBSJBCMFGSPNUIFWBSJBCMFOBNF 1BTTUIFBSHVNFOUT ɾWBSJBCMFOBNF ɾB#JOEJOHPCKFDU 'JSTU MFU`TEF fi OF*OUFHFS@@QMVTQMVT@@ *UJODSFNFOUTTFMGBOETFUTJUTWBMVFUPBWBSJBCMF JOJUTFOWJSPONFOUVTJOHUIFBSHVNFOUT

Slide 80

Slide 80 text

# ruby/numeric.rb class Integer def __plusplus__(name, b) b.local_variable_set(name, self.succ) end # ... %F fi OF*OUFHFS@@QMVTQMVT@@ *OUFHFS@@QMVTQMVT@@DBOCFDBMMFEMJLFUIJT JOB3VCZTDSJQU *UBTTJHOTBOJODSFNFOUFEWBMVFUPUIFSFDFJWFS # In a Ruby script i = 0 i.__plusplus__("i", binding) i # => 1 1BTTUIFBSHVNFOUT ɾWBSJBCMFOBNF ɾ,FSOFMCJOEJOH

Slide 81

Slide 81 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { SET_LEX_STATE(EXPR_END); ID succ = rb_intern("succ"); $$ = new_qcall(p, $2, $1, succ, Qnull, &@2, &@$); // ... } .PEJGZUIFBDUJPOUPDBMM*OUFHFS@@QMVTQMVT@@ /FYU MFU`TNPEJGZUIFBDUJPOUPDBMM *OUFHFS@@QMVTQMVT@@JOTUFBEPG*OUFHFSTVDD *OUFHFSTVDDJTDBMMFEJOUIFQSFWJPVTJNQMFNFOUBUJPO /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF

Slide 82

Slide 82 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { SET_LEX_STATE(EXPR_END); // ... $$ = new_qcall(p, $2, $1, ???, ???, &@3, &@$); .PEJGZUIFBDUJPOUPDBMM*OUFHFS@@QMVTQMVT@@ 'JSTU JOUIFTBNFXBZBTCFGPSF DBMMUIF4&5@-&9@45"5&NBDSPBOEQBTT BTUIFUIJSEBSHVNFOUUPOFX@RDBMM 5FSNJOBUFUIJTFYQSFTTJPO /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF 1BTTUIFWBMVFPGUIFSFDFJWFS

Slide 83

Slide 83 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { SET_LEX_STATE(EXPR_END); ID plusplus = rb_intern("__plusplus__"); $$ = new_qcall(p, $2, $1, plusplus, ???, &@3, &@$); .PEJGZUIFBDUJPOUPDBMM*OUFHFS@@QMVTQMVT@@ 1BTTUIFNFUIPEJEPG*OUFHFS@@QMVTQMVT@@ BTUIFGPVSUIBSHVNFOU /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF 1BTTUIFNFUIPEJE (FUUIFNFUIPEJEPG*OUFHFS@@QMVTQMVT@@

Slide 84

Slide 84 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { SET_LEX_STATE(EXPR_END); ID plusplus = rb_intern("__plusplus__"); $$ = new_qcall(p, $2, $1, plusplus, ???, &@3, &@$); .PEJGZUIFBDUJPOUPDBMM*OUFHFS@@QMVTQMVT@@ /PX *OUFHFS@@QMVTQMVT@@SFRVJSFTUXPBSHVNFOUT /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF # In a Ruby script i = 0 i.__plusplus__("i", binding)

Slide 85

Slide 85 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { SET_LEX_STATE(EXPR_END); ID plusplus = rb_intern("__plusplus__"); $$ = new_qcall(p, $2, $1, plusplus, ???, &@3, &@$); .PEJGZUIFBDUJPOUPDBMM*OUFHFS@@QMVTQMVT@@ 5IF fi STUJTBTUSJOHMJUFSBMPGUIFWBSJBCMFOBNF BOEUIFTFDPOEJTBNFUIPEDBMMPG,FSOFMCJOEJOH /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF # In a Ruby script i = 0 i.__plusplus__("i", binding) 1BTTUIFBSHVNFOUT ɾWBSJBCMFOBNF ɾ,FSOFMCJOEJOH

Slide 86

Slide 86 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { SET_LEX_STATE(EXPR_END); ID plusplus = rb_intern("__plusplus__"); $$ = new_qcall(p, $2, $1, plusplus, ???, &@3, &@$); .PEJGZUIFBDUJPOUPDBMM*OUFHFS@@QMVTQMVT@@ 5IFTFBSHVNFOUTNVTUCFQSFQBSFEBTBO3/PEF UIBUJTBOBSSBZBOEUIFOQBTTFEUPUIF fi GUIBSHVNFOU PGOFX@RDBMM 1BTTUIFBSHVNFOUTIFSF BTBO3/PEFUIBUJTBOBSSBZ /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF

Slide 87

Slide 87 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { // $1; // $1->u1.id; .PEJGZUIFBDUJPOUPDBMM*OUFHFS@@QMVTQMVT@@ 4P MFUTDSFBUFUIFTUSJOHMJUFSBMPGUIFSFDFJWFS`T WBSJBCMFOBNF 8FDBOHFUUIF3/PEFPGUIFSFDFJWFSGSPN 5IFWBSJBCMFJEJTTUPSFEJOBNFNCFSPGUIJT3/PEF /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF 5IFWBMVFPGQSJNBSZ@WBMVF 5IF3/PEFPGUIFSFDFJWFSPCKFDU 5IFWBSJBCMFJEPGUIFSFDFJWFS

Slide 88

Slide 88 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { // ... VALUE v = QUOTE_ID($1->u1.id); NODE *receiver = NEW_LIT(v, &NULL_LOC); .PEJGZUIFBDUJPOUPDBMM*OUFHFS@@QMVTQMVT@@ $SFBUFB7"-6&PG4USJOHGSPNUIFWBSJBCMFJE BOEDSFBUFBO3/PEFPGBMJUFSBMGSPNUIJTWBMVF *UDBOCFUIF fi STUBSHVNFOUPG*OUFHFS@@QMVTQMVT@@ "O3/PEFUIBUJTBTUSJOHMJUFSBMGSPNUIF7"-6& 7"-6&PGUIFTUSJOHGSPNUIFWBSJBCMFJE /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF

Slide 89

Slide 89 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { // ... VALUE v = QUOTE_ID($1->u1.id); NODE *receiver = NEW_LIT(v, &NULL_LOC); NODE *binding = NEW_VCALL(rb_intern("binding"), &@$); .PEJGZUIFBDUJPOUPDBMM*OUFHFS@@QMVTQMVT@@ /FYU DSFBUFBO3/PEFUIBUDBMMT,FSOFCJOEJOH BTUIFTFDPOEBSHVNFOUPG*OUFHFS@@QMVTQMVT@@ "O3/PEFUIBUDBMMT,FSOFMCJOEJOH /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF

Slide 90

Slide 90 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { // ... VALUE v = QUOTE_ID($1->u1.id); NODE *receiver = NEW_LIT(v, &NULL_LOC); NODE *binding = NEW_VCALL(rb_intern("binding"), &@$); NODE *args = NEW_LIST(receiver, &NULL_LOC); args = list_append(p, args, binding); .PEJGZUIFBDUJPOUPDBMM*OUFHFS@@QMVTQMVT@@ $SFBUFBO3/PEFUIBUJTBOBSSBZGSPNBO3/PEF PGUIFMJUFSBMBOEBO3/PEFPGUIFNFUIPEDBMM "O3/PEFUIBUJTBOBSSBZPGUIFBSHVNFOUT /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF

Slide 91

Slide 91 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { // ... VALUE v = QUOTE_ID($1->u1.id); NODE *receiver = NEW_LIT(v, &NULL_LOC); NODE *binding = NEW_VCALL(rb_intern("binding"), &@$); NODE *args = NEW_LIST(receiver, &NULL_LOC); args = list_append(p, args, binding); ID plusplus = rb_intern("__plusplus__"); $$ = new_qcall(p, $2, $1, plusplus, args, &@2, &@$); .PEJGZUIFBDUJPOUPDBMM*OUFHFS@@QMVTQMVT@@ 5IFOQBTTJUUPOFX@RDBMM BTJUT fi GUIBSHVNFOU 5IJTDPNQMFUFTUIFWJUBMQBSUPGUIFJNQMFNFOUBUJPO /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF

Slide 92

Slide 92 text

*TJUXPSLJOH 8JUIUIJTJNQMFNFOUBUJPO XSJUFBTDSJQUDPOUBJOJOH AABOEDIFDLJOHUIFWBMVFPGUIFSFDFJWFS UIFOFYFDVUFTUIFDPNQJMFDPNNBOE NBLFSVO 3VOUIFDPNQJMFDPNNBOE # ruby/test.rb i = 0 i++ p i

Slide 93

Slide 93 text

*UMPPLTXPSLJOH NBLFSVO HFOFSBUJOHQBSTFD DPNQJMJOHQBSTFD MJOLJOHNJOJSVCZ NJOJSVCZ*SVCZMJC*a *FYUDPNNPOa SBSNEBSXJOGBLF SVCZUFTUSC # ruby/test.rb i = 0 i++ p i JJTOPXJODSFNFOUFE 5IFOUIFDPNQJMBUJPOTVDDFFEFE BOEUIFWBSJBCMFXBT BTTJHOFEBOJODSFNFOUFEWBMVF 5IFJNQMFNFOUBUJPOPGJTTVDDFTTGVM

Slide 94

Slide 94 text

)PXFWFSʜ

Slide 95

Slide 95 text

*GPVOEBQSPCMFNJOUIJTJNQMFNFOUBUJPOBHBJO 1++ # => ??? *OUIJTJNQMFNFOUBUJPO AABDUTMJLFBOBMJBTGPS*OUFHFS@@QMVTQMVT@@ *UNBLFTVTXBOUUPDBMMAAFWFOJGUIFSFDFJWFSJTOPU BWBSJBCMFCVUBO*OUFHFSMJUFSBM )PXFWFS EPJOHTPXPVME

Slide 96

Slide 96 text

DBVTFBTFHNFOUBUJPOGBVMU

Slide 97

Slide 97 text

5IFSFDFJWFSJTOPUBMXBZTBWBSJBCMF // ruby/parse.y method_call : // ... | primary_value tINCOP { // ... SET_LEX_STATE(EXPR_END); VALUE v = QUOTE_ID($1->u1.id); 5IFSFBTPOJTUIBUUIJTJNQMFNFOUBUJPOOFFET UIFWBSJBCMFJEPGUIFSFDFJWFS 8FUSZUPHFUUIFWBSJBCMFJEVOEFSUIFBTTVNQUJPO UIBUUIF3/PEFPGUIFSFDFJWFSPCKFDUIBTJU &YQFDUJOHJTBO3/PEF UIBUIBTUIFWBSJBCMFJE /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF

Slide 98

Slide 98 text

// ruby/parse.y method_call : // ... | primary_value tINCOP { // ... SET_LEX_STATE(EXPR_END); VALUE v = QUOTE_ID($1->u1.id); )PXFWFS JGUIFSFDFJWFSJTBMJUFSBM UIJT3/PEFEPFTOU IBWFUIFWBSJBCMFJE *OUIBUDBTF BOVOJOUFOEFENFNPSZBSFBJTBDDFTTFE BOEBTFHNFOUBUJPOGBVMUPDDVST 6OMFTTUIFSFDFJWFSJTBWBSJBCMF XFDBO`UBDDFTTWBSJBCMFJE /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF 5IFSFDFJWFSJTOPUBMXBZTBWBSJBCMF

Slide 99

Slide 99 text

3VCZIBTOPWBSJBCMFPCKFDU *UNFBOTUIBUXFJNQMJDJUMZFYQFDUUIFSFDFJWFSUPCFBWBSJBCMF XIFOXFXPVMEMJLFUPVTFAA "OEUIJTTFFNTUPCFXIBU.BU[TBZTUIBUDBO`UEFGJOFPCKFDU PSJFOUFETFNBOUJDTGPSJODSFNFOUEFDSFNFOUPQFSBUPST 8IJMFAAJTGPSNBOJQVMBUJOHWBSJBCMFT UIFSFBSFOPWBSJBCMF PCKFDUTJO3VCZUIBUDBOCFNBOJQVMBUFECZNFUIPET

Slide 100

Slide 100 text

4P MFUTTUPQDBMMJOHTPNFNFUIPEXJUIAA BOEUIJOLPGBOPUIFSXBZ

Slide 101

Slide 101 text

5VSOAAJOUPAA

Slide 102

Slide 102 text

4PGBS XFIBWFUSJFEUPDPOTJEFSAABTBOBMJBTPG NFUIPEDBMM i++ )PXFWFS JOUIBUXBZ XFIBWFUPDPOTJEFSXIFUIFSUIF SFDFJWFSJTBWBSJBCMFPSBMJUFSBM BOEJUJTEJ ff i DVMUUPCF DPOTJTUFOUXJUIJO3VCZTTFNBOUJDT 5VSOAAJOUPAA "NFUIPEDBMM

Slide 103

Slide 103 text

-FU`TGPSHFUBCPVUQSFWJPVTJEFBTBOE UIJOLNPSFTJNQMZ 8IBUXFXBOUUPEPJTAA 5VSOAAJOUPAA

Slide 104

Slide 104 text

4P XIZOPUKVTUDSFBUFUIFTBNF"45XJUIAA $ ruby -e "pp RubyVM::AbstractSyntaxTree.parse('i+= 1')" (SCOPE@1:0-1:5 tbl: [:i] args: nil body: (LASGN@1:0-1:5 :i (CALL@1:0-1:5 (LVAR@1:0-1:1 :i) :+ (LIST@1:4-1:5 (LIT@1:4-1:5 1) nil)))) 5VSOAAJOUPAA 5IF"45PGAJA

Slide 105

Slide 105 text

*OQBSTFZ BHSBNNBSSVMFJTEF fi OFEUPQBSTFTDSJQUT TVDIBTAJA i++ i += 1 4PJGXFDBOEPFYBDUMZUIFTBNFUIJOHBTAJA XIFOUIFTDBOOFSSFBEBTDSJQUMJLFAJA XF`MMCFBCMFUPQBSTFJUBTAJA MJLFBTZOUBYTVHBS 5VSOAAJOUPAA ⬇︎

Slide 106

Slide 106 text

8IFOUIFTDBOOFSSFBETAA JUSFUVSOTUIFTZNCPM U01@"4(/GPSAABOEU*/5&(&3GPSAA i += 1 i++ 3FUVSOUIFTBNFTZNCPMTBTAA U01@"4(/ U01@"4(/ U*/5&(&3 3/PEF 4ZNCPM 7BMVF U*/5&(&3 3/PEF 4PJUXPVMECFOJDFJGUIFTDBOOFSDPVMESFUVSOCPUIU01@"4(/ BOEU*/5&(&3BUPODFXIFOJUSFBETAA CVUVOGPSUVOBUFMZ UIFTDBOOFSPOMZSFUVSOTPOFTZNCPMQFSSFBE

Slide 107

Slide 107 text

4PIPXBCPVUNPEJGZJOHUIFTDBOOFSMJLFUIJT i += 1 i++ 3FUVSOUIFTBNFTZNCPMTBTAA U01@"4(/ U01@"4(/ U*/5&(&3 3/PEF 4ZNCPM 7BMVF U*/5&(&3 3/PEF 'PSUIF fi STUAA SFUVSOUIFTZNCPMBOEWBMVFPGAA 'PSUIFTFDPOEAA SFUVSOUIFTZNCPMBOEWBMVFPGJOUFHFS

Slide 108

Slide 108 text

5IBOLGVMMZ .3*TDBOOFSIBTMPDBUJPOBMJOGPSNBUJPOJOUIF SFBEJOHMJOF5IFZDPVMECFIFMQGVMJOUIJTUJNF // ruby/parse.y /* Structure of Lexer Buffer: lex.pbeg lex.ptok lex.pcur lex.pend | | | | |------------+------------+------------| |<---------->| token */ 5PQQPTJUJPOPGUIFMJOFSFBE &OEQPTJUJPOPGUIFMJOFSFBE $VSSFOUQPTJUJPOPGDVSTPS 5IFTDBOOFSIBTMPDBUJPOBMJOGPSNBUJPO

Slide 109

Slide 109 text

)FSFJTIPXUIFTDBOOFSTIPVMEXPSLXJUIUIJTJEFB i++ 8IFOUIFSFJTBTDSJQUMJLFAJA UIFTDBOOFS fi STUSFBETJBTBWBSJBCMFAJABOE SFUVSOTUIFTZNCPMPGJU 5IFDVSTPSPGUIFTDBOOFSJTIFSF 8IBUUIFNPEJ fi FETDBOOFSEPFT 3FBEBOESFUVSOUIFTZNCPMPGUIFWBSJBCMFJ

Slide 110

Slide 110 text

i++ 5IFOUIFDVSTPSNPWFTPOFDIBSBDUFSBOEUIFTDBOOFS UIFOSFBETUIFOFYUDIBSBDUFS 4PGBS UIJTJTUIFDPOWFOUJPOBMCFIBWJPS 5IFDVSTPSJTIFSF 8IBUUIFNPEJ fi FETDBOOFSEPFT

Slide 111

Slide 111 text

i++ 5IFOFYUDIBSBDUFSJTUIF fi STU 8IFOUIFTDBOOFSSFBET EPOPUSFUVSOUIFTZNCPM JNNFEJBUFMZ CVUQFFLOFYUDIBSBDUFS LFFQJOHUIFDVSTPS QPTJUJPO 8IBUUIFNPEJ fi FETDBOOFSEPFT 5IFDVSTPSJTIFSF 5IJTJT

Slide 112

Slide 112 text

i++ *GUIFOFYUDIBSBDUFSJTBMTP UIFTDBOOFSDBOTFFUIBUUIJTJTQBSUPGAA 5IFDVSTPSJTIFSF 5IJTJTBMTP 5IJTJT 8IBUUIFNPEJ fi FETDBOOFSEPFT

Slide 113

Slide 113 text

i++ 5IFTDBOOFSTIPVMEOPXSFUVSOU01@"4(/ UIFTZNCPMGPSUIFUPLFOAA 3FUVSOTU01@"4(/ 5IFDVSTPSJTIFSF 8IBUUIFNPEJ fi FETDBOOFSEPFT

Slide 114

Slide 114 text

i++ 5IFDVSTPSNPWFTPOFDIBSBDUFS UIFOUIFTDBOOFSSFBET UIFMBTUDIBSBDUFS 5IFMBTUDIBSBDUFSJTUIFTFDPOE 5IFDVSTPSJTIFSF 5IJTJTBHBJO 8IBUUIFNPEJ fi FETDBOOFSEPFT

Slide 115

Slide 115 text

i++ 8IFOUIFTDBOOFSSFBETUIFTFDPOE QFFLBUUIFDIBSBDUFSJOUIFPOFQPTJUJPOCFGPSFJU LFFQJOHUIFDVSTPSQPTJUJPO 5IFDVSTPSJTIFSF 5IJTJTBHBJO 8IBUUIFNPEJ fi FETDBOOFSEPFT

Slide 116

Slide 116 text

i++ *GUIFQSFWJPVTDIBSBDUFSJTBMTP UIFTDBOOFSDBOTFFUIBUUIJTJTQBSUPGAABHBJO 5IJTJTBHBJO 5IFDVSTPSJTIFSF 5IJTJTBMTP 8IBUUIFNPEJ fi FETDBOOFSEPFT

Slide 117

Slide 117 text

i++ 5IFOUIFTDBOOFSSFUVSOTU*/5&(&3 UIFTZNCPMPGBOJOUFHFS XJUIUIFWBMVFJOUFHFSTFU )PXDBOXFEP 3FUVSOUIFJOUFHFS 8IBUUIFNPEJ fi FETDBOOFSEPFT

Slide 118

Slide 118 text

// ruby/parse.y static eunm yytokentype set_integer_literal(struct parser_params *p, VALUE v, int suffix) TFU@JOUFHFS@MJUFSBM .3*QSPWJEFTTFU@JOUFHFS@MJUFSBM *UDSFBUFTBO3/PEFUIBUJTBOJOUFHFSMJUFSBMBOE SFUVSOTUIFTZNCPMU*/5&(&3TFUXJUIJU

Slide 119

Slide 119 text

i++ $BMMJOHUIJTGVODUJPOXIFOUIFTFDPOEJTSFBEXJMM SFUVSOBTZNCPMXJUIBWBMVFPGJOUFHFS 5IJTXJMMDBVTFUIFTDBOOFSUPCFIBWFUIFTBNF BTXIFOJUSFBETAA-FUTHFUUPJU $BMMTFU@JOUFHFS@MJUFSBM $BMMTFU@JOUFHFS@MJUFSBM UPSFUVSOU*/5&(&3

Slide 120

Slide 120 text

// ruby/parse.y static enum yytokentype parser_yylex(struct parser_params *p) { // ... switch (c = nextc(p)) { // ... case '+': // ... .BLFUIFTDBOOFSSFUVSOU01@"4(/GPSUIF fi STU "TXFTBXFBSMJFS QBSTFS@ZZMFY UIBUFYFDVUFTMFYJDBM BOBMZTJTIBTBTXJUDITUBUFNFOUUPCFEF fi OFEBT XIBUUPEPJGUIFSFBEDIBSBDUFSJT -FUTNPEJGZJU *GUIFDIBSBDUFSSFBEJT i++

Slide 121

Slide 121 text

// ruby/parse.y static enum yytokentype parser_yylex(struct parser_params *p) { // ... switch (c = nextc(p)) { // ... case '+': peekc(p); .BLFUIFTDBOOFSSFUVSOU01@"4(/GPSUIF fi STU 'JSTU XIFOUIFTDBOOFSSFBET LFFQUIFDVSTPS QPTJUJPOBOEQFFLUIFOFYUDIBSBDUFSBGUFSJU 5IFSFJTBGVODUJPOQFFLD GPSJUJO.3* 1FFLUIFOFYUDIBSBDUFSPG i++

Slide 122

Slide 122 text

// ruby/parse.y static enum yytokentype parser_yylex(struct parser_params *p) { // ... switch (c = nextc(p)) { // ... case '+': if (peekc(p) == '+') { set_yylval_id('+'); SET_LEX_STATE(EXPR_BEG); return tOP_ASGN; } .BLFUIFTDBOOFSSFUVSOU01@"4(/GPSUIF fi STU *GUIFOFYUDIBSBDUFSJT SFUVSOUIFTZNCPM U01@"4(/XIJDINFBOTAA 3FUVSOU01@"4(/ *GUIFOFYUDIBSBDUFSJT i++ U01@"4(/

Slide 123

Slide 123 text

// ruby/parse.y static enum yytokentype parser_yylex(struct parser_params *p) { // ... switch (c = nextc(p)) { // ... case '+': if (peekc(p) == '+') { set_yylval_id('+'); SET_LEX_STATE(EXPR_BEG); return tOP_ASGN; } .BLFUIFTDBOOFSSFUVSOU01@"4(/GPSUIF fi STU 5IFOUIFDVSTPSNPWFTBIFBEUPPOFDIBSBDUFSBOE QBSTFS@ZZMFY BUUFNQUTUPSFBEUIFOFYUDIBSBDUFS 5IFDVSTPSNPWFTBIFBE i++

Slide 124

Slide 124 text

// ruby/parse.y static enum yytokentype parser_yylex(struct parser_params *p) { // ... switch (c = nextc(p)) { // ... case '+': if (peekc(p) == '+') { // ... } peekc_n(p, -2) .BLFUIFTDBOOFSSFUVSOU*/5&(&3GPSUIFTFDPOE /FYU XIFOUIFTDBOOFSSFBETUIFTFDPOE LFFQUIF DVSTPSQPTJUJPOBOEDIFDLUIFDIBSBDUFSPOFCFGPSFJU QFFLD@O QSPWJEFECZ.3*DBOCFVTFEGPSUIJT 1FFLUIFQSFWJPVTDIBSBDUFSPG *GUIFDIBSBDUFSSFBEJT i++

Slide 125

Slide 125 text

// ruby/parse.y static enum yytokentype parser_yylex(struct parser_params *p) { // ... switch (c = nextc(p)) { // ... case '+': if (peekc(p) == '+') { // ... } if (peekc_n(p, -2) == '+') { VALUE i = rb_cstr_to_inum("1", 16, FALSE); .BLFUIFTDBOOFSSFUVSOU*/5&(&3GPSUIFTFDPOE *GUIFQSFWJPVTDIBSBDUFSXBTBMTPB UIFODSFBUFB7"-6&UIBUJTBOJOUFHFS $SFBUFB7"-6&UIBUJTBJOUFHFS *GUIFQSFWJPVTDIBSBDUFSJT

Slide 126

Slide 126 text

// ruby/parse.y static enum yytokentype parser_yylex(struct parser_params *p) { // ... switch (c = nextc(p)) { // ... case '+': if (peekc(p) == '+') { set_yylval_id('+'); SET_LEX_STATE(EXPR_BEG); return tOP_ASGN; } if (peekc_n(p, -2) == '+') { VALUE i = rb_cstr_to_inum("1", 16, FALSE); return set_integer_literal(p, i, 0); } // ... .BLFUIFTDBOOFSSFUVSOU*/5&(&3GPSUIFTFDPOE 3FUVSOUIFSFTVMUPGTFU@JOUFHFS@MJUFSBM i++ U*/5&(&3 1BTTJUBTBOBSHVNFOUUPDBMMTFU@JOUFHFS@MJUFSBM BOESFUVSOUIFSFTVMUGSPNUIFTDBOOFS

Slide 127

Slide 127 text

// ruby/parse.y static enum yytokentype parser_yylex(struct parser_params *p) { // ... switch (c = nextc(p)) { // ... case '+': if (peekc(p) == '+') { set_yylval_id('+'); SET_LEX_STATE(EXPR_BEG); return tOP_ASGN; } if (peekc_n(p, -2) == '+') { VALUE i = rb_cstr_to_inum("1", 16, FALSE); return set_integer_literal(p, i, 0); } // ... .BLFUIFTDBOOFSSFUVSOU*/5&(&3GPSUIFTFDPOE 5IJTTIPVMESFUVSOUIFTBNFSFTVMUBTJGAA IBECFFOSFBE"OEUIJTJNQMFNFOUBUJPOJTDPNQMFUF U01@"4(/ U*/5&(&3 i++

Slide 128

Slide 128 text

*TJUXPSLJOH NBLFSVO # ruby/test.rb i = 0 i++ p i 3VOUIFDPNQJMFDPNNBOE 8JUIUIJTJNQMFNFOUBUJPO XSJUFBTDSJQUDPOUBJOJOH AABOEDIFDLJOHUIFWBMVFPGUIFSFDFJWFS UIFOFYFDVUFTUIFDPNQJMFDPNNBOE

Slide 129

Slide 129 text

*UMPPLTXPSLJOH NBLFSVO HFOFSBUJOHQBSTFD DPNQJMJOHQBSTFD MJOLJOHNJOJSVCZ NJOJSVCZ*SVCZMJC*a *FYUDPNNPOa SBSNEBSXJOGBLF SVCZUFTUSC # ruby/test.rb i = 0 i++ p i JJTOPXJODSFNFOUFE 5IFOUIFDPNQJMBUJPOTVDDFFEFE BOEUIFWBSJBCMFXBT BTTJHOFEBOJODSFNFOUFEWBMVF

Slide 130

Slide 130 text

NBLFSVO NJOJSVCZ*SVCZMJC*a *FYUDPNNPOa SBSNEBSXJOGBLF SVCZUFTUSCSVCZUFTUSC TZOUBYFSSPS VOFYQFDUFEPQFSBUPSBTTJHONFOU FYQFDUJOHFOEPGJOQVU 4ZOUBY&SSPS NBLF&SSPS *UMPPLTXPSLJOH # ruby/test.rb 1++ "OTZOUBYFSSPSIBTPDDVSSFE $BMMJOHAAXJUIBOJOUFHFSMJUFSBMEPFTOPUDBVTF BTFHNFOUBUJPOGBVMU CVUBTZOUBYFSSPSBTTBNFBT AA5IJTJTUIFJOUFOEFECFIBWJPS 5IFJNQMFNFOUBUJPOPGJTTVDDFTTGVM

Slide 131

Slide 131 text

)PXFWFSʜ

Slide 132

Slide 132 text

*GPVOEBQSPCMFNJOUIJTJNQMFNFOUBUJPOBHBJO i = 0 i++ * 2 # => 2 p i # => ? 8IFOFYFDVUJOHBTDSJQUMJLFUIJT XIBUXPVMECFBOBQQSPQSJBUFWBMVFGPSUIFWBSJBCMFAJA

Slide 133

Slide 133 text

5IJTJTBLJOEPGMBOHVBHFEFTJHONBUUFS BOEUIFSFBSF NBOZXBZTUPUIJOLBCPVUJU1FSTPOBMMZ *UIJOLJUJT BQQSPQSJBUFGPSUIFWBSJBCMFAJAUPCFBTTJHOFE i = 0 i++ * 2 # => Expect: (i += 1) * 2 p i # => Expect: 1 *FYQFDUUIFWBSJBCMFAJAUPCFBTTJHOFE fi STUBOE NVMUJQMJFECZOFYU

Slide 134

Slide 134 text

)PXFWFS UIJTAAJTFRVJWBMFOUUPAA5IFSFGPSF UIFSFTVMUJTBTTJHOFEUPUIFWBSJBCMFAJABGUFSUIF NVMUJQMJDBUJPOPGJTDPNQVUFE fi STUCZQSFDFEFODF i = 0 i++ * 2 # => Actual: i += (1 * 2) p i # => Actual: 2 5IFOUIFWBSJBCMFAJAJTBTTJHOFE *GFFMUIJTJTBOBUVSBMCFIBWJPSGPSAA CVUBCJU TUSBOHFGPSAA

Slide 135

Slide 135 text

4JODFUIFQSFDFEFODFPGPQFSBUPSTJTEF fi OFEJOQBSTFZ JUJTQPTTJCMFUPBWPJEUIJTQSPCMFNCZNBLJOHUIF QSFDFEFODFPGAAIJHIFSUIBOAA // ruby/parse.y // ... %right '=' tOP_ASGN %left modifier_rescue %right '?' ':' // ... %left '&' %left tLSHFT tRSHFT %left '+' '-' %left '*' '/' ‘%' // ... 5IFQSFDFEFODF )JHIFS -PXFS

Slide 136

Slide 136 text

)PXFWFS UIFQSPCMFNUIJTUJNFJTPOMZGPSUIFDBTFPG SFBEJOHAA*EPOUXBOUUPDIBOHFUIFQSFDFEFODFGPS UIFDBTFPGSFBEJOHAAVTVBMMZ x = 0 x += 1 ** 2 p x # => Intend: 2 (Keeping current behavior) y = 0 y++ ** 2 p y # => Intend: 1 (Changing current behavior)

Slide 137

Slide 137 text

"MUFSOBUJWFMZ JUNJHIUCFQPTTJCMFUPDSFBUFBTZOUBYUSFF UIBUXSBQTUIFMFGUIBOETJEFBOEAAJOA AUPDPOUSPM UIFQSFDFEFODFPGFYQSFTTJPOT i = 0 i++ * 2 # => i += (1 * 2) )PXFWFS UIJTXPVMENBLFUIFCFIBWJPSPGUIFTDBOOFS UPPDPNQMJDBUFE

Slide 138

Slide 138 text

0, MFU`TUIJOLPGBOPUIFSXBZ

Slide 139

Slide 139 text

5VSOAAJOUPAA 3FWJTFE

Slide 140

Slide 140 text

*OUIFQSFWJPVTJNQMFNFOUBUJPO XFUSJFEUPNBLFUIF TBNF"45XJUIAACZUIFTDBOOFS i = 0 i++ * 2 # => i += (1 * 2) p i # => 2 #VUXFGPVOEUIBUJGAAJTGPMMPXFECZBOFYQSFTTJPO XFDBOOPUIBOEMFJU 5VSOAAJOUPAA 3FWJTFE

Slide 141

Slide 141 text

5PBWPJEUIJT IPXBCPVUDPOTJEFSJOHUIFTFRVFODFPG UIFMFGUIBOETJEFPGUIFFYQSFTTJPOBOEBTBTJOHMF TZOUBYBOEEPJOHUIFTBNFUIJOHUPAACZUIFQBSTFS i++ 1BSTFBOENBLFBTBNF"45BT 5VSOAAJOUPAA 3FWJTFE

Slide 142

Slide 142 text

5IFSFBSFUXPOFDFTTBSZUIJOHTUPJNQMFNFOUUIJT 5VSOAAJOUPAA 3FWJTFE

Slide 143

Slide 143 text

5IFSFBSFUXPOFDFTTBSZUIJOHTUPJNQMFNFOUUIJT "EETZNCPMTBOEHSBNNBSSVMFTUPBMMPX TZOUBYMJLFAJA 5VSOAAJOUPAA 3FWJTFE

Slide 144

Slide 144 text

5IFSFBSFUXPOFDFTTBSZUIJOHTUPJNQMFNFOUUIJT "EETZNCPMTBOEHSBNNBSSVMFTUPBMMPX TZOUBYMJLFAJA %F fi OFBOBDUJPOUIBUEPFTUIFTBNFUIJOH XIFOBTZOUBYMJLFAJAJTQBSTFE BTXIFOBTZOUBYMJLFAJAJTEPOF 5VSOAAJOUPAA 3FWJTFE -FUTHFUUPJU i = 0 i++ # Do the same thing as `i+=1` internally

Slide 145

Slide 145 text

// ruby/parse.y %token tCOLON2 RUBY_TOKEN(COLON2) "::" %token tCOLON3 ":: at EXPR_BEG" %token tOP_ASGN "operator-assignment" /* +=, -= etc. */ %token tINCOP "increment-operator" %token tASSOC "=>" %token tLPAREN "(" %token tLPAREN_ARG "( arg" %token tRPAREN ")" %token tLBRACK "[" %token tLBRACE “{" %token tSTAR "*" %token tDSTAR "**arg" %token tAMPER "&" // ... %F fi OFTZNCPMU*/$01 'JSTU EF fi OFU*/$01BTUIFTZNCPM GPSUIFUPLFO %F fi OFBOFXTZNCPMGPS

Slide 146

Slide 146 text

// ruby/parse.y static enum yytokentype parser_yylex(struct parser_params *p) { // ... switch (c = nextc(p)) { // ... case '+': c = nextc(p); // ... if (c == '+') .BLFUIFTDBOOFSSFUVSOU*/$01 5IFONPEJGZQBSTFS@ZZMFY *GJTSFBEUXJDFJOBSPX *GUIFOFYUDIBSBDUFSJTBMTP 3FBEOFYUDIBSBDUFSPGUIF 8IFOUIFDIBSBDUFSSFBEJT

Slide 147

Slide 147 text

// ruby/parse.y static enum yytokentype parser_yylex(struct parser_params *p) { // ... switch (c = nextc(p)) { // ... case '+': c = nextc(p); // ... if (c == '+') { SET_LEX_STATE(EXPR_BEG); return tINCOP; } // ... .BLFUIFTDBOOFSSFUVSOU*/$01 SFUVSOU*/$01 5IFTDBOOFSNPEJ fi DBUJPOJTOPXDPNQMFUF 3FUVSOU*/$01

Slide 148

Slide 148 text

// ruby/parse.y arg : lhs '=' lex_ctxt arg_rhs // ... | var_lhs tOP_ASGN lex_ctxt arg_rhs // ... | ???? %F fi OFBOFXHSBNNBSSVMF /FYU EF fi OFBOFXHSBNNBSSVMFGPSAA 4JODFBHSBNNBSSVMFGPSBTDSJQUTVDIBTAJAJT EF fi OFEJOQBSTFZ MFUTEF fi OFUIFOFXPOFOFBSIFSF %F fi OFUIFOFXHSBNNBSSVMF "HSBNNBSSVMFGPS 3VCZTDSJQUTMJLFAJA

Slide 149

Slide 149 text

// ruby/parse.y arg : // ... | var_lhs lex_ctxt tINCOP %F fi OFBOFXHSBNNBSSVMF )FSFJTUIFHSBNNBSSVMFUPCFBEEFE 5IFOFXHSBNNBSSVMFDIFDLTUIBUUIFTZNCPMT WBS@MIT MFY@DUYU BOEU*/$01BSFJOBSPX %F fi OFBOFXHSBNNBSSVMF

Slide 150

Slide 150 text

// ruby/parse.y arg : // ... | var_lhs lex_ctxt tINCOP 5IFNJEEMFPOF MFY@DUYU JTOPUTPSFMFWBOUUIJTUJNF TPTLJQJU WBS@MITJTUIFMFGUTJEFPGAA BOEU*/$01JTAA MFY@DUYUJTOPUTPSFMFWBOU TPXFTLJQJU 5IJTNBLFTFYQSFTTJPOTMJLFAJAWBMJEBTBTZOUBY 5IFTFTZNCPMTNFBOTʜ J # In a Ruby script i++ OPOF %F fi OFBOFXHSBNNBSSVMF

Slide 151

Slide 151 text

// ruby/parse.y arg : // ... | var_lhs lex_ctxt tINCOP { // ... %F fi OFBOFXBDUJPOUPEPUIFTBNFUIJOHAAEPFT -FUTOPXEF fi OFUIFBDUJPOUPCFFYFDVUFEVQPO SFEVDJOHUIJTHSBNNBSSVMF

Slide 152

Slide 152 text

// ruby/parse.y arg : // ... | var_lhs lex_ctxt tINCOP { SET_LEX_STATE(EXPR_END); 'JSTU DBMM4&5@-&9@45"5&XJUI&913@&/%UPUFMM UIFTDBOOFSUPFOEUIJTFYQSFTTJPO /PUF5IFEF fi OJUJPOTPGBDUJPOTGPS3JQQFSBSFTLJQQFEJOUIJTTMJEF 5FSNJOBUFUIJTFYQSFTTJPO %F fi OFBOFXBDUJPOUPEPUIFTBNFUIJOHAAEPFT

Slide 153

Slide 153 text

// ruby/parse.y arg : // ... | var_lhs lex_ctxt tINCOP { SET_LEX_STATE(EXPR_END); ??? /FYU MFUTEPUIFTBNFUIJOHBTAA )PXDBOXFEPUIBU /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF %F fi OFBOFXBDUJPOUPEPUIFTBNFUIJOHAAEPFT

Slide 154

Slide 154 text

// ruby/parse.y static NODE * new_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, struct lex_context ctxt, const YYLTYPE *loc); OFX@PQ@BTTJHO .3*QSPWJEFTOFX@PQ@BTTJHO UPDSFBUFBO3/PEF UIBUJTBOFYQSFTTJPOXJUIAAPSAA -FUTVTFUIJTGVODUJPOUPEPXIBUJTUIFTBNF BTAA

Slide 155

Slide 155 text

// ruby/parse.y static NODE * new_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, struct lex_context ctxt, const YYLTYPE *loc); OFX@PQ@BTTJHO 4PNFBSHVNFOUTBSFSFRVJSFEUPDBMMUIJTGVODUJPO "O3/PEFUIBUJTUIFWBMVFPOUIFMFGUTJEFPGUIFFYQSFTTJPO "OPQFSBUPS AAPSAA "O3/PEFUIBUJTUIFWBMVFPOUIFSJHIUTJEFPGUIFFYQSFTTJPO

Slide 156

Slide 156 text

// ruby/parse.y arg : // ... | var_lhs lex_ctxt tINCOP { SET_LEX_STATE(EXPR_END); // ... new_op_assign(p, ???, ???, ???, $2, &@$); } $BMMOFX@PQ@BTTJHO /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF 4PMFUTQSFQBSFUIFBSHVNFOUT UPDBMMOFX@PQ@BTTJHO OFX@PQ@BTTJHO SFRVJSFTBSHVNFOUT

Slide 157

Slide 157 text

// ruby/parse.y arg : // ... | var_lhs lex_ctxt tINCOP { SET_LEX_STATE(EXPR_END); // ... new_op_assign(p, $1, '+', ???, $2, &@$); } 1BTTUIFMFGUIBOETJEFPGAABTUIFTFDPOE BSHVNFOUBOEAABTUIFUIJSEBSHVNFOU -FGUIBOETJEF /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF $BMMOFX@PQ@BTTJHO

Slide 158

Slide 158 text

// ruby/parse.y arg : // ... | var_lhs lex_ctxt tINCOP { SET_LEX_STATE(EXPR_END); // ... new_op_assign(p, $1, '+', ???, $2, &@$); } 5IFGPVSUIBSHVNFOUJTUIFWBMVFPGUIFSJHIUTJEFPG AA*OUIFDBTFPGAA UIFSJHIUTJEFJTBMXBZTBO JOUFHFS TPXFOFFEUPDSFBUFBWBMVFPGUIJT 3FRVJSFTBOJOUFHFSWBMVFAA /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF $BMMOFX@PQ@BTTJHO

Slide 159

Slide 159 text

// ruby/parse.y arg : // ... | var_lhs lex_ctxt tINCOP { SET_LEX_STATE(EXPR_END); // ... new_op_assign(p, $1, '+', ???, $2, &@$); } TFU@JOUFHFS@MJUFSBM VTFEJOPOFQSFWJPVT JNQMFNFOUBUJPODBOOPUCFVTFEIFSF BTJUJTBGVODUJPOUPTFUBWBMVFUPBTZNCPM 8FOFFEUPDSFBUFBO3/PEFUIBUJTBOJOUFHFS /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF $BMMOFX@PQ@BTTJHO

Slide 160

Slide 160 text

// ruby/parse.y arg : // ... | var_lhs lex_ctxt tINCOP { SET_LEX_STATE(EXPR_END); VALUE v = rb_cstr_to_inum("1", 16, FALSE); NODE *one = NEW_LIT(v, &NULL_LOC); 5PEPUIJT DSFBUFB7"-6&PGJOUFHFS BOEUIFO DSFBUFBO3/PEFUIBUJTMJUFSBMGSPNUIJT7"-6& "7"-6&PGBOJOUFHFS "O3/PFPGBMJUFSBM /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF $BMMOFX@PQ@BTTJHO

Slide 161

Slide 161 text

// ruby/parse.y arg : // ... | var_lhs lex_ctxt tINCOP { SET_LEX_STATE(EXPR_END); VALUE v = rb_cstr_to_inum("1", 16, FALSE); NODE *one = NEW_LIT(v, &NULL_LOC); RB_OBJ_WRITTEN(p->ast, Qnil, x); new_op_assign(p, $1, '+', one, $2, &@$); } 5IFOQBTTJUUPUIFGPVSUIBSHVNFOUPG OFX@PQ@BTTJHO 1BTTUIF3/PEFUIBUJTBJOUFHFSMJUFSBM /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF $BMMOFX@PQ@BTTJHO

Slide 162

Slide 162 text

// ruby/parse.y arg : // ... | var_lhs lex_ctxt tINCOP { SET_LEX_STATE(EXPR_END); VALUE v = rb_cstr_to_inum("1", 16, FALSE); NODE *one = NEW_LIT(v, &NULL_LOC); RB_OBJ_WRITTEN(p->ast, Qnil, x); $$ = new_op_assign(p, $1, '+', one, $2, &@$); } 'JOBMMZ TFUUIF3/PEF UIFSFUVSOWBMVFPG OFX@PQ@BTTJHO UPUIFTZNCPMBGUFSSFEVDUJPO /PUFUIFEF fi OJUJPOPGBDUJPOTJTTMJHIUMZTJNQMJ fi FEJOUIJTTMJEF "TTJHOUIFSFUVSOWBMVFUPUIFTZNCPMBGUFSSFEVDUJPO $BMMOFX@PQ@BTTJHO

Slide 163

Slide 163 text

5IFJNQMFNFOUBUJPOPGAAJT OPXDPNQMFUF

Slide 164

Slide 164 text

%FNP

Slide 165

Slide 165 text

3VOUIFEFNP

Slide 166

Slide 166 text

"MMTXFMMUIBUFOETXFMMʜ

Slide 167

Slide 167 text

6OGPSUVOBUFMZ UIFBOTXFSJTOP 5IFBEEJUJPOPGUIFAAPQFSBUPSJTCSFBLJOH POFFYJTUJOHTZOUBY

Slide 168

Slide 168 text

*OPSEJOBSZ3VCZ XFDBOVTFBOZOVNCFSPGJO TVDDFTTJPOXJUIPVUDBVTJOHTZOUBYFSSPST # Normal Ruby i = 0 i + 1 # => 1 i ++ 1 # => 1 i +++ 1 # => 1 i ++++ 1 # => 1 i +++++ 1 # => 1 5IJTJTCFDBVTFJGUIFSFBSFUXPPSNPSFT UIFTFDPOEBOETVCTFRVFOUTBSFDPOTJEFSFE VOBSZPQFSBUPST "MM`T/05XFMMUIBUFOETXFMM "MMTZOUBY0,

Slide 169

Slide 169 text

#VUJO3VCZXJUIPQFSBUPS XFHFUBTZOUBYFSSPSXJUIVOFYQFDUFEJOUFHFSMJUFSBM JGXFUSZUPQVUBOJOUFHFSBGUFSAA # Ruby with "++" operator # ruby/test.rb i = 0 i + 1 # => 1 i ++ 1 # => SyntaxError i = 0 i + (+1) # => 1 i ++ +1 # => 3 "MM`T/05XFMMUIBUFOETXFMM SVCZSVCZUFTUSC SVCZUFTUSCSVCZUFTUSC TZOUBYFSSPS VOFYQFDUFEJOUFHFSMJUFSBM FYQFDUJOHFOEPGJOQVU 4ZOUBY&SSPS J J? 5IFZBSFTZOUBY0, ɾ5PVTFBVOBSZPQFSBUPSXJUIQBSFOUIFTFT ɾ5PVTFAABOEBVOBSZPQFSBUPSBUUIFTBNFUJNF

Slide 170

Slide 170 text

*TUIJTBWBMJETQFDJ fi DBUJPO )PXTIPVMEUIFPQFSBUPSBOEVOBSZPQFSBUPST DPPQFSBUFXJUIFBDIPUIFS 5IFTFBSFRVFTUJPOTUIBUTIPVMECFDPOTJEFSFEJO3VCZ UIBUBEEFEUIFOFXTZOUBYXJUIUIFPQFSBUPS 5IJTJTBOJTTVFPGMBOHVBHFEFTJHO 'PSUIFNPNFOU UIJTJTUIFTQFDJ fi DBUJPOPGUIF JNQMFNFOUBUJPOTPGBS 5IFMBOHVBHFEFTJHOBGUFSBEEJOHBOFXTZOUBY

Slide 171

Slide 171 text

8FDBOOPMPOHFSDBMMUIJT3VCZ CFDBVTF*IBWFDIBOHFEUIFFYJTUJOHTZOUBY 5IJTOFXMBOHVBHFOFFETBOFXOBNF TPNFUIJOHBQQSPQSJBUFGPSJU

Slide 172

Slide 172 text

3VCZ3VCZ

Slide 173

Slide 173 text

3VCZ3VCZ IUUQTHJUIVCDPNTIJPJNNSVCZQMVTQMVT

Slide 174

Slide 174 text

&QJMPHVF

Slide 175

Slide 175 text

!TQJLFPMBGUPMENFʜ SFGIUUQTUXJUUFSDPNTQJLFPMBG

Slide 176

Slide 176 text

5IFSFBSFUXPUZQFTPGQFPQMF 0OFJTXIPOFFETBOFXHSBNNBSSVMF UPBEEBOFXTZOUBYJOUP.3* BOEPUIFSTXIPEPO`U

Slide 177

Slide 177 text

5IFSFBSFUXPUZQFTPGQFPQMF 0OFJTXIPOFFETBOFXHSBNNBSSVMF UPBEEBOFXTZOUBYJOUP.3* BOEPUIFSTXIPEPO`U "EEJOHOFXTZOUBYPOMZCZMFYJDBMBOBMZTJT

Slide 178

Slide 178 text

8IBUUIJTNFBOTJTUIBUBMUIPVHI*FWFOUVBMMZBEEFE BOFXTZOUBYSVMFGPSPQFSBUPSUIJTUJNF UIFSFBSFQSPCBCMZPUIFSXBZTUPEPJUUIBU*IBWFOPU EJTDPWFSFEJOQSBDUJDF

Slide 179

Slide 179 text

"OEOPUKVTUPQFSBUPS UIFSFXJMMCFBTNBOZXBZTUPBEEOFXTZOUBYUP .3*BTJNQMFNFOUPSTDBODPNFVQXJUI

Slide 180

Slide 180 text

"OEBT*IBWFTIPXO .3*IBTNBOZVTFGVMUPPMLJUTGPS SFBMJ[JOHUIFTFJEFBT 7BSJPVTUPPMLJUTUPTVQQPSUZPVSJEFB 'PSFYBNQMF )PXUPNPEJGZUIFTDBOOFS QBSTFS@ZZMFY )PXUPEF fi OFOFXTZOUBYSVMFTBOEBDUJPOTXJUITFNBOUJDWBMVFT 8IBUJTUIFPCKFDUPSJFOUFETFNBOUJDT "NBDSPUPDIBOHFUIFTUBUFPGUIFTDBOOFS 4&5@-&9@45"5& 4PNFVTFGVMGVODUJPOTUPDSFBUF3/PEFT FHOFX@RDBMM OFX@PQ@BTHO 4PNFVTFGVMNBDSPTUPDSFBUF3/PEFT FH/&8@-*5 /&8@7$"-- /&8@-*45 5IFMPDBUJPOBMJOGPSNBUJPOPGUIFTDBOOFSBOETPNFVTFGVMGVODUJPOT UPQFFLBUUIFDIBSBDUFSPOBTPVSDFDPEF FHQFFLD QFFLD@O

Slide 181

Slide 181 text

#ZNBLJOHGVMMVTFPGUIFN XIPBEET BOFXTZOUBYUP.3*OFYUJOPUIFSXBZT ʜJUNBZCFZPV

Slide 182

Slide 182 text

5IBOLZPVGPSZPVSBUUFOUJPO 4QFDJBMUIBOLTUP !TQJLFPMBG !NJOFSPBPLJ !PLVSBNBTBGVNJ 3FGFSFODFUP 3VCZ)BDLJOH(VJEF 1BSU4ZOUBYBOBMZTJT IUUQTSVCZIBDLJOHHVJEFHJUIVCJP 3VCZ6OEFSB.JDSPTDPQF"O*MMVTUSBUFE(VJEFUP3VCZ*OUFSOBMT $IBQUFS5PLFOJ[BUJPOBOE1BSTJOH IUUQTQBUTIBVHIOFTTZOFUSVCZVOEFSBNJDSPTDPQF

Slide 183

Slide 183 text

'PSXIFOUIFEFNPEPFTOUXPSL

Slide 184

Slide 184 text

3VOXJUIDPNQJMFE3VCZ