î 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 |.closurecsit|tƒst‚||kr%dSd||.addclosure) r;rVr=ÚDFAStateÚnfasetr$Ú setdefaultr%r&Úaddarc) rr,ÚfinishrUr*r2r$Znfastater3r4rXÚstr )rTr rO©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,r[Ztodor0r2r3r4Ú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)r]z %s -> %d)r^r_r)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)r_Úranger"Ú unifystate)rr1Zchangesr0Zstate_ir`Zstate_jr2r r r rPäs     zParserGenerator.simplify_dfacCs±|jƒ\}}|jdkr+||fStƒ}tƒ}|j|ƒ|j|ƒxI|jdkr¢|jƒ|jƒ\}}|j|ƒ|j|ƒqZW||fSdS)Nú|)Ú parse_altrCrVrZr)rrQrRZaaZzzr r r rNùs       zParserGenerator.parse_rhscCsr|jƒ\}}xS|jdks?|jtjtjfkrg|jƒ\}}|j|ƒ|}qW||fS)Nú(ú[)rgrh)Ú parse_itemrCrIrrBÚSTRINGrZ)rrQÚbr-Údr r r rf s  zParserGenerator.parse_altcCsÁ|jdkrU|jƒ|jƒ\}}|jtjdƒ|j|ƒ||fS|jƒ\}}|j}|dkr†||fS|jƒ|j|ƒ|dkr³||fS||fSdS)Nrhú]ú+Ú*)rnro)rCrrNrLrrMrZÚ parse_atom)rrQrRrCr r r ris          zParserGenerator.parse_itemcCs¹|jdkrH|jƒ|jƒ\}}|jtjdƒ||fS|jtjtjfkrœt ƒ}t ƒ}|j ||jƒ|jƒ||fS|j d|j|jƒdS)Nrgú)z+expected (...) or NAME or STRING, got %s/%s) rCrrNrLrrMrIrBrjrVrZÚ raise_error)rrQrRr r r rp(s       zParserGenerator.parse_atomcCsc|j|ks*|dk rL|j|krL|jd|||j|jƒn|j}|jƒ|S)Nzexpected %s/%s, got %s/%s)rIrCrrr)rrIrCr r r rL9s *   zParserGenerator.expectcCsit|jƒ}x/|dtjtjfkr@t|jƒ}qW|\|_|_|_|_|_ dS)Nr) r4rrÚCOMMENTÚNLrIrCZbeginÚendÚline)rÚtupr r r rAszParserGenerator.gettokenc Gsz|rGy||}WqGdj|gttt|ƒƒƒ}YqGXnt||j|jd|jd|jfƒ‚dS)Nú rr)ÚjoinrÚmapÚstrÚ SyntaxErrorrrurv)rÚmsgÚargsr r r rrHs-zParserGenerator.raise_error)rrrrr5r+r'rrDrrOrarbrPrNrfrirprLrrrr r r r r s$   .    $       r c@s+eZdZdd„Zddd„ZdS)rVcCs g|_dS)N)r$)rr r r rSszNFAState.__init__NcCsP|dks!t|tƒs!t‚t|tƒs6t‚|jj||fƒdS)N)r;r{r=rVr$r&)rr4r3r r r rZVs!zNFAState.addarc)rrrrrZr r r r rVQs  rVc@sFeZdZdd„Zdd„Zdd„Zdd„Zd Zd S) rWcCspt|tƒst‚ttt|ƒƒtƒs6t‚t|tƒsKt‚||_||k|_i|_dS)N) r;Údictr=r4ÚiterrVrXr)r$)rrXÚfinalr r r r]s ! zDFAState.__init__cCsPt|tƒst‚||jks*t‚t|tƒs?t‚||j|s ÿH %