Mini Shell

Direktori : /opt/alt/python37/lib64/python3.7/lib2to3/pgen2/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/lib2to3/pgen2/__pycache__/pgen.cpython-37.pyc

B

�9�%�h���@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	�7/opt/alt/python37/lib64/python3.7/lib2to3/pgen2/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}||_||_t�|j�|_|��|�	�\|_
|_|dk	rZ|�i|_|�
�dS)N)�open�close�filename�streamr�generate_tokens�readline�	generator�gettoken�parse�dfas�startsymbol�first�addfirstsets)�selfrrZclose_streamr	r	r
�__init__szParserGenerator.__init__c	Cs*t�}t|j���}|��|�|j�|�d|j�x.|D]&}dt|j	�}||j	|<||j
|<q<Wx�|D]�}|j|}g}xl|D]d}g}x6t|j�
��D]$\}	}
|�|�||	�|�|
�f�q�W|jr�|�d|�|�f�|�|�q�W|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]}|�||�}d||<qW|S)Nr)rr$r()rr.r0Zrawfirstrr4�ilabelr	r	r
r,4s
zParserGenerator.make_firstcCsbt|j�}|d��r�||jkrZ||jkr4|j|S|j�|j|df�||j|<|Snbtt|d�}t|t	�sxt
|��|tjks�t
|��||jkr�|j|S|j�|df�||j|<|Sn�|ddks�t
|��t
|�}|d���r ||jk�r�|j|S|j�tj|f�||j|<|Sn>tj|}||jk�r@|j|S|j�|df�||j|<|SdS)Nr)�"�')r"�labels�isalphar#Zsymbol2labelr'�getattrr�
isinstance�int�AssertionError�tok_name�tokens�eval�keywords�NAMErZopmap)rr.r4r7Zitoken�valuer	r	r
r(=s<












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


zParserGenerator.addfirstsetsc	Cs
|j|}d|j|<|d}i}i}x�|j��D]x\}}||jkr�||jkrl|j|}|dkr�td|��n|�|�|j|}|�|�|||<q0d||<|di||<q0Wi}	xJ|��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&�
ValueErrorrF�update)rr0r2r3ZtotalsetZoverlapcheckr4r5�fsetZinverseZitsfirstZsymbolr	r	r
rFss2









zParserGenerator.calcfirstc	Cs�i}d}x�|jtjkr�x|jtjkr.|��qW|�tj�}|�tjd�|��\}}|�tj�|�	||�}t
|�}|�|�t
|�}|||<|dkr
|}q
W||fS)N�:)�typer�	ENDMARKER�NEWLINEr�expectrD�OP�	parse_rhs�make_dfar"�simplify_dfa)	rrrr0�a�zr2ZoldlenZnewlenr	r	r
r�s"
zParserGenerator.parsec	s�t|t�st�t|t�st��fdd�}�fdd��t||�|�g}x�|D]�}i}x<|jD]2}x,|jD]"\}}	|dk	rf�|	|�|i��qfWqZWxRt|���D]B\}}
x,|D]}|j|
kr�Pq�Wt|
|�}|�	|�|�
||�q�WqJW|S)Ncsi}�||�|S)Nr	)r3�base)�
addclosurer	r
�closure�s
z)ParserGenerator.make_dfa.<locals>.closurecsLt|t�st�||krdSd||<x$|jD]\}}|dkr*�||�q*WdS)Nr)r=�NFAStater?r%)r3rUr4r5)rVr	r
rV�sz,ParserGenerator.make_dfa.<locals>.addclosure)r=rXr?�DFAState�nfasetr%�
setdefaultr$r&r'�addarc)rr-�finishrWr+r3r%Znfastater4r5rZ�str	)rVr
rQ�s&




zParserGenerator.make_dfac
Cs�td|�|g}x�t|�D]�\}}td|||kr4dp6d�x^|jD]T\}}||kr^|�|�}	nt|�}	|�|�|dkr�td|	�qBtd||	f�qBWqWdS)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_nfacCsltd|�x\t|�D]P\}}td||jr,dp.d�x0t|j���D]\}}td||�|�f�qBWqWdS)NzDump of DFA forz  Statez(final)r_z    %s -> %d)r`rar*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]}|�||�qTWd}Pq4WqWqWdS)NTFr)ra�ranger"�
unifystate)rr2Zchangesr1Zstate_irbZstate_jr3r	r	r
rR�s
zParserGenerator.simplify_dfacCs�|��\}}|jdkr||fSt�}t�}|�|�|�|�x6|jdkrt|��|��\}}|�|�|�|�q@W||fSdS)N�|)�	parse_altrErXr\r)rrSrTZaaZzzr	r	r
rP�s



zParserGenerator.parse_rhscCsP|��\}}x:|jdks*|jtjtjfkrF|��\}}|�|�|}qW||fS)N)�(�[)�
parse_itemrErKrrD�STRINGr\)rrS�br.�dr	r	r
rh
s
zParserGenerator.parse_altcCs�|jdkr>|��|��\}}|�tjd�|�|�||fS|��\}}|j}|dkr`||fS|��|�|�|dkr�||fS||fSdS)Nrj�])�+�*rp)rErrPrNrrOr\�
parse_atom)rrSrTrEr	r	r
rks


zParserGenerator.parse_itemcCs�|jdkr4|��|��\}}|�tjd�||fS|jtjtjfkrpt	�}t	�}|�
||j�|��||fS|�d|j|j�dS)Nri�)z+expected (...) or NAME or STRING, got %s/%s)rErrPrNrrOrKrDrlrXr\�raise_error)rrSrTr	r	r
rr(s
zParserGenerator.parse_atomcCsD|j|ks|dk	r2|j|kr2|�d|||j|j�|j}|��|S)Nzexpected %s/%s, got %s/%s)rKrErtr)rrKrEr	r	r
rN9szParserGenerator.expectcCsJt|j�}x"|dtjtjfkr,t|j�}qW|\|_|_|_|_|_	dS)Nr)
r5rr�COMMENT�NLrKrEZbegin�end�line)r�tupr	r	r
rAs
zParserGenerator.gettokenc
Gs^|r8y||}Wn&d�|gttt|���}YnXt||j|jd|jd|jf��dS)N� rr)�joinr�map�str�SyntaxErrorrrwrx)r�msg�argsr	r	r
rtHs zParserGenerator.raise_error)N)N)rrrrr6r,r(rrFrrQrcrdrRrPrhrkrrrNrrtr	r	r	r
r
s$
	.$

rc@seZdZdd�Zddd�ZdS)rXcCs
g|_dS)N)r%)rr	r	r
rSszNFAState.__init__NcCs8|dkst|t�st�t|t�s$t�|j�||f�dS)N)r=r}r?rXr%r')rr5r4r	r	r
r\VszNFAState.addarc)N)rrrrr\r	r	r	r
rXQsrXc@s0eZdZdd�Zdd�Zdd�Zdd�Zd	Zd	S)
rYcCsLt|t�st�ttt|��t�s$t�t|t�s2t�||_||k|_i|_dS)N)	r=�dictr?r5�iterrXrZr*r%)rrZ�finalr	r	r
r]s
zDFAState.__init__cCs8t|t�st�||jkst�t|t�s*t�||j|<dS)N)r=r}r?r%rY)rr5r4r	r	r
r\eszDFAState.addarccCs.x(|j��D]\}}||kr||j|<qWdS)N)r%r&)r�old�newr4r5r	r	r
rfkszDFAState.unifystatecCsft|t�st�|j|jkrdSt|j�t|j�kr6dSx*|j��D]\}}||j�|�k	rBdSqBWdS)NFT)r=rYr?r*r"r%r&�get)r�otherr4r5r	r	r
�__eq__pszDFAState.__eq__N)rrrrr\rfr��__hash__r	r	r	r
rY[s
rY�Grammar.txtcCst|�}|��S)N)rr6)r�pr	r	r
�generate_grammar�sr�N)r�)r_rrrZGrammarr�objectrrXrYr�r	r	r	r
�<module>sI
%

Zerion Mini Shell 1.0