
    -Ph'                        d Z ddlZddlmZ ddlmZ ddlmZ ej        rddlm	Z	m
Z
 ddlmZ nddlm	Z	m
Z
 ddlmZ ddZej        d	ed
efd            Zej        de	d
efd            Zej        d	ede	fd            Z G d d          ZdS )z0
Python Lexical Analyser

Converting NFA to DFA
    N   )Machines)LOWEST_PRIORITY)TransitionMap)NodeFastMachinec           	         t          j                    }t          |          }| j                                        D ]=\  }}|                    t          |                    }|                    ||           >|j        D ]}t                      }|
                    |          D ]H}|j                                        D ],\  }}	|r%|	r#|                    |t          |	                     -I|                                D ]/\  }}
|                    |||                    |
                     0|r*|                    d           |                    |           |S )zg
    Given a nondeterministic Machine, return a new equivalent
    Machine which is deterministic.
    z
===== State Mapping =====
)r   r   StateMapinitial_statesitems
old_to_newepsilon_closuremake_initial_statestatesr   
new_to_oldtransitionsadd_setset_epsilon_closureadd_transitionswritedump)old_machinedebugnew_machine	state_mapkey	old_state	new_stater   eventold_target_states
old_statess              O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/Cython/Plex/DFA.py
nfa_to_dfar#      s     (355K";//I
 (6<<>> 7 7i(()C)CDD	&&sI6666 !' \ \	#oo"--i88 	W 	WI,5,A,G,G,I,I W W(( W. W''/BCT/U/UVVVW "-!2!2!4!4 	\ 	\E:''	5):N:Nz:Z:Z[[[[	\  3444u    	state_setreturnc                 z    t                      }| D ])}t          |          D ]}|                    |           *|S )zc
    Given a set of states, return the union of the epsilon
    closures of its member states.
    )setr   add)r%   resultstate1state2s       r"   r   r   ?   sR     UUF  %f-- 	 	FJJv	Mr$   statec                 b    | j         }|%t                      }|| _         t          ||            |S )zW
    Return the set of states reachable from the given state
    by epsilon moves.
    )r   r(   add_to_epsilon_closure)r-   r*   s     r"   r   r   L   s7     "F~ &vu---Mr$   c                     || vrE|                      |           |j                                        }|r|D ]}t          | |           dS dS dS )zd
    Recursively add to |state_set| states reachable from the given state
    by epsilon moves.
    N)r)   r   get_epsilonr/   )r%   r-   state_set_2r,   s       r"   r/   r/   [   s{     Ie'3355 	:% : :&y&9999 	: 	:: :r$   c                   H    e Zd ZdZd ZdefdZdefdZd ZdefdZ	d	 Z
d
S )r
   z
    Helper class used by nfa_to_dfa() to map back and forth between
    sets of states from the old machine and states of the new machine.
    c                 0    || _         i | _        i | _        d S N)r   old_to_new_dictnew_to_old_dict)selfr   s     r"   __init__zStateMap.__init__r   s     &!!r$   old_state_setc                 
   |                      |          }| j                            |d          }|sP|                     |          }| j                            |          }|| j        |<   || j        t          |          <   |S )aX  
        Return the state of the new machine corresponding to the
        set of old machine states represented by |state_set|. A new
        state will be created if necessary. If any of the old states
        are accepting states, the new state will be an accepting state
        with the highest priority action from the old states.
        N)make_keyr6   gethighest_priority_actionr   r   r7   id)r8   r:   r   r   actions        r"   r   zStateMap.old_to_neww   s     mmM**(,,S$77	 	@11-@@F(226::I(1D %2?D I/r$   r%   c                 N    d }t           }|D ]}|j        }||k    r	|j        }|}|S r5   )r   action_priorityr@   )r8   r%   best_actionbest_priorityr-   prioritys         r"   r>   z StateMap.highest_priority_action   sA    ' 	) 	)E,H-''#l (r$   c                 6    | j         t          |                   S )z<Given a new state, return a set of corresponding old states.)r7   r?   )r8   r   s     r"   r   zStateMap.new_to_old   s    #ByMM22r$   c                 :    t          t          |                    S )zv
        Convert a set of states into a uniquified
        sorted tuple suitable for use as a dictionary key.
        )tuplesorted)r8   r%   s     r"   r<   zStateMap.make_key   s    
 VI&&'''r$   c           	          ddl m} | j        j        D ]G}| j        t          |                   }|                    d|d         d ||          d           Hd S )Nr   )state_set_strz	   State numberz <-- 
)TransitionsrK   r   r   r7   r?   r   )r8   filerK   r   r:   s        r"   r   zStateMap.dump   s    ......)0 	D 	DI 0I?MJJJ(###]]=%A%A%A%AC D D D D	D 	Dr$   N)__name__
__module____qualname____doc__r9   r(   r   r>   r   r<   r    r$   r"   r
   r
   l   s         
" " "
    "	 	 	 	 	3 3 3(# ( ( ( (D D D D Dr$   r
   r5   )rS   cython r   r   rN   r   compiled$cython.cimports.Cython.Plex.Machinesr   r   'cython.cimports.Cython.Plex.Transitionstype_TransitionMapCython.Plex.MachinesCython.Plex.Transitionsr#   cfuncr(   r   r   r/   r
   rT   r$   r"   <module>r^      s           % % % % % % & & & & & &	? LFFFFFFFF[[[[[[[66666666KKKKKK' ' ' 'T 	3 	3 	 	 	 	 4 C     :c :$ : : : : 8D 8D 8D 8D 8D 8D 8D 8D 8D 8Dr$   