î j fÔ5ã@sŠddlmZmZmZGdd„dejƒZGdd„deƒZGdd„deƒZGdd „d eƒZ d d d „Z d S)é)ÚgrammarÚtokenÚtokenizec@seZdZdS)Ú PgenGrammarN)Ú__name__Ú __module__Ú __qualname__©r r ú7/opt/alt/python34/lib64/python3.4/lib2to3/pgen2/pgen.pyrs rc@sîeZdZddd„Zdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd d!„Zd"d#„Zd$d%„ZdS)&ÚParserGeneratorNcCs d}|dkr*t|ƒ}|j}n||_||_tj|jƒ|_|jƒ|j ƒ\|_ |_ |dk r‰|ƒni|_ |j ƒdS)N)ÚopenÚcloseÚfilenameÚstreamrÚgenerate_tokensÚreadlineÚ generatorÚgettokenÚparseÚdfasÚ startsymbolÚfirstÚ addfirstsets)ÚselfrrZ close_streamr r r Ú__init__ s         zParserGenerator.__init__c CsŽtƒ}t|jjƒƒ}|jƒ|j|jƒ|jd|jƒx;|D]3}dt|j ƒ}||j |<||j |Úupdate) rr/r1r2ZtotalsetZ overlapcheckr3r4ÚfsetZinverseZitsfirstZsymbolr r r r>ss2            zParserGenerator.calcfirstc Csïi}d}xÖ|jtjkräx |jtjkrC|jƒq$W|jtjƒ}|jtjdƒ|jƒ\}}|jtjƒ|j ||ƒ}t |ƒ}|j |ƒt |ƒ}|||<|dkr|}qqW||fS)Nú:) ÚtyperÚ ENDMARKERÚNEWLINErÚexpectr<ÚOPÚ parse_rhsÚmake_dfar"Ú simplify_dfa) rrrr/ÚaÚzr1ZoldlenZnewlenr r r r‘s"      zParserGenerator.parsec s‡fdd†}‡fdd†‰t||ƒ|ƒg}x×|D]Ï}i}xS|jD]H}x?|jD]4\}} |dk riˆ| |j|iƒƒqiqiWqYWxj|jƒD]\\}} x=|D]} | j| krÅPqÅqÅWt| |ƒ} |j| ƒ|j| |ƒq²WqCW|S)Ncsi}ˆ||ƒ|S)Nr )r2Úbase)Ú addclosurer r Úclosure°s z)ParserGenerator.make_dfa..closurecsT||krdSd||.addclosure)ÚDFAStateÚnfasetr$Ú setdefaultr%r&Úaddarc) rr,ÚfinishrOr*r2r$Znfastater3r4rQÚstr )rNr rI©s"  $  zParserGenerator.make_dfac CsÛtd|ƒ|g}x¾t|ƒD]°\}}td|||krJdpMdƒx|jD]t\}}||kr…|j|ƒ} nt|ƒ} |j|ƒ|dkr»td| ƒq[td|| fƒq[Wq#WdS)NzDump of NFA forz Statez(final)Úz -> %dz %s -> %d)ÚprintÚ enumerater$r(r"r&) rr/r,rTZtodor0r2r3r4Újr r r Údump_nfaÍs  "    zParserGenerator.dump_nfacCsŠtd|ƒxvt|ƒD]h\}}td||jr>dpAdƒx:|jjƒD])\}}td||j|ƒfƒqUWqWdS)NzDump of DFA forz Statez(final)rVz %s -> %d)rWrXr)r$r%r()rr/r1r0r2r3r4r r r Údump_dfaÝs  zParserGenerator.dump_dfacCs¦d}x™|r¡d}x†t|ƒD]x\}}xit|dt|ƒƒD]N}||}||krH||=x|D]}|j||ƒqrWd}PqHqHWq"Wq WdS)NTFr)rXÚranger"Ú unifystate)rr1Zchangesr0Zstate_irYZstate_jr2r r r rJäs     zParserGenerator.simplify_dfacCs±|jƒ\}}|jdkr+||fStƒ}tƒ}|j|ƒ|j|ƒxI|jdkr¢|jƒ|jƒ\}}|j|ƒ|j|ƒqZW||fSdS)Nú|)Ú parse_altr=ÚNFAStaterSr)rrKrLZaaZzzr r r rHùs       zParserGenerator.parse_rhscCsr|jƒ\}}xS|jdks?|jtjtjfkrg|jƒ\}}|j|ƒ|}qW||fS)Nú(ú[)rarb)Ú parse_itemr=rCrr<ÚSTRINGrS)rrKÚbr-Údr r r r_ s  zParserGenerator.parse_altcCsÁ|jdkrU|jƒ|jƒ\}}|jtjdƒ|j|ƒ||fS|jƒ\}}|j}|dkr†||fS|jƒ|j|ƒ|dkr³||fS||fSdS)Nrbú]ú+Ú*)rhri)r=rrHrFrrGrSÚ parse_atom)rrKrLr=r r r rcs          zParserGenerator.parse_itemcCs¹|jdkrH|jƒ|jƒ\}}|jtjdƒ||fS|jtjtjfkrœt ƒ}t ƒ}|j ||jƒ|jƒ||fS|j d|j|jƒdS)Nraú)z+expected (...) or NAME or STRING, got %s/%s) r=rrHrFrrGrCr<rdr`rSÚ raise_error)rrKrLr r r rj(s       zParserGenerator.parse_atomcCsc|j|ks*|dk rL|j|krL|jd|||j|jƒn|j}|jƒ|S)Nzexpected %s/%s, got %s/%s)rCr=rlr)rrCr=r r r rF9s *   zParserGenerator.expectcCsit|jƒ}x/|dtjtjfkr@t|jƒ}qW|\|_|_|_|_|_ dS)Nr) r4rrÚCOMMENTÚNLrCr=ZbeginÚendÚline)rÚtupr r r rAszParserGenerator.gettokenc Gsz|rGy||}WqGdj|gttt|ƒƒƒ}YqGXnt||j|jd|jd|jfƒ‚dS)Nú rr)ÚjoinrÚmapÚstrÚ SyntaxErrorrrorp)rÚmsgÚargsr r r rlHs-zParserGenerator.raise_error)rrrrr5r+r'rr>rrIrZr[rJrHr_rcrjrFrrlr r r r r s$   .    $       r c@s+eZdZdd„Zddd„ZdS)r`cCs g|_dS)N)r$)rr r r rSszNFAState.__init__NcCs|jj||fƒdS)N)r$r&)rr4r3r r r rSVszNFAState.addarc)rrrrrSr r r r r`Qs  r`c@sFeZdZdd„Zdd„Zdd„Zdd„Zd Zd S) rPcCs%||_||k|_i|_dS)N)rQr)r$)rrQÚfinalr r r r]s zDFAState.__init__cCs||j|s ÿH %