AlkantarClanX12

Your IP : 18.116.14.48


Current Path : /opt/alt/python35/lib64/python3.5/lib2to3/pgen2/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/lib2to3/pgen2/__pycache__/pgen.cpython-35.pyc



��Yf�5�@s�ddlmZmZmZGdd�dej�ZGdd�de�ZGdd�de�ZGdd	�d	e�Z	d
dd�Z
d
S)�)�grammar�token�tokenizec@seZdZdS)�PgenGrammarN)�__name__�
__module__�__qualname__�r	r	�7/opt/alt/python35/lib64/python3.5/lib2to3/pgen2/pgen.pyrsrc@s�eZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd d!�Zd"d#�Zd$d%�ZdS)&�ParserGeneratorNcCs�d}|dkr't|�}|j}||_||_tj|j�|_|j�|j	�\|_
|_|dk	r�|�i|_|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__cCs�t�}t|jj��}|j�|j|j�|jd|j�x;|D]3}dt|j	�}||j	|<||j
|<qRWx�|D]�}|j|}g}x�|D]�}g}xKt|jj
��D]4\}	}
|j|j||	�|j|
�f�q�W|jr/|jd|j|�f�|j|�q�W|jj|�||j||�f|j|j	|<q�W|j	|j|_|S)N��)r�listr�keys�sort�remover�insert�len�
symbol2numberZ
number2symbol�sorted�arcs�items�append�
make_label�index�isfinal�states�
make_first�start)r�c�names�name�i�dfar+�stater%�label�nextr	r	r
�make_grammars.	





",	*zParserGenerator.make_grammarcCsJ|j|}i}x0t|�D]"}|j||�}d||<q W|S)Nr)rr$r()rr.r0Zrawfirstrr4�ilabelr	r	r
r,4s
zParserGenerator.make_firstcCs�t|j�}|dj�r||jkry||jkrH|j|S|jj|j|df�||j|<|Sq�tt|d�}t|t	�s�t
|��|tjks�t
|��||jkr�|j|S|jj|df�||j|<|Sn�|ddks!t
|��t
|�}|dj�r�||jkrW|j|S|jjtj|f�||j|<|SnNtj|}||jkr�|j|S|jj|df�||j|<|SdS)Nr�"�')r8r9)r"Zlabels�isalphar#Zsymbol2labelr'�getattrr�
isinstance�int�AssertionError�tok_name�tokens�eval�keywords�NAMErZopmap)rr.r4r7Zitoken�valuer	r	r
r(=s<




zParserGenerator.make_labelcCsPt|jj��}|j�x*|D]"}||jkr&|j|�q&WdS)N)rrrrr�	calcfirst)rr/r0r	r	r
rks


zParserGenerator.addfirstsetsc	Csc|j|}d|j|<|d}i}i}x�|jj�D]�\}}||jkr�||jkr�|j|}|dkr�td|��n|j|�|j|}|j|�|||<q@d||<|di||<q@Wi}	xa|j�D]S\}}
xD|
D]<}||	kr@td||||	|f��||	|<qWq�W||j|<dS)Nrzrecursion for rule %rrzArule %s is ambiguous; %s is in the first sets of %s as well as %s)rrr%r&�
ValueErrorrE�update)rr0r2r3ZtotalsetZoverlapcheckr4r5�fsetZinverseZitsfirstZsymbolr	r	r
rEss2









zParserGenerator.calcfirstc	Cs�i}d}x�|jtjkr�x |jtjkrC|j�q$W|jtj�}|jtjd�|j�\}}|jtj�|j	||�}t
|�}|j|�t
|�}|||<|dkr|}qW||fS)N�:)�typer�	ENDMARKER�NEWLINEr�expectrC�OP�	parse_rhs�make_dfar"�simplify_dfa)	rrrr0�a�zr2ZoldlenZnewlenr	r	r
r�s"


zParserGenerator.parsecsDt|t�st�t|t�s*t��fdd�}�fdd��t||�|�g}x�|D]�}i}xP|jD]E}x<|jD]1\}}	|dk	r��|	|j|i��q�Wq�Wxmt|j��D]Y\}}
x:|D]}|j|
kr�Pq�Wt|
|�}|j	|�|j
||�q�WqmW|S)Ncsi}�||�|S)Nr	)r3�base)�
addclosurer	r
�closure�s
z)ParserGenerator.make_dfa.<locals>.closurecsft|t�st�||kr%dSd||<x0|jD]%\}}|dkr9�||�q9WdS)Nr)r<�NFAStater>r%)r3rTr4r5)rUr	r
rU�s
z,ParserGenerator.make_dfa.<locals>.addclosure)r<rWr>�DFAState�nfasetr%�
setdefaultr$r&r'�addarc)rr-�finishrVr+r3r%Znfastater4r5rY�str	)rUr
rP�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')
rr0r-r\Ztodor1r3r4r5�jr	r	r
�dump_nfa�s
	"
zParserGenerator.dump_nfacCs�td|�x|t|�D]n\}}td||jr>dpAd�x@t|jj��D])\}}td||j|�f�q[WqWdS)NzDump of DFA forz  Statez(final)r^z    %s -> %d)r_r`r*r$r%r&r))rr0r2r1r3r4r5r	r	r
�dump_dfa�s

"zParserGenerator.dump_dfacCs�d}x�|r�d}x�t|�D]u\}}xft|dt|��D]K}||}||krH||=x|D]}|j||�qrWd}PqHWq"Wq	WdS)NTFr)r`�ranger"�
unifystate)rr2Zchangesr1Zstate_iraZstate_jr3r	r	r
rQ�s	 

zParserGenerator.simplify_dfacCs�|j�\}}|jdkr+||fSt�}t�}|j|�|j|�xI|jdkr�|j�|j�\}}|j|�|j|�qZW||fSdS)N�|)�	parse_altrDrWr[r)rrRrSZaaZzzr	r	r
rO�s
		



zParserGenerator.parse_rhscCsr|j�\}}xS|jdks?|jtjtjfkrg|j�\}}|j|�|}qW||fS)N�(�[)rhri)�
parse_itemrDrJrrC�STRINGr[)rrR�br.�dr	r	r
rg
s

zParserGenerator.parse_altcCs�|jdkrU|j�|j�\}}|jtjd�|j|�||fS|j�\}}|j}|dkr�||fS|j�|j|�|dkr�||fS||fSdS)Nri�]�+�*)rorp)rDrrOrMrrNr[�
parse_atom)rrRrSrDr	r	r
rjs


	



zParserGenerator.parse_itemcCs�|jdkrH|j�|j�\}}|jtjd�||fS|jtjtjfkr�t	�}t	�}|j
||j�|j�||fS|jd|j|j�dS)Nrh�)z+expected (...) or NAME or STRING, got %s/%s)rDrrOrMrrNrJrCrkrWr[�raise_error)rrRrSr	r	r
rq(s

		

	zParserGenerator.parse_atomcCs`|j|ks*|dk	rI|j|krI|jd|||j|j�|j}|j�|S)Nzexpected %s/%s, got %s/%s)rJrDrsr)rrJrDr	r	r
rM9s*		
zParserGenerator.expectcCsit|j�}x/|dtjtjfkr@t|j�}qW|\|_|_|_|_|_	dS)Nr)
r5rr�COMMENT�NLrJrDZbegin�end�line)r�tupr	r	r
rAszParserGenerator.gettokencGsw|rDy||}Wn-dj|gttt|���}YnXt||j|jd|jd|jf��dS)N� rr)�joinr�map�str�SyntaxErrorrrvrw)r�msg�argsr	r	r
rsHs*zParserGenerator.raise_error)rrrrr6r,r(rrErrPrbrcrQrOrgrjrqrMrrsr	r	r	r
r
s$	.$
rc@s+eZdZdd�Zddd�ZdS)rWcCs
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>rWr%r')rr5r4r	r	r
r[Vs!zNFAState.addarc)rrrrr[r	r	r	r
rWQsrWc@sFeZdZdd�Zdd�Zdd�Zdd�Zd	Zd	S)
rXcCspt|t�st�ttt|��t�s6t�t|t�sKt�||_||k|_i|_dS)N)	r<�dictr>r5�iterrWrYr*r%)rrY�finalr	r	r
r]s!	zDFAState.__init__cCsPt|t�st�||jks*t�t|t�s?t�||j|<dS)N)r<r|r>r%rX)rr5r4r	r	r
r[eszDFAState.addarccCs=x6|jj�D]%\}}||kr||j|<qWdS)N)r%r&)r�old�newr4r5r	r	r
rekszDFAState.unifystatecCs�t|t�st�|j|jkr+dSt|j�t|j�krMdSx9|jj�D](\}}||jj|�k	r]dSq]WdS)NFT)r<rXr>r*r"r%r&�get)r�otherr4r5r	r	r
�__eq__pszDFAState.__eq__N)rrrrr[rer��__hash__r	r	r	r
rX[s
rXzGrammar.txtcCst|�}|j�S)N)rr6)r�pr	r	r
�generate_grammar�sr�N)r^rrrZGrammarr�objectrrWrXr�r	r	r	r
�<module>s�H
%