usr/lib/python3.6/site-packages/ply/__pycache__/yacc.cpython-36.pyc000064400000151550147205344360021013 0ustar003 .[`F @sddlZddlZddlZddlZddlZddlZddlZdZdZ dZ dZ dZ dZ dZd Zd ZdZejddkrteZneZejZGd d d eZGd ddeZGdddeZddZddZdada da!dZ"ddZ#ddZ$ddZ%ddZ&GdddZ'Gd d!d!Z(Gd"d#d#Z)ej*d$Z+Gd%d&d&eZ,Gd'd(d(eZ-Gd)d*d*eZ.d+d,Z/Gd-d.d.eZ0Gd/d0d0eZ1Gd1d2d2eZ2Gd3d4d4eZ3d5d6Z4d7d8Z5Gd9d:d:eZ6Gd;d<dZ8d?d@Z9GdAdBdBeZ:de de ddd de ddddf dCdDZ;dS)ENz3.9z3.8Tz parser.outparsetabLALRF(c@s4eZdZddZddZeZddZddZeZd S) PlyLoggercCs ||_dS)N)f)selfrr /usr/lib/python3.6/yacc.py__init__nszPlyLogger.__init__cOs|jj||ddS)N )rwrite)rmsgargskwargsr r r debugqszPlyLogger.debugcOs|jjd||ddS)Nz WARNING: r )rr )rrrrr r r warningvszPlyLogger.warningcOs|jjd||ddS)NzERROR: r )rr )rrrrr r r erroryszPlyLogger.errorN) __name__ __module__ __qualname__r rinforrZcriticalr r r r rms rc@seZdZddZddZdS) NullLoggercCs|S)Nr )rnamer r r __getattribute__szNullLogger.__getattribute__cOs|S)Nr )rrrr r r __call__szNullLogger.__call__N)rrrrrr r r r rsrc@s eZdZdS) YaccErrorN)rrrr r r r rsrcCsPt|}d|krt|}t|tkr4|dtd}dt|jt||f}|S)Nr z ...z<%s @ 0x%x> (%s))reprlen resultlimittyperid)rrepr_strresultr r r format_results r%cCsBt|}d|krt|}t|dkr(|Sdt|jt|fSdS)Nr z <%s @ 0x%x>)rrr rr!)r"r#r r r format_stack_entrys  r'aPLY: Don't use global functions errok(), token(), and restart() in p_error(). Instead, invoke the methods on the associated parser instance: def p_error(p): ... # Use parser.errok(), parser.token(), parser.restart() ... parser = yacc.yacc() cCstjttS)N)warningswarn_warnmsg_errokr r r r erroks r,cCstjttS)N)r(r)r*_restartr r r r restarts r.cCstjttS)N)r(r)r*_tokenr r r r tokens r0c Cs>|ja|ja|ja||}y bbbWntk r8YnX|S)N)r,r+r0r/r.r- NameError) errorfuncr0parserr"r r r call_errorfuncs r4c@seZdZddZddZdS) YaccSymbolcCs|jS)N)r )rr r r __str__szYaccSymbol.__str__cCst|S)N)str)rr r r __repr__szYaccSymbol.__repr__N)rrrr6r8r r r r r5sr5c@sfeZdZdddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ dS)YaccProductionNcCs||_||_d|_d|_dS)N)slicestacklexerr3)rsr;r r r r szYaccProduction.__init__cCsBt|trdd|j|DS|dkr2|j|jS|j|jSdS)NcSsg|] }|jqSr )value).0r=r r r sz.YaccProduction.__getitem__..r) isinstancer:r>r;)rnr r r __getitem__s   zYaccProduction.__getitem__cCs||j|_dS)N)r:r>)rrBvr r r __setitem__szYaccProduction.__setitem__cCsdd|j||DS)NcSsg|] }|jqSr )r>)r?r=r r r r@sz/YaccProduction.__getslice__..)r:)rijr r r __getslice__szYaccProduction.__getslice__cCs t|jS)N)rr:)rr r r __len__szYaccProduction.__len__cCst|j|ddS)Nlinenor)getattrr:)rrBr r r rJszYaccProduction.linenocCs||j|_dS)N)r:rJ)rrBrJr r r set_linenoszYaccProduction.set_linenocCs,t|j|dd}t|j|d|}||fS)NrJr endlineno)rKr:)rrB startlineZendliner r r linespanszYaccProduction.linespancCst|j|ddS)Nlexposr)rKr:)rrBr r r rP szYaccProduction.lexposcCs,t|j|dd}t|j|d|}||fS)NrPr endlexpos)rKr:)rrBstartposendposr r r lexspanszYaccProduction.lexspancCstdS)N) SyntaxError)rr r r rszYaccProduction.error)N)rrrr rCrErHrIrJrLrOrPrTrr r r r r9s r9c@s\eZdZddZddZddZddZd d Zdd dZdddZ dddZ dddZ d S)LRParsercCs0|j|_|j|_|j|_||_|jd|_dS)NT) lr_productions productions lr_actionactionlr_gotogotor2set_defaulted_stateserrorok)rZlrtabZerrorfr r r r s zLRParser.__init__cCs d|_dS)NT)r^)rr r r r,&szLRParser.errokcCs@|jdd=|jdd=t}d|_|jj||jjddS)Nz$endr) statestacksymstackr5r append)rsymr r r r.)s    zLRParser.restartcCsTi|_xH|jjD]:\}}t|j}t|dkr|ddkr|d|j|<qWdS)Nr)defaulted_statesrZitemslistvaluesr)rstateactionsZrulesr r r r]9s  zLRParser.set_defaulted_statescCs i|_dS)N)rd)rr r r disable_defaulted_states@sz!LRParser.disable_defaulted_statesNFcCsZ|str.t|trttj}|j|||||S|rD|j|||||S|j|||||SdS)N) yaccdevelrAintrsysstderr parsedebugparseoptparseopt_notrack)rinputr<rtracking tokenfuncr r r parseCs  zLRParser.parsec Csd}g}|j}|j} |j} |j} td} d} |jd|sLddlm}|j}|| _|| _ |dk rj|j ||dkrz|j }n|}||_ g}||_ g}||_ || _d}|jdt}d|_|j|d}x|jd|jd||| kr.|s|s|}n|j}|st}d|_|j}||j|}n| |}|jd|| |jd d d jd d |Dddt|fj|dk r|dkr|j||}|jd||j|d}| r| d8} q|dkrN| | }|j}|j}t}||_d|_|rB|jd|jddjdd || dDd| |d%||n|jd|jg| |d&||r|| dd}||d<|r|d}|j|_|j|_|d'}t|d|j|_t|d|j|_|| _ yd|| d=||_!|j"| || d=|jdt#| d|j|| |d(|}|j|Wqt$k r|j||j%|dd)|j|d*}d|_d|_|}t&} d|_'YqXqn|r|j|_|j|_|g}|| _ yL||_!|j"| |jdt#| d|j|| |d+|}|j|Wqt$k rJ|j||j|d,}d|_d|_|}t&} d|_'YqXq|dkr|d-}t|dd}|jdt#||jd|S|dkr|j(dd d jdd |Dddt|fj| dks|j'rt&} d|_'|}|jdkrd}|j)rB|rt*|d r||_||_!t+|j)||}|j'r|}d}qn`|rt*|dr\|j}nd}|r~t,j-j.d ||jfnt,j-j.d!|jnt,j-j.d"dSnt&} t|dkr|jdkrd}d}d}|dd=q|jdkrdS|jdkr|d.}|jdkr6|r0t|d|j|_t|d#|j|_d}qt}d|_t*|dr\|j|_|_t*|d#rv|j|_|_||_|j||}q|j}|r|j|_|j|_|j|d/}qt/d$qWdS)0NrzPLY: PARSE DEBUG STARTrc)lexz$endz State : %sz#Defaulted state %s: Reduce using %dz Stack : %sz%s . %s cSsg|] }|jqSr )r )r?xxr r r r@sz'LRParser.parsedebug..z Action : Shift and goto state %sz3Action : Reduce rule [%s] with %s and goto state %d[,cSsg|]}t|jqSr )r'r>)r?Z_vr r r r@s]rMrQz Result : %srFr>zDone : Returning %szPLY: PARSE DEBUG ENDz Error : %scSsg|] }|jqSr )r )r?ryr r r r@Bsr<rJz(yacc: Syntax error at line %d, token=%s zyacc: Syntax error, token=%sz yacc: Parse error in input. EOF rPzyacc: internal parser error!!! r}r}r}r}r}r}r}r}r}r})0rZr\rXrdr9rrwrvr<r3rrr0r_r`r;rar5r rpopgetjoinr7lstriprrr>rJrPrKrMrQr:rhcallabler%rUextend error_countr^rr2hasattrr4rmrnr RuntimeError) rrrr<rrsrt lookaheadlookaheadstackrir\prodrdpslice errorcountrv get_tokenr_r`errtokenrbrhltypetppnameplentargt1rBr$tokrJr r r ro\s~        .        $               .           zLRParser.parsedebugc Csvd}g}|j}|j} |j} |j} td} d} |sBddlm}|j}|| _|| _|dk r`|j ||dkrp|j }n|}||_ g}||_ g}||_ || _ d}|jdt}d|_|j|d}x|| kr|s|s|}n|j}|st}d|_|j}||j|}n| |}|dk rh|dkrN|j||}|j|d}| r| d8} q|dkrF| | }|j}|j}t}||_d|_|r|| dd}||d<|r|d}|j|_|j|_|d}t|d|j|_t|d|j|_|| _yP|| d=||_|j| || d=|j|| |d|}|j|Wqtk r|j||j|dd|j|d}d|_d|_|}t } d|_!YqXqn|r|j|_|j|_|g}|| _y8||_|j| |j|| |d|}|j|Wqtk rB|j||j|d}d|_d|_|}t } d|_!YqXq|dkrh|d}t|d d}|S|dkrf| dks|j!rNt } d|_!|}|jdkrd}|j"r|rt#|d  r||_||_t$|j"||}|j!rL|}d}qn`|rr<rJz(yacc: Syntax error at line %d, token=%s zyacc: Syntax error, token=%sz yacc: Parse error in input. EOF rPzyacc: internal parser error!!! r}r}r}r}r}r}r}r}r}))rZr\rXrdr9rwrvr<r3rrr0r_r`r;rar5r r~rrrr>rJrPrKrMrQr:rhrrUrrr^r2rr4rmrnr r) rrrr<rrsrtrrrir\rrdrrrvrr_r`rrbrhrrrrrrrrBr$rrJr r r rpsX                                  zLRParser.parseoptc Csd}g}|j}|j} |j} |j} td} d} |sBddlm}|j}|| _|| _|dk r`|j ||dkrp|j }n|}||_ g}||_ g}||_ || _ d}|jdt}d|_|j|d}x|| kr|s|s|}n|j}|st}d|_|j}||j|}n| |}|dk r |dkrN|j||}|j|d}| r| d8} q|dkr| | }|j}|j}t}||_d|_|rX|| dd}||d<|| _yP|| d=||_|j| || d=|j|| |d|}|j|Wqtk rR|j||j|dd|j|d}d|_d|_|}t} d|_YqXqn|g}|| _y8||_|j| |j|| |d|}|j|Wqtk r|j||j|d}d|_d|_|}t} d|_YqXq|dkr |d}t|dd}|S|dkr| dks(|jrt} d|_|}|jdkrFd}|jr|rht|d rh||_||_t |j||}|jr|}d}qn`|rt|d r|j!}nd}|rt"j#j$d ||jfnt"j#j$d |jnt"j#j$d dSnt} t|dkr(|jdkr(d}d}d}|dd=q|jdkr8dS|jdkr|d}|jdkr^d}qt}d|_t|d r|j!|_!|_%t|d r|j&|_&|_'||_|j||}q|j}|j|d}qt(dqWdS)Nrrc)rvz$endrFr>r<rJz(yacc: Syntax error at line %d, token=%s zyacc: Syntax error, token=%sz yacc: Parse error in input. EOF rPzyacc: internal parser error!!! r}r}r}r}r}r}r}r}))rZr\rXrdr9rwrvr<r3rrr0r_r`r;rar5r r~rrrr>r:rhrrUrrr^rKr2rr4rJrmrnr rMrPrQr)rrrr<rrsrtrrrir\rrdrrrvrr_r`rrbrhrrrrrrrBr$rrJr r r rqs8                                  zLRParser.parseopt_notrack)NNFFN)NNFFN)NNFFN)NNFFN) rrrr r,r.r]rjrurorprqr r r r rVs  ] 4rVz^[a-zA-Z0-9_-]+$c@sReZdZdZdddZddZd d Zd d Zd dZddZ ddZ ddZ dS) ProductionrrightNrwc Cs||_t||_||_||_d|_||_||_||_t |j|_ g|_ x$|jD]}||j krN|j j |qNWg|_ d|_ |jrd|jdj|jf|_n d|j|_dS)Nz%s -> %srxz %s -> )rtuplernumberfuncrfilelineprecrusymsralr_itemslr_nextrr7) rrrr precedencerrrr=r r r r s$    zProduction.__init__cCs|jS)N)r7)rr r r r6=szProduction.__str__cCsdt|dS)Nz Production())r7)rr r r r8@szProduction.__repr__cCs t|jS)N)rr)rr r r rICszProduction.__len__cCsdS)Nrcr )rr r r __nonzero__FszProduction.__nonzero__cCs |j|S)N)r)rindexr r r rCIszProduction.__getitem__cCs|t|jkrdSt||}yt|j|d|_Wnttfk rRg|_YnXy|j|d|_Wntk rd|_YnX|S)Nrc)rrLRItem Prodnameslr_after IndexErrorKeyError lr_before)rrBrr r r lr_itemMs   zProduction.lr_itemcCs|jr||j|_dS)N)rr)rpdictr r r bind]szProduction.bindrr)rNrwr) rrrreducedr r6r8rIrrCrrr r r r rs rc@s,eZdZddZddZddZddZd S) MiniProductioncCs.||_||_||_d|_||_||_||_dS)N)rrrrrrr7)rr7rrrrrr r r r fszMiniProduction.__init__cCs|jS)N)r7)rr r r r6oszMiniProduction.__str__cCs d|jS)NzMiniProduction(%s))r7)rr r r r8rszMiniProduction.__repr__cCs|jr||j|_dS)N)rr)rrr r r rvszMiniProduction.bindN)rrrr r6r8rr r r r res rc@s$eZdZddZddZddZdS)rcCsZ|j|_t|j|_|j|_||_i|_|jj|dt|j|_t|j|_|j |_ dS)N.) rrfrrlr_index lookaheadsinsertrrr)rrrBr r r r s   zLRItem.__init__cCs,|jrd|jdj|jf}n d|j}|S)Nz%s -> %srxz %s -> )rrr)rr=r r r r6s zLRItem.__str__cCsdt|dS)NzLRItem(r)r7)rr r r r8szLRItem.__repr__N)rrrr r6r8r r r r rs rcCs:t|d}x(|dkr4|||kr*||S|d8}qWdS)Nrcr)r)Zsymbols terminalsrFr r r rightmost_terminals     rc@s eZdZdS) GrammarErrorN)rrrr r r r rsrc@seZdZddZddZddZddZd$d d Zd%ddZddZ ddZ ddZ ddZ ddZ ddZddZddZd&d d!Zd"d#Zd S)'GrammarcCsfdg|_i|_i|_i|_x|D]}g|j|<q Wg|jd<i|_i|_i|_i|_t|_ d|_ dS)Nr) ProductionsrProdmap Terminals NonterminalsFirstFollow PrecedencesetUsedPrecedenceStart)rrtermr r r r s  zGrammar.__init__cCs t|jS)N)rr)rr r r rIszGrammar.__len__cCs |j|S)N)r)rrr r r rCszGrammar.__getitem__cCsL|jdgkstd||jkr*td||dkr:td||f|j|<dS)Nz2Must call set_precedence() before add_production()z,Precedence already specified for terminal %rleftrnonassocz:Associativity must be one of 'left','right', or 'nonassoc')rrr)rAssertionErrorrr)rrassoclevelr r r set_precedences   zGrammar.set_precedenceNrwrcCs||jkrtd|||f|dkr6td|||ftj|sRtd|||fxt|D]\}}|ddkryJt|}t|dkrtd||||f||jkrg|j|<|||<w\Wntk rYnXtj| r\|d kr\td ||||fq\Wd |kr|dd kr$td ||f|dd krBtd ||f|d} |jj | } | sptd||| fn |j j | |dd=nt ||j} |jj | d} d||f} | |j kr|j | } td||| fd| j| jft|j} ||jkrg|j|<xR|D]J}||jkr.|j|j| n&||jkrDg|j|<|j|j| q Wt| ||| |||}|jj|||j | <y|j|j|Wn"tk r|g|j|<YnXdS)Nz7%s:%d: Illegal rule name %r. Already defined as a tokenrz5%s:%d: Illegal rule name %r. error is a reserved wordz%s:%d: Illegal rule name %rrz'"rczA%s:%d: Literal token %s in rule %r may only be a single characterz%precz!%s:%d: Illegal name %r in rule %rz+%s:%d: Syntax error. Nothing follows %%preczH%s:%d: Syntax error. %%prec can only appear at the end of a grammar rulez/%s:%d: Nothing known about the precedence of %rrz%s -> %sz%s:%d: Duplicate rule %s. zPrevious definition at %s:%dr}r}r)rr)rr_is_identifiermatch enumerateevalrrUrrraddrrrrrrrarrr)rprodnamesymsrrrrBr=cZprecnameZprodprecmapmZpnumberrrr r r add_production sp                        zGrammar.add_productioncCsT|s|jdj}||jkr&td|tdd|g|jd<|j|jd||_dS)Nrczstart symbol %s undefinedrzS')rrrrrrar)rstartr r r set_startas   zGrammar.set_startcs>fddtjdjdfddjDS)NcsJ|kr dSj|x.jj|gD]}x|jD] }|q2Wq&WdS)N)rrrr)r=rr")mark_reachable_from reachablerr r rts   z5Grammar.find_unreachable..mark_reachable_fromrcsg|]}|kr|qSr r )r?r=)rr r r@~sz,Grammar.find_unreachable..)rrrr)rr )rrrr find_unreachableqszGrammar.find_unreachablec Csi}x|jD] }d||<q Wd|d<x|jD] }d||<q,Wxpd}x`|jjD]R\}}xH|D]@}x |jD]}||shd}PqhWd}|r\||sd||<d}Pq\WqNW|s>Pq>Wg} x@|jD]4\}} | s||jkr||jkr|dkrq| j|qW| S)NTz$endFr)rrrrerra) rZ terminatesrrB some_changeZplrr=Z p_terminatesinfiniterr r r infinite_cycless:       zGrammar.infinite_cyclescCsXg}xN|jD]D}|sq x8|jD].}||jkr||jkr|dkr|j||fqWq W|S)Nr)rrrrra)rr$rr=r r r undefined_symbolss  zGrammar.undefined_symbolscCs8g}x.|jjD] \}}|dkr| r|j|qW|S)Nr)rrera)rZ unused_tokr=rDr r r unused_terminalss zGrammar.unused_terminalscCs<g}x2|jjD]$\}}|s|j|d}|j|qW|S)Nr)rrerra)rZ unused_prodr=rDrr r r unused_ruless zGrammar.unused_rulescCsDg}x:|jD]0}||jkp"||jks |j||j|dfq W|S)Nr)rrrra)rZunusedZtermnamer r r unused_precedences  zGrammar.unused_precedencecCs`g}xV|D]D}d}x2|j|D]$}|dkr0d}q||kr|j|qW|rLq Pq W|jd|S)NFzT)rra)rZbetar$xZx_produces_emptyrr r r _first s  zGrammar._firstcCs|jr |jSx|jD]}|g|j|<qWdg|jd<x|jD]}g|j|<qT) rrrrrrrrrrar) rrkdidaddrrFBZfstZhasemptyrr r r compute_followQs<     zGrammar.compute_followcCsx|jD]}|}d}g}x|t|kr,d}ntt||}y|j|j|d|_Wnttfk rng|_YnXy|j|d|_Wntk rd|_YnX||_ |sP|j ||}|d7}qW||_ qWdS)Nrrc) rrrrrrrrrrrar)rrZlastlrirFrZlrir r r build_lritemss.       zGrammar.build_lritems)Nrwr)N)N)rrrr rIrCrrrrrrrrrrrrrr r r r rs $  T @#% ;rc@s eZdZdS) VersionErrorN)rrrr r r r rsrc@s,eZdZddZddZddZddZd S) LRTablecCsd|_d|_d|_d|_dS)N)rYr[rW lr_method)rr r r r szLRTable.__init__cCs~t|tjr|}ntd|tj|}|jtkr:td|j |_ |j |_ g|_ x|jD]}|j jt|qXW|j|_|jS)Nz import %sz&yacc table file version is out of date)rAtypes ModuleTypeexecrmmodulesZ _tabversion__tabversion__rZ _lr_actionrYZ_lr_gotor[rWZ_lr_productionsrarZ _lr_methodrZ _lr_signature)rmodulerrr r r read_tables     zLRTable.read_tablec Csy ddl}Wntk r(ddl}YnXtjj|s:tt|d}|j|}|tkr^t d|j||_ |j|}|j||_ |j||_ |j|}g|_ x|D]}|j jt|qW|j|S)Nrrbz&yacc table file version is out of date)cPickle ImportErrorpickleospathexistsopenloadrrrrYr[rWrarclose)rfilenamerZin_fZ tabversion signaturerXrr r r read_pickles(          zLRTable.read_picklecCsx|jD]}|j|qWdS)N)rWr)rrrr r r bind_callabless zLRTable.bind_callablesN)rrrr rrrr r r r rsrc CsTi}x|D] }d||<q Wg}i}x,|D]$}||dkr(t|||||||q(W|S)Nr)traverse)XRFPNrr;Fr r r digraphs    r c Cs |j|t|}|||<||||<||}xr|D]j} || dkrXt| ||||||t|||| ||<x.|j| gD]} | ||kr|||j| q|Wq4W|||krt||d<||||d<|j} x2| |krt||d<||||d<|j} qWdS)Nrrcr}r}r}r})rarrminrMAXINTr~) rrr;rrrrdrelyaelementr r r rs(        rc@s eZdZdS) LALRErrorN)rrrr r r r r)src@seZdZd$ddZddZddZd d Zd d Zd dZddZ ddZ ddZ ddZ ddZ ddZddZddZd%d d!Zd&d"d#ZdS)'LRGeneratedTablerNcCs|dkrtd|||_||_|s*t}||_i|_i|_|j|_i|_ i|_ d|_ d|_ d|_ g|_g|_g|_|jj|jj|jj|jdS)NSLRrzUnsupported method %sr)rr)rgrammarrrlogrYr[rrW lr_goto_cache lr0_cidhash _add_countZ sr_conflictZ rr_conflictZ conflicts sr_conflicts rr_conflictsrrrlr_parse_table)rrmethodrr r r r 4s,    zLRGeneratedTable.__init__cCsz|jd7_|dd}d}xV|rtd}xH|D]@}x:|jD]0}t|dd|jkrRq:|j|j|j|_d}q:Wq.Wq W|S)NrcTF lr0_addedr)rrrKrarr)rIJrrGrr r r lr0_closureYs    zLRGeneratedTable.lr0_closurec Cs|jjt||f}|r|S|jj|}|s:i}||j|<g}xP|D]H}|j}|rD|j|krD|jt|}|s~i}||t|<|j||}qDW|jd}|s|r|j|}||d<n||d<||jt||f<|S)Nz$end)rrr!rrrar ) rrrgr=ZgsrrBs1r r r lr0_gotoss2        zLRGeneratedTable.lr0_gotoc Cs|j|jjdjgg}d}x"|D]}||jt|<|d7}q"Wd}x|t|kr||}|d7}i}x$|D]}x|jD] }d||<qxWqlWxJ|D]B}|j||}| st||jkrqt||jt|<|j |qWqFW|S)Nrrc) r rrrrr!rrr#ra) rCrFrZasymsiir=rr!r r r lr0_itemss(      zLRGeneratedTable.lr0_itemscCst}d}xrxV|jjddD]B}|jdkr:|j|jqx$|jD]}||krBPqBW|j|jqWt||krrPt|}q W|S)Nrrc)rrrrrrr)rnullableZ num_nullablerrr r r compute_nullable_nonterminalss     z.LRGeneratedTable.compute_nullable_nonterminalscCsrg}xht|D]\\}}xR|D]J}|j|jdkr||j|jdf}|d|jjkr||kr|j|qWqW|S)Nrc)rrrrrrra)rr$transZstatenorhrrr r r find_nonterminal_transitionss z-LRGeneratedTable.find_nonterminal_transitionsc Csi}|\}}g}|j|||}xJ|D]B} | j| jdkr&| j| jd} | |jjkr&| |kr&|j| q&W|dkr||jjdjdkr|jd|S)Nrcrz$end)r#rrrrrrar) rr$r)r'Zdr_setrhrtermsr!rrr r r dr_relations   zLRGeneratedTable.dr_relationc Csvg}|\}}|j|||}|jjt|d}xB|D]:} | j| jdkr4| j| jd} | |kr4|j|| fq4W|S)Nrcr})r#rrr!rrrra) rr$r)emptyr rhrr!rGrrr r r reads_relation s zLRGeneratedTable.reads_relationcCsi}i}i}x|D] }d||<qWx|D]\}} g} g} xR||D]D} | j| krZqH| j} |}x| | jdkr | d} | j| }||f|kr| d}xH|| jkr| j||jjkrP| j||krP|d}qW| j||f|j|||}|jj t |d}qfWx||D]t}|j| jkr,q|j| jkr>qd}xD||jkrx|j|| j|dkrlP|d}qDW| j||fqWqHWx2| D]*}||krg||<||j|| fqW| ||| f<q*W||fS)Nrcrr}) rrrrrrrar#rrr!)rr$r)r'ZlookdictZ includedictZdtransrrhrZlookbZincludesrrrGZlir!r"rFr r r compute_lookback_includesC sX         z*LRGeneratedTable.compute_lookback_includescs0fdd}fdd}t|||}|S)Ncsj|S)N)r,)r)r$r'rr r  sz4LRGeneratedTable.compute_read_sets..csj|S)N)r.)r)r$r'rr r r0 s)r )rr$ntransr'rrrr )r$r'rr compute_read_sets s z"LRGeneratedTable.compute_read_setscs(fdd}fdd}t|||}|S)Ncs|S)Nr )r)readsetsr r r0 sz6LRGeneratedTable.compute_follow_sets..cs j|gS)N)r)r)inclsetsr r r0 s)r )rr1r3r4rrrr )r4r3r compute_follow_sets s   z$LRGeneratedTable.compute_follow_setsc Csxxr|jD]f\}}x\|D]T\}}||jkr4g|j|<|j|g}x*|D]"}||j|krF|j|j|qFWqWq WdS)N)rerrra) rZ lookbacksZ followsetr)Zlbrhrrrr r r add_lookaheads s    zLRGeneratedTable.add_lookaheadscCsP|j}|j|}|j|||}|j|||\}}|j|||}|j||dS)N)r(r*r2r/r5r6)rr$r'r)r3ZlookdZincludedZ followsetsr r r add_lalr_lookaheads s  z$LRGeneratedTable.add_lalr_lookaheadsc$ Cs<|jj}|jj}|j}|j}|j}i}|jd|j|j}|jdkrP|j |d}x|D]} g} i} i} i} |jd|jd||jdx| D]}|jd|j |qW|jdx| D]}|j |j dkr,|j dkrd| d <|| d <q|jdkr|j|}n|jj|j }x|D]}| j||d |j |ff| j|}|dk r|dkrB|| |j j\}}|j|d\}}||ks||kr|d kr|j | |<|| |<| r| r|jd ||jj||df||j jd7_nB||kr|dkrd| |<n$|s|jd||jj||dfn|dkr|| }||j }|j|jkr|j | |<|| |<||}}||j jd7_||j jd8_n ||}}|jj|||f|jd|| |j | |n td|n(|j | |<|| |<||j jd7_q&Wq|j }|j|d}||jjkr|j| |}|jjt|d}|dkr| j||d|f| j|}|dk r|dkr||krtd|n|dkr|| |j j\}}|j|d\}}||ks||krV|d krV|| |j jd8_|| |<|| |<|s|jd||jj||dfnL||krt|dkrtd| |<n.| r| r|jd ||jj||dfn td|q|| |<|| |<qWi}xF| D]>\}}}|| kr|| |kr|jd||d|||f<qW|jdd}xX| D]P\}}}|| kr&|| |k r&||f|kr&|jd||d}d|||f<q&W|r|jdi} x6| D].}!x&|!jD]}"|"|jjkrd| |"<qWqWxL| D]D}#|j| |#}|jjt|d}|dkr|| |#<|jd|#|qW| ||<| ||<| ||<|d7}q\WdS)NzParsing method: %srrrwzstate %dz (%d) %srczS'z$endzreduce using rule %d (%s)rrz3 ! shift/reduce conflict for %s resolved as reducereducerz2 ! shift/reduce conflict for %s resolved as shiftZshiftz= ! reduce/reduce conflict for %s resolved using rule %d (%s)zUnknown conflict in state %dzshift and go to state %dz Shift/shift conflict in state %dz %-15s %sz ! %-15s [ %s ]z" %-30s shift and go to state %d)rrr})rrr}) rrrr[rYrrrr&r7rrrrrrrarrrrrrrrrr#rr!rrr)$rrrr\rZrZactionpr$strZactlistZ st_actionZ st_actionpZst_gotorZlaheadsrr"ZsprecZslevelZrprecZrlevelZoldpZppZchosenpZrejectprFr!rGZ _actprintrZnot_usedZnkeysr%r=rBr r r r s                                             zLRGeneratedTable.lr_parse_tablerwcCst|tjrtd|jdd}tjj||d}ylt|d}|j dtjj |t |j |fd}|rti}xf|j jD]X\} } xN| jD]B\} } |j| } | sggf} | || <| dj| | dj| qWq|W|j dxz|jD]n\}} |j d |x | dD]} |j d | q W|j d x | dD]} |j d | q8W|j d qW|j d |j dnJ|j dx4|j jD]&\}} |j d|d|d| fqW|j d |ri}xl|jjD]^\} } xR| jD]F\} } |j| } | sggf} | || <| dj| | dj| qWqW|j dx||jD]p\}} |j d |x | dD]} |j d | qjW|j d x | dD]} |j d | qW|j d qJW|j d |j dnJ|j dx4|jjD]&\}} |j d|d|d| fqW|j d |j dxd|jD]Z}|jrl|j d|j|j|j|jtjj |j|jfn|j dt||j|jfq0W|j d|jWn&tk r}zWYdd}~XnXdS)Nz"Won't overwrite existing tabmodulerrcz.pywzu # %s # This file is automatically generated. Do not edit. _tabversion = %r _lr_method = %r _lr_signature = %r rz _lr_action_items = {z%r:([z%r,z],[z]),z} z _lr_action = {} for _k, _v in _lr_action_items.items(): for _x,_y in zip(_v[0],_v[1]): if not _x in _lr_action: _lr_action[_x] = {} _lr_action[_x][_k] = _y del _lr_action_items z _lr_action = { z (%r,%r):%r,z _lr_goto_items = {z _lr_goto = {} for _k, _v in _lr_goto_items.items(): for _x, _y in zip(_v[0], _v[1]): if not _x in _lr_goto: _lr_goto[_x] = {} _lr_goto[_x][_k] = _y del _lr_goto_items z _lr_goto = { z_lr_productions = [ z (%r,%r,%d,%r,%r,%d), z (%r,%r,%d,None,None,None), z] r})rArrIOErrorsplitrrrrr basenamerrrYrerrar[rWrr7rrrrr)r tabmodule outputdirrZbasemodulenamerrZsmallerrer=ZndrrDrFrrer r r write_table s       "      "   "  zLRGeneratedTable.write_tablecCsy ddl}Wntk r(ddl}YnXt|d}|jt|t|j|j|t|j||t|j|j|t|j|j |tg}x^|j D]T}|j r|j |j |j|j|j tjj|j|jfq|j t ||j|jdddfqW|j||tWdQRXdS)Nrwb)rrrrdumprpickle_protocolrrYr[rWrrar7rrrrr=rr)rrrrZoutfZoutprr r r pickle_table s    ,"zLRGeneratedTable.pickle_table)rN)rwrw)rw)rrrr r r#r&r(r*r,r.r/r2r5r6r7rrArEr r r r r3s" %#8+P8 zrcCs0tj|}|jj}|j|jkr,|j|j|S)N)rm _getframe f_globalscopyf_localsupdate)ZlevelsrZldictr r r get_caller_module_dict9 s     rKc Csg}|j}d}|}x|D]}|d7}|j}|s4qy|ddkrh|sVtd||f|} |dd} n@|d} | }|dd} |d} | dkr| dkrtd||f|j||| | fWqtk rYqtk rtd |||jfYqXqW|S) Nrcr|z%s:%d: Misplaced '|'r:z::=z!%s:%d: Syntax error. Expected ':'z%s:%d: Syntax error in rule %r) splitlinesr<rUra Exceptionstrip) docrrrZpstringsZlastpZdlineZpsrrrZassignr r r parse_grammarE s6    rRc@seZdZd ddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZdS)! ParserReflectNcCsL||_d|_d|_d|_t|_g|_d|_|dkrBtt j |_ n||_ dS)NF) rr error_functokensrrrrrrmrnr)rrrr r r r o szParserReflect.__init__cCs,|j|j|j|j|jdS)N) get_startget_error_func get_tokensget_precedenceget_pfunctions)rr r r get_all~ s zParserReflect.get_allcCs6|j|j|j|j|j|j|jS)N)validate_startvalidate_error_funcvalidate_tokensvalidate_precedencevalidate_pfunctionsvalidate_modulesr)rr r r validate_all szParserReflect.validate_allcCsyddlm}Wn tk r0ddlm}YnXy|dd}|jrV|j|jjd|jr~|jdjdd|jDjd|jr|jd j|jjdx*|j D] }|d r|j|d jdqWWnt t fk rYnXt j |j}tjdd kr |jd}|S) Nr)md5F)Zusedforsecurityzlatin-1rwcSsg|]}dj|qS)rw)r)r?rr r r r@ sz+ParserReflect.signature..rxr)ZhashlibrcrrrJencoderrrUpfuncs TypeError ValueErrorbase64Z b16encodedigestrm version_infodecode)rrcZsigrrir r r r s* "  zParserReflect.signaturec Cstjd}x|jD]}ytj|\}}Wntk r>wYnXi}xjt|D]^\}}|d7}|j|}|rN|jd}|j |} | s|||<qNtj |} |j j d| ||| qNWqWdS)Nz\s*def\s+(p_[a-zA-Z_0-9]*)\(rcz;%s:%d: Function %s redefined. Previously defined on line %d) recompilerinspectZgetsourcelinesr;rrgroupr getsourcefilerr) rZfrerlinesZlinenZ counthashrrrprevrr r r ra s$       zParserReflect.validate_modulescCs|jjd|_dS)Nr)rrr)rr r r rV szParserReflect.get_startcCs&|jdk r"t|jts"|jjddS)Nz'start' must be a string)rrA string_typesrr)rr r r r\ s  zParserReflect.validate_startcCs|jjd|_dS)Np_error)rrrT)rr r r rW szParserReflect.get_error_funccCs|jrt|jtjrd}n*t|jtjr.d}n|jjdd|_dS|jjj}|jjj }t j |j}|j j ||jjj|}|dkr|jjd||d|_dS)Nrrcz2'p_error' defined, but is not a function or methodTz$%s:%d: p_error() requires 1 argument)rTrAr FunctionType MethodTyperr__code__co_firstlineno co_filenamern getmodulerr co_argcount)rZismethodZelineZefilerZargcountr r r r] s      z!ParserReflect.validate_error_funccCsn|jjd}|s&|jjdd|_dSt|ttfsJ|jjdd|_dS|sd|jjdd|_dS||_dS)NrUzNo token list is definedTztokens must be a list or tupleztokens is empty)rrrrrArfrrU)rrUr r r rX s    zParserReflect.get_tokenscCsZd|jkr |jjdd|_dSt}x.|jD]$}||krH|jjd||j|q.WdS)Nrz.Illegal token name 'error'. Is a reserved wordTzToken %r multiply defined)rUrrrrr)rrrBr r r r^ s   zParserReflect.validate_tokenscCs|jjd|_dS)Nr)rrr)rr r r rY szParserReflect.get_precedencecCsg}|jrt|jttfs2|jjdd|_dSxt|jD]\}}t|ttfsj|jjdd|_dSt|dkr|jjd|d|_dS|d}t|ts|jjdd|_dSxH|ddD]8}t|ts|jjd d|_dS|j |||dfqWq>W||_ dS) Nz"precedence must be a list or tupleTzBad precedence tablerz?Malformed precedence entry %s. Must be (assoc, term, ..., term)rz)precedence associativity must be a stringrcz precedence items must be strings) rrArfrrrrrrsrapreclist)rr|rrrrr r r r_ s6       z!ParserReflect.validate_precedencecCsg}xl|jjD]^\}}|jd s|dkr.qt|tjtjfrt|d|jj }t j |}|j ||||j fqW|jddd||_dS)Np_rtrxcSs |dt|d|d|dfS)Nrrcrr)r7)Z p_functionr r r r0B s z.ParserReflect.get_pfunctions..)key)rre startswithrArrurvrKrwrxrnrzra__doc__sortre)rZ p_functionsritemrrr r r rZ5 s zParserReflect.get_pfunctionscCs^g}t|jdkr(|jjdd|_dSx"|jD]\}}}}tj|}|j|}t|tj rfd}nd}|j j |kr|jjd|||j d|_q2|j j |kr|jjd|||j d|_q2|j s|jjd|||j q2y,t|||} x| D]} |j|| fqWWn:tk r<} z|jjt| d|_WYdd} ~ XnX|jj|q2Wx|jjD]\} } | jd rt| tjtj frq\| jd rq\| jd r| d kr|jjd | t| tjr| j j dkst| tj r\| jj j dkr\| j r\y8| j jd }|ddkr4|jjd| j j| j j| Wntk rLYnXq\W||_dS)Nrz+no rules of the form p_rulename are definedTrrcz%%s:%d: Rule %r has too many argumentsz#%s:%d: Rule %r requires an argumentzA%s:%d: No documentation string specified in function %r (ignored)r}Zt_rtz%r not defined as a functionrxrMz9%s:%d: Possible grammar rule %r defined without p_ prefix)rrerrrnrprrArrvrwr{rrrrRrarUr7rrrerru__func__r<ryrxrr)rrrrrrQrrZreqargsZparsed_gr!r@rBrDr r r r`J s\            z!ParserReflect.validate_pfunctions)N)rrrr r[rbrrarVr\rWr]rXr^rYr_rZr`r r r r rSn s  #rSc <Osd |dkr t}| rd}| dkr&ttj} rffddtD} t| }d|krntj|dj|d<ntd}| dkrt |t j r|j}nLd|kr|d}n:|j d}dj |dd6}td |ttj|dd }tjj|} |jd }|ot |trd|kr|d|}|dk r$||d <t|| d }|j|jrHtd|j}yt}| rj|j| }n |j|}|s||kry"|j|jt||j }|j!a!|St"k r}z| j#d|WYdd}~XnXWnFt$k r }z| j#t|WYdd}~Xnt%k r YnX| dkr|rytt&tjj | |d} Wn<t'k r}z| j#d||ft(} WYdd}~XnXnt(} | j)dt*d}|j+rtd|j s| j#dt,|j-}xZ|j.D]P\}}}y|j/|||Wn0t0k r&}z| j#d|WYdd}~XnXqWxl|j1D]b\}}|\} }!}"}#y|j2|"|#|| |!Wn4t0k r}z| jd|d}WYdd}~XnXq6Wy&|dkr|j3|j4n |j3|Wn6t0k r}z| jt|d}WYdd}~XnX|rtd|j5}$x*|$D]"\}%}&| jd|&j6|&j7|%d}qW|j8}'|'r| j)d | j)d| j)d x&|'D]}| j#d|| j)d|qnW|r| j)d | j)d| j)d x&t9|j:D]\}(})| j)d|(|)qW|j;}*x$|*D]}&| j#d|&j6|&j7|&j<qWt=|'dkr"| j#dt=|'dkr@| j#dt=|'t=|*dkrX| j#d t=|*dkrv| j#d!t=|*|rN| j)d | j)d"| j)d t>|j?}+|+j@x2|+D]*}| j)d#|d$j d%d|j?|DqW| j)d | j)d&| j)d t>|jA},|,j@x2|,D]*}-| j)d#|-d$j d'd|jA|-DqW| j)d |r|jB}.x|.D]}/| j#d(|/qbW|jC}0x|0D]}1| jd)|1d}qW|jD}2x$|2D]\}}| jd*||d}qW|rtd|r| jEd+|tF||| }|rlt=|jG}3|3dkr | j#d,n|3dkr6| j#d-|3t=|jH}4|4dkrV| j#d.n|4dkrl| j#d/|4|r|jGs|jHr| j#d | j#d0| j#d x&|jGD]\}5}6}7| j#d1|6|5|7qWtI}8x|jHD]x\}5}9}:|5tJ|9tJ|:f|8krq| j#d2|5|9| j#d3|:|5| j#d2|5|9| j#d3|:|5|8jK|5tJ|9tJ|:fqWg};xL|jHD]B\}5}9}:|:jL r^|:|;kr^| j#d4|:| j#d4|:|;jM|:q^W|ry|jN|| |Wn6t'k r}z| j#d5||fWYdd}~XnX| rBy|jO| |Wn6t'k r@}z| j#d5| |fWYdd}~XnX|j|jt||j }|j!a!|S)7Nrcsg|]}|t|fqSr )rK)r?r)rr r r@ szyacc..__file__rrrrcz import %srw __package__r)rzUnable to build parserz.There was a problem loading the table file: %rr:zCouldn't open %r. %sz5Created by PLY version %s (http://www.dabeaz.com/ply)Fz no p_error() function is definedz%sTz;%s:%d: Symbol %r used, but not defined as a token or a rulezUnused terminals:zToken %r defined, but not usedz %srz Rule %-5d %sz$%s:%d: Rule %r defined, but not usedzThere is 1 unused tokenzThere are %d unused tokenszThere is 1 unused rulezThere are %d unused rulesz'Terminals, with rules where they appearz %-20s : %srxcSsg|] }t|qSr )r7)r?r=r r r r@E sz*Nonterminals, with rules where they appearcSsg|] }t|qSr )r7)r?r=r r r r@M szSymbol %r is unreachablez)Infinite recursion detected for symbol %rz0Precedence rule %r defined for unknown symbol %rzGenerating %s tablesz1 shift/reduce conflictz%d shift/reduce conflictsz1 reduce/reduce conflictz%d reduce/reduce conflictsz Conflicts:z7shift/reduce conflict for %s in state %d resolved as %sz;reduce/reduce conflict in state %d resolved using rule (%s)zrejected rule (%s) in state %dzRule (%s) is never reducedzCouldn't create %r. %sr})P tab_modulerrmrndirdictrrrKrArrr<rrrKrrdirnamerr7rSr[rrrrrrrrrVrTrurOrrrrr;rr __version__rbrrUr|rrrrrrrrrrrrrrrrfrrrrrrrrrrrr!rrrarArE)rZcheck_recursionoptimizeZ write_tablesZ debugfiler?ZdebuglogZerrorlogZ picklefileZ_itemsrZsrcfilepartsZpkgnameZpkgZpinforZlrZread_signaturer3r@errorsrrrrfuncnameZgramrrrrrrbrrrBrrr+ZnontermsZnontermZ unreachableurinfZ unused_precZnum_srZnum_rrrhrZ resolutionZalready_reportedZruleZrejectedZ warned_neverr )rr yacc s               "     $                    *     *                       $$  r)>s   4m H.rT    )