Hacked By AnonymousFox

Current Path : /lib64/python3.8/lib2to3/pgen2/__pycache__/
Upload File :
Current File : //lib64/python3.8/lib2to3/pgen2/__pycache__/pgen.cpython-38.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_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/r5r9Zitoken�valuer	r	r
r)=s<












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'�
ValueErrorrH�update)rr1r3r4ZtotalsetZoverlapcheckr5r6�fsetZinverseZitsfirstZsymbolr	r	r
rHss4








�zParserGenerator.calcfirstc	Cs�i}d}|jtjkr�|jtjkr*|��q|�tj�}|�tjd�|��\}}|�tj�|�	||�}t
|�}|�|�t
|�}|||<|dkr|}q||fS)N�:)�typer�	ENDMARKER�NEWLINEr�expectrF�OP�	parse_rhs�make_dfar#�simplify_dfa)	rrrr1�a�zr3ZoldlenZnewlenr	r	r
r�s"

zParserGenerator.parsec	s�t|t�st�t|t�st��fdd�}�fdd��t||�|�g}|D]�}i}|jD].}|jD]"\}}	|dk	r`�|	|�|i��q`qVt|���D]@\}}
|D]}|j|
kr�q�q�t|
|�}|�	|�|�
||�q�qH|S)Ncsi}�||�|Srr	)r4�base��
addclosurer	r
�closure�s
z)ParserGenerator.make_dfa.<locals>.closurecsHt|t�st�||krdSd||<|jD]\}}|dkr(�||�q(dSr8)r?�NFAStaterAr&)r4rWr5r6rXr	r
rY�sz,ParserGenerator.make_dfa.<locals>.addclosure)r?r[rA�DFAState�nfasetr&�
setdefaultr%r'r(�addarc)rr.�finishrZr,r4r&Znfastater5r6r]�str	rXr
rS�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 forrbrcrdre)rfrgr+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)rg�ranger#�
unifystate)rr3Zchangesr2Zstate_irhZstate_jr4r	r	r
rT�szParserGenerator.simplify_dfacCs~|��\}}|jdkr||fSt�}t�}|�|�|�|�|jdkrr|��|��\}}|�|�|�|�q>||fSdS)N�|)�	parse_altrGr[r_r)rrUrVZaaZzzr	r	r
rR�s




zParserGenerator.parse_rhscCsL|��\}}|jdks(|jtjtjfkrD|��\}}|�|�|}q||fS)N)�(�[)�
parse_itemrGrMrrF�STRINGr_)rrU�br/�dr	r	r
rn
s
�
zParserGenerator.parse_altcCs�|jdkr>|��|��\}}|�tjd�|�|�||fS|��\}}|j}|dkr`||fS|��|�|�|dkr�||fS||fSdS)Nrp�])�+�*rv)rGrrRrPrrQr_�
parse_atom)rrUrVrGr	r	r
rqs


zParserGenerator.parse_itemcCs�|jdkr4|��|��\}}|�tjd�||fS|jtjtjfkrpt	�}t	�}|�
||j�|��||fS|�d|j|j�dS)Nro�)z+expected (...) or NAME or STRING, got %s/%s)rGrrRrPrrQrMrFrrr[r_�raise_error)rrUrVr	r	r
rx(s
�zParserGenerator.parse_atomcCsD|j|ks|dk	r2|j|kr2|�d|||j|j�|j}|��|S)Nzexpected %s/%s, got %s/%s)rMrGrzr)rrMrGr	r	r
rP9s�zParserGenerator.expectcCsFt|j�}|dtjtjfkr*t|j�}q
|\|_|_|_|_|_	dS)Nr)
r6rr�COMMENT�NLrMrGZbegin�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�SyntaxErrorrr}r~)r�msg�argsr	r	r
rzHs �zParserGenerator.raise_error)N)N)rrrrr7r-r)rrHrrSrirjrTrRrnrqrxrPrrzr	r	r	r
r
s$
	.$

rc@seZdZdd�Zddd�ZdS)r[cCs
g|_dSr)r&)rr	r	r
rSszNFAState.__init__NcCs8|dkst|t�st�t|t�s$t�|j�||f�dSr)r?r�rAr[r&r(�rr6r5r	r	r
r_VszNFAState.addarc)N)rrrrr_r	r	r	r
r[Qsr[c@s0eZdZdd�Zdd�Zdd�Zdd�Zd	Zd	S)
r\cCsLt|t�st�ttt|��t�s$t�t|t�s2t�||_||k|_i|_dSr)	r?�dictrAr6�iterr[r]r+r&)rr]�finalr	r	r
r]s
zDFAState.__init__cCs8t|t�st�||jkst�t|t�s*t�||j|<dSr)r?r�rAr&r\r�r	r	r
r_eszDFAState.addarccCs*|j��D]\}}||kr
||j|<q
dSr)r&r')r�old�newr5r6r	r	r
rlkszDFAState.unifystatecCsdt|t�st�|j|jkrdSt|j�t|j�kr6dS|j��D]\}}||j�|�k	r@dSq@dS)NFT)r?r\rAr+r#r&r'�get)r�otherr5r6r	r	r
�__eq__pszDFAState.__eq__N)rrrrr_rlr��__hash__r	r	r	r
r\[s
r\�Grammar.txtcCst|�}|��Sr)rr7)r�pr	r	r
�generate_grammar�sr�N)r�)rdrrrZGrammarr�objectrr[r\r�r	r	r	r
�<module>sI
%

Hacked By AnonymousFox1.0, Coded By AnonymousFox