Your IP : 3.14.245.172


Current Path : /lib64/python3.8/lib2to3/pgen2/__pycache__/
Upload File :
Current File : //lib64/python3.8/lib2to3/pgen2/__pycache__/pgen.cpython-38.opt-2.pyc

U

e5d�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	�*/usr/lib64/python3.8/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	Cst�}t|j���}|��|�|j�|�d|j�|D]&}dt|j	�}||j	|<||j
|<q:|D]�}|j|}g}|D]`}g}t|j�
��D]$\}	}
|�|�||	�|�|
�f�q�|jr�|�d|�|�f�|�|�q||j�|�||�||�f|j|j	|<qf|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_grammarcCs4|j|}i}t|�D]}|�||�}d||<q|S�Nr)rr%r))rr/r1Zrawfirstrr5�ilabelr	r	r
r-4s

zParserGenerator.make_firstcCs&t|j�}|d��r�||jkrZ||jkr4|j|S|j�|j|df�||j|<|Sn>tt|d�}||jkrz|j|S|j�|df�||j|<|Sn�t	|�}|d��r�||j
kr�|j
|S|j�tj|f�||j
|<|Sn>tj
|}||jk�r|j|S|j�|df�||j|<|SdS�Nr)r#�labels�isalphar$Zsymbol2labelr(�getattrr�tokens�eval�keywords�NAMErZopmap)rr/r5r9Zitoken�valuer	r	r
r)=s6













zParserGenerator.make_labelcCs8t|j���}|��|D]}||jkr|�|�qdSr)rrrr r�	calcfirst)rr0r1r	r	r
rks

zParserGenerator.addfirstsetsc	Cs�|j|}d|j|<|d}i}i}|j��D]x\}}||jkr�||jkrj|j|}|dkr~td|��n|�|�|j|}|�|�|||<q.d||<|di||<q.i}	|��D]:\}}
|
D],}||	kr�td||||	|f��||	|<q�q�||j|<dS)Nrzrecursion for rule %rrzArule %s is ambiguous; %s is in the first sets of %s as well as %s)rrr&r'�
ValueErrorrC�update)rr1r3r4ZtotalsetZoverlapcheckr5r6�fsetZinverseZitsfirstZsymbolr	r	r
rCss4








�zParserGenerator.calcfirstc	Cs�i}d}|jtjkr�|jtjkr*|��q|�tj�}|�tjd�|��\}}|�tj�|�	||�}t
|�}|�|�t
|�}|||<|dkr|}q||fS)N�:)�typer�	ENDMARKER�NEWLINEr�expectrA�OP�	parse_rhs�make_dfar#�simplify_dfa)	rrrr1�a�zr3ZoldlenZnewlenr	r	r
r�s"

zParserGenerator.parsec	s��fdd�}�fdd��t||�|�g}|D]�}i}|jD].}|jD]"\}}	|dk	rD�|	|�|i��qDq:t|���D]@\}}
|D]}|j|
kr�q�q�t|
|�}|�|�|�||�qvq,|S)Ncsi}�||�|Srr	)r4�base��
addclosurer	r
�closure�s
z)ParserGenerator.make_dfa.<locals>.closurecs:||krdSd||<|jD]\}}|dkr�||�qdSr8�r&)r4rRr5r6rSr	r
rT�sz,ParserGenerator.make_dfa.<locals>.addclosure)�DFAState�nfasetr&�
setdefaultr%r'r(�addarc)rr.�finishrUr,r4r&Znfastater5r6rX�str	rSr
rN�s"



zParserGenerator.make_dfac
Cs�td|�|g}t|�D]|\}}td|||kr2dp4d�|jD]T\}}||krZ|�|�}	nt|�}	|�|�|dkr�td|	�q>td||	f�q>qdS)NzDump of NFA for�  State�(final)�z	    -> %d�    %s -> %d)�print�	enumerater&r*r#r()
rr1r.r[Ztodor2r4r5r6�jr	r	r
�dump_nfa�s

zParserGenerator.dump_nfacCsdtd|�t|�D]L\}}td||jr*dp,d�t|j���D]\}}td||�|�f�q>qdS)NzDump of DFA forr]r^r_r`)rarbr+r%r&r'r*)rr1r3r2r4r5r6r	r	r
�dump_dfa�s

zParserGenerator.dump_dfacCspd}|rld}t|�D]T\}}t|dt|��D]8}||}||kr.||=|D]}|�||�qLd}qq.qqdS)NTFr)rb�ranger#�
unifystate)rr3Zchangesr2Zstate_ircZstate_jr4r	r	r
rO�szParserGenerator.simplify_dfacCs~|��\}}|jdkr||fSt�}t�}|�|�|�|�|jdkrr|��|��\}}|�|�|�|�q>||fSdS)N�|)�	parse_altrB�NFAStaterZr)rrPrQZaaZzzr	r	r
rM�s




zParserGenerator.parse_rhscCsL|��\}}|jdks(|jtjtjfkrD|��\}}|�|�|}q||fS)N)�(�[)�
parse_itemrBrHrrA�STRINGrZ)rrP�br/�dr	r	r
ri
s
�
zParserGenerator.parse_altcCs�|jdkr>|��|��\}}|�tjd�|�|�||fS|��\}}|j}|dkr`||fS|��|�|�|dkr�||fS||fSdS)Nrl�])�+�*rr)rBrrMrKrrLrZ�
parse_atom)rrPrQrBr	r	r
rms


zParserGenerator.parse_itemcCs�|jdkr4|��|��\}}|�tjd�||fS|jtjtjfkrpt	�}t	�}|�
||j�|��||fS|�d|j|j�dS)Nrk�)z+expected (...) or NAME or STRING, got %s/%s)rBrrMrKrrLrHrArnrjrZ�raise_error)rrPrQr	r	r
rt(s
�zParserGenerator.parse_atomcCsD|j|ks|dk	r2|j|kr2|�d|||j|j�|j}|��|S)Nzexpected %s/%s, got %s/%s)rHrBrvr)rrHrBr	r	r
rK9s�zParserGenerator.expectcCsFt|j�}|dtjtjfkr*t|j�}q
|\|_|_|_|_|_	dSr:)
r6rr�COMMENT�NLrHrBZbegin�end�line)r�tupr	r	r
rAs
zParserGenerator.gettokenc
Gs^|r8z||}Wn&d�|gttt|���}YnXt||j|jd|jd|jf��dS)N� rr)�joinr�map�str�SyntaxErrorrryrz)r�msg�argsr	r	r
rvHs �zParserGenerator.raise_error)N)N)rrrrr7r-r)rrCrrNrdrerOrMrirmrtrKrrvr	r	r	r
r
s$
	.$

rc@seZdZdd�Zddd�ZdS)rjcCs
g|_dSrrV)rr	r	r
rSszNFAState.__init__NcCs|j�||f�dSr)r&r(�rr6r5r	r	r
rZVszNFAState.addarc)N)rrrrrZr	r	r	r
rjQsrjc@s0eZdZdd�Zdd�Zdd�Zdd�Zd	Zd	S)
rWcCs||_||k|_i|_dSr)rXr+r&)rrX�finalr	r	r
r]s
zDFAState.__init__cCs||j|<dSrrVr�r	r	r
rZeszDFAState.addarccCs*|j��D]\}}||kr
||j|<q
dSr)r&r')r�old�newr5r6r	r	r
rgkszDFAState.unifystatecCsV|j|jkrdSt|j�t|j�kr(dS|j��D]\}}||j�|�k	r2dSq2dS)NFT)r+r#r&r'�get)r�otherr5r6r	r	r
�__eq__pszDFAState.__eq__N)rrrrrZrgr��__hash__r	r	r	r
rW[s
rW�Grammar.txtcCst|�}|��Sr)rr7)r�pr	r	r
�generate_grammar�sr�N)r�)r_rrrZGrammarr�objectrrjrWr�r	r	r	r
�<module>sI
%

?>