Your IP : 3.144.18.59


Current Path : /opt/alt/python36/lib64/python3.6/lib2to3/pgen2/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/lib2to3/pgen2/__pycache__/pgen.cpython-36.opt-2.pyc

3

��2a�5�@sdddlmZmZmZGdd�dej�ZGdd�de�ZGdd�de�ZGdd	�d	e�Z	ddd�Z
d
S)�)�grammar�token�tokenizec@seZdZdS)�PgenGrammarN)�__name__�
__module__�__qualname__�r	r	�)/opt/alt/python36/lib64/python3.6/pgen.pyrsrc@s�eZdZd&dd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd'd d!�Zd"d#�Zd$d%�ZdS)(�ParserGeneratorNcCsld}|dkrt|�}|j}||_||_tj|j�|_|j�|j	�\|_
|_|dk	rZ|�i|_|j
�dS)N)�open�close�filename�streamr�generate_tokens�readline�	generator�gettoken�parse�dfas�startsymbol�first�addfirstsets)�selfrrZclose_streamr	r	r
�__init__szParserGenerator.__init__cCs*t�}t|jj��}|j�|j|j�|jd|j�x.|D]&}dt|j	�}||j	|<||j
|<q<Wx�|D]�}|j|}g}xl|D]d}g}x6t|jj
��D]$\}	}
|j|j||	�|j|
�f�q�W|jr�|jd|j|�f�|j|�q�W|jj|�||j||�f|j|j	|<qlW|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_grammarcCs8|j|}i}x$t|�D]}|j||�}d||<qW|S)Nr)rr$r()rr.r0Zrawfirstrr4�ilabelr	r	r
r,4s
zParserGenerator.make_firstcCs&t|j�}|dj�r�||jkrZ||jkr4|j|S|jj|j|df�||j|<|Sn>tt|d�}||jkrz|j|S|jj|df�||j|<|Sn�t	|�}|dj�r�||j
kr�|j
|S|jjtj|f�||j
|<|Sn>tj
|}||jk�r|j|S|jj|df�||j|<|SdS)Nr)r"Zlabels�isalphar#Zsymbol2labelr'�getattrr�tokens�eval�keywords�NAMErZopmap)rr.r4r7Zitoken�valuer	r	r
r(=s6













zParserGenerator.make_labelcCs<t|jj��}|j�x |D]}||jkr|j|�qWdS)N)rrrrr�	calcfirst)rr/r0r	r	r
rks


zParserGenerator.addfirstsetsc	Cs
|j|}d|j|<|d}i}i}x�|jj�D]x\}}||jkr�||jkrl|j|}|dkr�td|��n|j|�|j|}|j|�|||<q0d||<|di||<q0Wi}	xJ|j�D]>\}}
x4|
D],}||	kr�td||||	|f��||	|<q�Wq�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)rr0r2r3ZtotalsetZoverlapcheckr4r5�fsetZinverseZitsfirst�symbolr	r	r
r?ss2









zParserGenerator.calcfirstc	Cs�i}d}x�|jtjkr�x|jtjkr.|j�qW|jtj�}|jtjd�|j�\}}|jtj�|j	||�}t
|�}|j|�t
|�}|||<|dkr
|}q
W||fS)N�:)�typer�	ENDMARKER�NEWLINEr�expectr=�OP�	parse_rhs�make_dfar"�simplify_dfa)	rrrr0�a�zr2ZoldlenZnewlenr	r	r
r�s"
zParserGenerator.parsecs��fdd�}�fdd��t||�|�g}x�|D]�}i}x<|jD]2}x,|jD]"\}}	|dk	rJ�|	|j|i��qJWq>WxRt|j��D]B\}}
x,|D]}|j|
kr�Pq�Wt|
|�}|j|�|j||�q�Wq.W|S)Ncsi}�||�|S)Nr	)r3�base)�
addclosurer	r
�closure�s
z)ParserGenerator.make_dfa.<locals>.closurecs>||krdSd||<x$|jD]\}}|dkr�||�qWdS)Nr)r%)r3rOr4r5)rPr	r
rP�sz,ParserGenerator.make_dfa.<locals>.addclosure)�DFAState�nfasetr%�
setdefaultr$r&r'�addarc)rr-�finishrQr+r3r%Znfastater4r5rS�str	)rPr
rK�s"




zParserGenerator.make_dfac
Cs�td|�|g}x�t|�D]�\}}td|||kr4dp6d�x^|jD]T\}}||kr^|j|�}	nt|�}	|j|�|dkr�td|	�qBtd||	f�qBWqWdS)NzDump of NFA forz  Statez(final)�z	    -> %dz    %s -> %d)�print�	enumerater%r)r"r')
rr0r-rVZtodor1r3r4r5�jr	r	r
�dump_nfa�s

zParserGenerator.dump_nfacCsltd|�x\t|�D]P\}}td||jr,dp.d�x0t|jj��D]\}}td||j|�f�qBWqWdS)NzDump of DFA forz  Statez(final)rXz    %s -> %d)rYrZr*r$r%r&r))rr0r2r1r3r4r5r	r	r
�dump_dfa�s

zParserGenerator.dump_dfacCs~d}xt|rxd}xft|�D]Z\}}xPt|dt|��D]:}||}||kr4||=x|D]}|j||�qTWd}Pq4WqWqWdS)NTFr)rZ�ranger"�
unifystate)rr2Zchangesr1Zstate_ir[Zstate_jr3r	r	r
rL�s
zParserGenerator.simplify_dfacCs�|j�\}}|jdkr||fSt�}t�}|j|�|j|�x6|jdkrt|j�|j�\}}|j|�|j|�q@W||fSdS)N�|)�	parse_altr>�NFAStaterUr)rrMrNZaaZzzr	r	r
rJ�s



zParserGenerator.parse_rhscCsP|j�\}}x:|jdks*|jtjtjfkrF|j�\}}|j|�|}qW||fS)N�(�[)rcrd)�
parse_itemr>rErr=�STRINGrU)rrM�br.�dr	r	r
ra
s
zParserGenerator.parse_altcCs�|jdkr>|j�|j�\}}|jtjd�|j|�||fS|j�\}}|j}|dkr`||fS|j�|j|�|dkr�||fS||fSdS)Nrd�]�+�*)rjrk)r>rrJrHrrIrU�
parse_atom)rrMrNr>r	r	r
res


zParserGenerator.parse_itemcCs�|jdkr4|j�|j�\}}|jtjd�||fS|jtjtjfkrpt	�}t	�}|j
||j�|j�||fS|jd|j|j�dS)Nrc�)z+expected (...) or NAME or STRING, got %s/%s)r>rrJrHrrIrEr=rfrbrU�raise_error)rrMrNr	r	r
rl(s
zParserGenerator.parse_atomcCsD|j|ks|dk	r2|j|kr2|jd|||j|j�|j}|j�|S)Nzexpected %s/%s, got %s/%s)rEr>rnr)rrEr>r	r	r
rH9szParserGenerator.expectcCsJt|j�}x"|dtjtjfkr,t|j�}qW|\|_|_|_|_|_	dS)Nr)
r5rr�COMMENT�NLrEr>Zbegin�end�line)r�tupr	r	r
rAs
zParserGenerator.gettokencGs^|r8y||}Wn&dj|gttt|���}YnXt||j|jd|jd|jf��dS)N� rr)�joinr�map�str�SyntaxErrorrrqrr)r�msg�argsr	r	r
rnHs zParserGenerator.raise_error)N)N)rrrrr6r,r(rr?rrKr\r]rLrJrarerlrHrrnr	r	r	r
r
s$
	.$

rc@seZdZdd�Zddd�ZdS)rbcCs
g|_dS)N)r%)rr	r	r
rSszNFAState.__init__NcCs|jj||f�dS)N)r%r')rr5r4r	r	r
rUVszNFAState.addarc)N)rrrrrUr	r	r	r
rbQsrbc@s0eZdZdd�Zdd�Zdd�Zdd�Zd	Zd	S)
rRcCs||_||k|_i|_dS)N)rSr*r%)rrS�finalr	r	r
r]s
zDFAState.__init__cCs||j|<dS)N)r%)rr5r4r	r	r
rUeszDFAState.addarccCs.x(|jj�D]\}}||kr||j|<qWdS)N)r%r&)r�old�newr4r5r	r	r
r_kszDFAState.unifystatecCsX|j|jkrdSt|j�t|j�kr(dSx*|jj�D]\}}||jj|�k	r4dSq4WdS)NFT)r*r"r%r&�get)r�otherr4r5r	r	r
�__eq__pszDFAState.__eq__N)rrrrrUr_r��__hash__r	r	r	r
rR[s
rR�Grammar.txtcCst|�}|j�S)N)rr6)r�pr	r	r
�generate_grammar�sr�N)r�)rXrrrZGrammarr�objectrrbrRr�r	r	r	r
�<module>sI
%

?>