Your IP : 52.15.233.83


Current Path : /opt/alt/python34/lib64/python3.4/lib2to3/pgen2/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/lib2to3/pgen2/__pycache__/pgen.cpython-34.pyo

�
j f�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/python34/lib64/python3.4/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}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__cCs�t�}t|jj��}|j�|j|j�|jd|j�x;|D]3}dt|j	�}||j	|<||j
|<qRWx�|D]�}|j|}g}x�|D]�}g}xE|jj�D]4\}	}
|j
|j||	�|j|
�f�q�W|jr,|j
d|j|�f�n|j
|�q�W|jj
|�||j||�f|j|j	|<q�W|j	|j|_|S)N��)r�listr�keys�sort�remover�insert�len�
symbol2numberZ
number2symbol�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_grammarcCsD|j|}i}x*|D]"}|j||�}d||<qW|S)Nr)rr')rr-r/Zrawfirstrr3�ilabelr	r	r
r+4s

zParserGenerator.make_firstcCs�t|j�}|dj�r�||jkry||jkrH|j|S|jj|j|df�||j|<|Sq�tt|d�}||jkr�|j|S|jj|df�||j|<|Sn�t	|�}|dj�r2||j
kr|j
|S|jjtj|f�||j
|<|SnNtj
|}||jkrY|j|S|jj|df�||j|<|SdS)Nr)r"Zlabels�isalphar#Zsymbol2labelr&�getattrr�tokens�eval�keywords�NAMErZopmap)rr-r3r6Zitoken�valuer	r	r
r'=s6




zParserGenerator.make_labelcCsSt|jj��}|j�x-|D]%}||jkr&|j|�q&q&WdS)N)rrrrr�	calcfirst)rr.r/r	r	r
rks


zParserGenerator.addfirstsetsc	Csj|j|}d|j|<|d}i}i}x�|jj�D]�\}}||jkr�||jkr�|j|}|dkr�td|��q�n|j|�|j|}|j|�|||<q@d||<id|6||<q@Wi}	xd|j�D]V\}}
xG|
D]?}||	krGtd||||	|f��n||	|<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%�
ValueErrorr>�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.<locals>.closurecsT||krdSd||<x3|jD](\}}|dkr$�||�q$q$WdS)Nr)r$)r2rMr3r4)rNr	r
rN�s
z,ParserGenerator.make_dfa.<locals>.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|jd|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$	.$
rc@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|<dS)N)r$)rr4r3r	r	r
rSeszDFAState.addarccCs@x9|jj�D](\}}||kr||j|<qqWdS)N)r$r%)r�old�newr3r4r	r	r
r]kszDFAState.unifystatecCsx|j|jkrdSt|j�t|j�kr8dSx9|jj�D](\}}||jj|�k	rHdSqHWdS)NFT)r)r"r$r%�get)r�otherr3r4r	r	r
�__eq__pszDFAState.__eq__N)rrrrrSr]r~�__hash__r	r	r	r
rP[s
rPzGrammar.txtcCst|�}|j�S)N)rr5)r�pr	r	r
�generate_grammar�sr�N)rVrrrZGrammarr�objectrr`rPr�r	r	r	r
�<module>s�H
%

?>