
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
ÁÌ]ó  ã               @   s€   d dl Z d dlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
 ddlmZ G dd	„ d	eƒZed
kr|d dlZd dlZd dlZdS )é    N)Úyaccé   )Úc_ast)ÚCLexer)Ú	PLYParserÚCoordÚ
ParseError)Úfix_switch_casesc               @   sD  e Zd Z�dCdd„Z�dDd	d
„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Z�dEd%d&„Zd'd(„ Zd)d*„ Z�dPZd>d?„ Zd@dA„ ZdBdC„ ZdDdE„ ZdFdG„ ZdHdI„ ZdJdK„ ZdLdM„ ZdNdO„ ZdPdQ„ ZdRdS„ Z dTdU„ Z!dVdW„ Z"dXdY„ Z#dZd[„ Z$d\d]„ Z%d^d_„ Z&d`da„ Z'dbdc„ Z(ddde„ Z)dfdg„ Z*dhdi„ Z+djdk„ Z,dldm„ Z-dndo„ Z.dpdq„ Z/drds„ Z0dtdu„ Z1dvdw„ Z2dxdy„ Z3dzd{„ Z4d|d}„ Z5d~d„ Z6d€d�„ Z7d‚dƒ„ Z8d„d…„ Z9d†d‡„ Z:dˆd‰„ Z;dŠd‹„ Z<dŒd�„ Z=dŽd�„ Z>d�d‘„ Z?d’d“„ Z@d”d•„ ZAd–d—„ ZBd˜d™„ ZCdšd›„ ZDdœd�„ ZEdždŸ„ ZFd d¡„ ZGd¢d£„ ZHd¤d¥„ ZId¦d§„ ZJd¨d©„ ZKdªd«„ ZLd¬d­„ ZMd®d¯„ ZNd°d±„ ZOd²d³„ ZPd´dµ„ ZQd¶d·„ ZRd¸d¹„ ZSdºd»„ ZTd¼d½„ ZUd¾d¿„ ZVdÀdÁ„ ZWdÂdÃ„ ZXdÄdÅ„ ZYdÆdÇ„ ZZdÈdÉ„ Z[dÊdË„ Z\dÌdÍ„ Z]dÎdÏ„ Z^dÐdÑ„ Z_dÒdÓ„ Z`dÔdÕ„ ZadÖd×„ ZbdØdÙ„ ZcdÚdÛ„ ZddÜdÝ„ ZedÞdß„ Zfdàdá„ Zgdâdã„ Zhdädå„ Zidædç„ Zjdèdé„ Zkdêdë„ Zldìdí„ Zmdîdï„ Zndðdñ„ Zodòdó„ Zpdôdõ„ Zqdöd÷„ Zrdødù„ Zsdúdû„ Ztdüdý„ Zudþdÿ„ Zv�d �d„ Zw�d�d„ Zx�d�d„ Zy�d�d„ Zz�d�d	„ Z{�d
�d„ Z|�d�d„ Z}�d�d„ Z~�d�d„ Z�d�d„ Z€�d�d„ Z��d�d„ Z‚�d�d„ Zƒ�d�d„ Z„�d�d„ Z…�d�d„ Z†�d �d!„ Z‡�d"�d#„ Zˆ�d$�d%„ Z‰�d&�d'„ ZŠ�d(�d)„ Z‹�d*�d+„ ZŒ�d,�d-„ Z��d.�d/„ ZŽ�d0�d1„ Z��d2�d3„ Z��d4�d5„ Z‘�d6�d7„ Z’�d8�d9„ Z“�d:�d;„ Z”�d<�d=„ Z•�d>�d?„ Z–�d@�dA„ Z—�dBS (Q  ÚCParserTúpycparser.lextabúpycparser.yacctabFÚ c       	      C   sš   t | j| j| j| jd�| _| jj|||d� | jj| _ddddddd	d
ddddddg}x|D ]}| j|ƒ q\W t	j	| d||||d�| _
tƒ g| _d| _dS )aŽ   Create a new CParser.

            Some arguments for controlling the debug/optimization
            level of the parser are provided. The defaults are
            tuned for release/performance mode.
            The simple rules for using them are:
            *) When tweaking CParser/CLexer, set these to False
            *) When releasing a stable parser, set to True

            lex_optimize:
                Set to False when you're modifying the lexer.
                Otherwise, changes in the lexer won't be used, if
                some lextab.py file exists.
                When releasing with a stable lexer, set to True
                to save the re-generation of the lexer table on
                each run.

            lextab:
                Points to the lex table that's used for optimized
                mode. Only if you're modifying the lexer and want
                some tests to avoid re-generating the table, make
                this point to a local lex table file (that's been
                earlier generated with lex_optimize=True)

            yacc_optimize:
                Set to False when you're modifying the parser.
                Otherwise, changes in the parser won't be used, if
                some parsetab.py file exists.
                When releasing with a stable parser, set to True
                to save the re-generation of the parser table on
                each run.

            yacctab:
                Points to the yacc table that's used for optimized
                mode. Only if you're modifying the parser, make
                this point to a local yacc table file

            yacc_debug:
                Generate a parser.out file that explains how yacc
                built the parsing table from the grammar.

            taboutputdir:
                Set this parameter to control the location of generated
                lextab and yacctab files.
        )Z
error_funcZon_lbrace_funcZon_rbrace_funcZtype_lookup_func)ÚoptimizeÚlextabÚ	outputdirZabstract_declaratorZassignment_expressionZdeclaration_listZdeclaration_specifiersZdesignationZ
expressionZidentifier_listZinit_declarator_listZinitializer_listZparameter_type_listZspecifier_qualifier_listZblock_item_listZtype_qualifier_listZstruct_declarator_listZtranslation_unit_or_empty)ÚmoduleÚstartÚdebugr   Z	tabmoduler   N)r   Ú_lex_error_funcÚ_lex_on_lbrace_funcÚ_lex_on_rbrace_funcÚ_lex_type_lookup_funcÚclexZbuildÚtokensZ_create_opt_ruler   ÚcparserÚdictÚ_scope_stackÚ_last_yielded_token)	ÚselfZlex_optimizer   Zyacc_optimizeZyacctabZ
yacc_debugZtaboutputdirZrules_with_optZrule© r   ú/usr/lib/python3.6/c_parser.pyÚ__init__   sF    5




zCParser.__init__r   c             C   s6   || j _| j jƒ  tƒ g| _d| _| jj|| j |d�S )a&   Parses C code and returns an AST.

            text:
                A string containing the C source code

            filename:
                Name of the file being parsed (for meaningful
                error messages)

            debuglevel:
                Debug level to yacc
        N)ÚinputZlexerr   )r   ÚfilenameZreset_linenor   r   r   r   Úparse)r   Útextr#   Z
debuglevelr   r   r    r$   ~   s    

zCParser.parsec             C   s   | j jtƒ ƒ d S )N)r   Úappendr   )r   r   r   r    Ú_push_scope–   s    zCParser._push_scopec             C   s    t | jƒdkst‚| jjƒ  d S )Nr   )Úlenr   ÚAssertionErrorÚpop)r   r   r   r    Ú
_pop_scope™   s    zCParser._pop_scopec             C   s4   | j d j|dƒs"| jd| |ƒ d| j d |< dS )zC Add a new typedef name (ie a TYPEID) to the current scope
        r   Tz;Typedef %r previously declared as non-typedef in this scopeNéÿÿÿÿr,   )r   ÚgetÚ_parse_error)r   ÚnameÚcoordr   r   r    Ú_add_typedef_name�   s
    
zCParser._add_typedef_namec             C   s4   | j d j|dƒr"| jd| |ƒ d| j d |< dS )ze Add a new object, function, or enum member name (ie an ID) to the
            current scope
        r   Fz;Non-typedef %r previously declared as typedef in this scopeNr,   r,   )r   r-   r.   )r   r/   r0   r   r   r    Ú_add_identifier¦   s
    
zCParser._add_identifierc             C   s.   x(t | jƒD ]}|j|ƒ}|dk	r|S qW dS )z8 Is *name* a typedef-name in the current scope?
        NF)Úreversedr   r-   )r   r/   ZscopeZin_scoper   r   r    Ú_is_type_in_scope°   s
    
 zCParser._is_type_in_scopec             C   s   | j || j||ƒƒ d S )N)r.   Ú_coord)r   ÚmsgÚlineÚcolumnr   r   r    r   º   s    zCParser._lex_error_funcc             C   s   | j ƒ  d S )N)r'   )r   r   r   r    r   ½   s    zCParser._lex_on_lbrace_funcc             C   s   | j ƒ  d S )N)r+   )r   r   r   r    r   À   s    zCParser._lex_on_rbrace_funcc             C   s   | j |ƒ}|S )z§ Looks up types that were previously defined with
            typedef.
            Passed to the lexer for recognizing identifiers that
            are types.
        )r4   )r   r/   Zis_typer   r   r    r   Ã   s    
zCParser._lex_type_lookup_funcc             C   s   | j jS )z§ We need access to yacc's lookahead token in certain cases.
            This is the last token yacc requested from the lexer, so we
            ask the lexer.
        )r   Z
last_token)r   r   r   r    Ú_get_yacc_lookahead_tokenÌ   s    z!CParser._get_yacc_lookahead_tokenc             C   sd   |}|}x|j r|j }q
W t|tjƒr0||_ |S |}xt|j tjƒsL|j }q6W |j |_ ||_ |S dS )z  Tacks a type modifier on a declarator, and returns
            the modified declarator.

            Note: the declarator and modifier may be modified
        N)ÚtypeÚ
isinstancer   ÚTypeDecl)r   ÚdeclÚmodifierZmodifier_headZmodifier_tailZ	decl_tailr   r   r    Ú_type_modify_declõ   s    

zCParser._type_modify_declc             C   sÆ   |}xt |tjƒs|j}qW |j|_|j|_x>|D ]6}t |tjƒs2t|ƒdkr^| j	d|j
ƒ q2||_|S q2W |s¢t |jtjƒsŒ| j	d|j
ƒ tjdg|j
d�|_n tjdd„ |D ƒ|d j
d�|_|S )	z- Fixes a declaration. Modifies decl.
        r   z Invalid multiple types specifiedzMissing type in declarationÚint)r0   c             S   s   g | ]}|j D ]}|‘qqS r   )Únames)Ú.0Úidr/   r   r   r    ú
<listcomp>U  s    z/CParser._fix_decl_name_type.<locals>.<listcomp>r   )r;   r   r<   r:   Údeclnamer/   ÚqualsÚIdentifierTyper(   r.   r0   ÚFuncDecl)r   r=   Útypenamer:   Ztnr   r   r    Ú_fix_decl_name_type,  s.    


zCParser._fix_decl_name_typec             C   s(   |pt g g g g d�}|| jd|ƒ |S )aõ   Declaration specifiers are represented by a dictionary
            with the entries:
            * qual: a list of type qualifiers
            * storage: a list of storage type qualifiers
            * type: a list of type specifiers
            * function: a list of function specifiers

            This method is given a declaration specifier, and a
            new specifier of a given kind.
            Returns the declaration specifier, with the new
            specifier incorporated.
        )ÚqualÚstorager:   Úfunctionr   )r   Úinsert)r   ZdeclspecZnewspecZkindÚspecr   r   r    Ú_add_declaration_specifierY  s    z"CParser._add_declaration_specifierc             C   sR  d|d k}g }|d j dƒdk	r&�n4|d d dkrèt|d ƒdk svt|d d jƒd	ksv| j|d d jd ƒ rªd
}x"|d D ]}t|dƒr„|j}P q„W | jd|ƒ tj|d d jd dd|d d jd�|d d< |d d= nrt	|d d tj
tjtjfƒ�sZ|d d }xt	|tjƒ�s.|j}�qW |jdk�rZ|d d jd |_|d d= xò|D ]ê}	|	d dk	�svt‚|�r¤tjd|d |d |	d |	d jd�}
n<tjd|d |d |d |	d |	j dƒ|	j dƒ|	d jd�}
t	|
jtj
tjtjfƒ�r |
}n| j|
|d ƒ}|�r>|�r.| j|j|jƒ n| j|j|jƒ |j|ƒ �q`W |S )zÿ Builds a list of declarations all sharing the given specifiers.
            If typedef_namespace is true, each declared name is added
            to the "typedef namespace", which also includes objects,
            functions, and enum constants.
        ÚtypedefrL   r   ÚbitsizeNr=   r:   é   r   ú?r0   zInvalid declaration)rE   r:   rF   r0   rK   )r/   rF   rL   r:   r0   rM   Úinit)r/   rF   rL   Úfuncspecr:   rU   rR   r0   r,   r,   r,   r,   r,   r,   r,   )r-   r(   rA   r4   Úhasattrr0   r.   r   r<   r;   ÚStructÚUnionrG   r:   rE   r)   ZTypedefÚDeclrJ   r1   r/   r2   r&   )r   rO   ÚdeclsÚtypedef_namespaceZ
is_typedefZdeclarationsr0   ÚtZdecls_0_tailr=   ÚdeclarationZ
fixed_declr   r   r    Ú_build_declarationsj  sn    &


zCParser._build_declarationsc             C   sB   d|d kst ‚| j|t|dd�gdd�d }tj||||jd�S )	z' Builds a function definition.
        rQ   rL   N)r=   rU   T)rO   r[   r\   r   )r=   Úparam_declsÚbodyr0   )r)   r_   r   r   ZFuncDefr0   )r   rO   r=   r`   ra   r^   r   r   r    Ú_build_function_definitionÃ  s    z"CParser._build_function_definitionc             C   s   |dkrt jS t jS dS )z` Given a token (either STRUCT or UNION), selects the
            appropriate AST class.
        ÚstructN)r   rX   rY   )r   Útokenr   r   r    Ú_select_struct_union_classÓ  s    z"CParser._select_struct_union_classÚleftÚLORÚLANDÚORÚXORÚANDÚEQÚNEÚGTÚGEÚLTÚLEÚRSHIFTÚLSHIFTÚPLUSÚMINUSÚTIMESÚDIVIDEÚMODc             C   s2   |d dkrt jg ƒ|d< nt j|d ƒ|d< dS )zh translation_unit_or_empty   : translation_unit
                                        | empty
        r   Nr   )r   ZFileAST)r   Úpr   r   r    Úp_translation_unit_or_emptyô  s    z#CParser.p_translation_unit_or_emptyc             C   s   |d |d< dS )z4 translation_unit    : external_declaration
        r   r   Nr   )r   ry   r   r   r    Úp_translation_unit_1ý  s    zCParser.p_translation_unit_1c             C   s.   |d dk	r|d j |d ƒ |d |d< dS )zE translation_unit    : translation_unit external_declaration
        rS   Nr   r   )Úextend)r   ry   r   r   r    Úp_translation_unit_2  s    zCParser.p_translation_unit_2c             C   s   |d g|d< dS )z7 external_declaration    : function_definition
        r   r   Nr   )r   ry   r   r   r    Úp_external_declaration_1  s    z CParser.p_external_declaration_1c             C   s   |d |d< dS )z/ external_declaration    : declaration
        r   r   Nr   )r   ry   r   r   r    Úp_external_declaration_2  s    z CParser.p_external_declaration_2c             C   s   |d |d< dS )z0 external_declaration    : pp_directive
        r   r   Nr   )r   ry   r   r   r    Úp_external_declaration_3  s    z CParser.p_external_declaration_3c             C   s   d|d< dS )z( external_declaration    : SEMI
        Nr   r   )r   ry   r   r   r    Úp_external_declaration_4  s    z CParser.p_external_declaration_4c             C   s   | j d| j|jdƒƒƒ dS )z  pp_directive  : PPHASH
        zDirectives not supported yetr   N)r.   r5   Úlineno)r   ry   r   r   r    Úp_pp_directive$  s    zCParser.p_pp_directivec             C   sP   t g g tjdg| j|jdƒƒd�gg d�}| j||d |d |d d�|d< d	S )
zR function_definition : declarator declaration_list_opt compound_statement
        r@   r   )r0   )rK   rL   r:   rM   rS   é   )rO   r=   r`   ra   r   N)r   r   rG   r5   r‚   rb   )r   ry   rO   r   r   r    Úp_function_definition_1-  s    zCParser.p_function_definition_1c             C   s.   |d }| j ||d |d |d d�|d< dS )zi function_definition : declaration_specifiers declarator declaration_list_opt compound_statement
        r   rS   r„   é   )rO   r=   r`   ra   r   N)rb   )r   ry   rO   r   r   r    Úp_function_definition_2>  s    zCParser.p_function_definition_2c             C   s   |d |d< dS )a
   statement   : labeled_statement
                        | expression_statement
                        | compound_statement
                        | selection_statement
                        | iteration_statement
                        | jump_statement
        r   r   Nr   )r   ry   r   r   r    Úp_statementI  s    zCParser.p_statementc          
   C   s¶   |d }|d dkr–|d }t jt jt jf}t|ƒdkrzt|d |ƒrzt jd|d |d |d |d dd|d jd	�g}qª| j|t	ddd
�gdd�}n| j||d dd�}||d< dS )zE decl_body : declaration_specifiers init_declarator_list_opt
        r   rS   Nr:   r   rK   rL   rM   )r/   rF   rL   rV   r:   rU   rR   r0   )r=   rU   T)rO   r[   r\   )
r   rX   rY   ÚEnumr(   r;   rZ   r0   r_   r   )r   ry   rO   ZtyZs_u_or_er[   r   r   r    Úp_decl_body\  s.    
zCParser.p_decl_bodyc             C   s   |d |d< dS )z& declaration : decl_body SEMI
        r   r   Nr   )r   ry   r   r   r    Úp_declaration—  s    zCParser.p_declarationc             C   s,   t |ƒdkr|d n|d |d  |d< dS )zj declaration_list    : declaration
                                | declaration_list declaration
        rS   r   r   N)r(   )r   ry   r   r   r    Úp_declaration_list   s    zCParser.p_declaration_listc             C   s   | j |d |d dƒ|d< dS )zM declaration_specifiers  : type_qualifier declaration_specifiers_opt
        rS   r   rK   r   N)rP   )r   ry   r   r   r    Úp_declaration_specifiers_1¦  s    z"CParser.p_declaration_specifiers_1c             C   s   | j |d |d dƒ|d< dS )zM declaration_specifiers  : type_specifier declaration_specifiers_opt
        rS   r   r:   r   N)rP   )r   ry   r   r   r    Úp_declaration_specifiers_2«  s    z"CParser.p_declaration_specifiers_2c             C   s   | j |d |d dƒ|d< dS )zV declaration_specifiers  : storage_class_specifier declaration_specifiers_opt
        rS   r   rL   r   N)rP   )r   ry   r   r   r    Úp_declaration_specifiers_3°  s    z"CParser.p_declaration_specifiers_3c             C   s   | j |d |d dƒ|d< dS )zQ declaration_specifiers  : function_specifier declaration_specifiers_opt
        rS   r   rM   r   N)rP   )r   ry   r   r   r    Úp_declaration_specifiers_4µ  s    z"CParser.p_declaration_specifiers_4c             C   s   |d |d< dS )zß storage_class_specifier : AUTO
                                    | REGISTER
                                    | STATIC
                                    | EXTERN
                                    | TYPEDEF
        r   r   Nr   )r   ry   r   r   r    Úp_storage_class_specifierº  s    z!CParser.p_storage_class_specifierc             C   s   |d |d< dS )z& function_specifier  : INLINE
        r   r   Nr   )r   ry   r   r   r    Úp_function_specifierÃ  s    zCParser.p_function_specifierc             C   s(   t j|d g| j|jdƒƒd�|d< dS )aŒ   type_specifier  : VOID
                            | _BOOL
                            | CHAR
                            | SHORT
                            | INT
                            | LONG
                            | FLOAT
                            | DOUBLE
                            | _COMPLEX
                            | SIGNED
                            | UNSIGNED
        r   )r0   r   N)r   rG   r5   r‚   )r   ry   r   r   r    Úp_type_specifier_1È  s    zCParser.p_type_specifier_1c             C   s   |d |d< dS )z� type_specifier  : typedef_name
                            | enum_specifier
                            | struct_or_union_specifier
        r   r   Nr   )r   ry   r   r   r    Úp_type_specifier_2×  s    zCParser.p_type_specifier_2c             C   s   |d |d< dS )zo type_qualifier  : CONST
                            | RESTRICT
                            | VOLATILE
        r   r   Nr   )r   ry   r   r   r    Úp_type_qualifierÞ  s    zCParser.p_type_qualifierc             C   s0   t |ƒdkr|d |d g n|d g|d< dS )z„ init_declarator_list    : init_declarator
                                    | init_declarator_list COMMA init_declarator
        r†   r   r„   r   N)r(   )r   ry   r   r   r    Úp_init_declarator_list_1å  s    z CParser.p_init_declarator_list_1c             C   s   t d|d d�g|d< dS )z6 init_declarator_list    : EQUALS initializer
        NrS   )r=   rU   r   )r   )r   ry   r   r   r    Úp_init_declarator_list_2ð  s    z CParser.p_init_declarator_list_2c             C   s   t |d dd�g|d< dS )z7 init_declarator_list    : abstract_declarator
        r   N)r=   rU   r   )r   )r   ry   r   r   r    Úp_init_declarator_list_3ø  s    z CParser.p_init_declarator_list_3c             C   s,   t |d t|ƒdkr|d ndd�|d< dS )zb init_declarator : declarator
                            | declarator EQUALS initializer
        r   rS   r„   N)r=   rU   r   )r   r(   )r   ry   r   r   r    Úp_init_declarator   s    zCParser.p_init_declaratorc             C   s   | j |d |d dƒ|d< dS )zS specifier_qualifier_list    : type_qualifier specifier_qualifier_list_opt
        rS   r   rK   r   N)rP   )r   ry   r   r   r    Úp_specifier_qualifier_list_1  s    z$CParser.p_specifier_qualifier_list_1c             C   s   | j |d |d dƒ|d< dS )zS specifier_qualifier_list    : type_specifier specifier_qualifier_list_opt
        rS   r   r:   r   N)rP   )r   ry   r   r   r    Úp_specifier_qualifier_list_2  s    z$CParser.p_specifier_qualifier_list_2c             C   s4   | j |d ƒ}||d d| j|jdƒƒd�|d< dS )z{ struct_or_union_specifier   : struct_or_union ID
                                        | struct_or_union TYPEID
        r   rS   N)r/   r[   r0   r   )re   r5   r‚   )r   ry   Úklassr   r   r    Úp_struct_or_union_specifier_1  s
    z%CParser.p_struct_or_union_specifier_1c             C   s4   | j |d ƒ}|d|d | j|jdƒƒd�|d< dS )zd struct_or_union_specifier : struct_or_union brace_open struct_declaration_list brace_close
        r   Nr„   rS   )r/   r[   r0   r   )re   r5   r‚   )r   ry   rœ   r   r   r    Úp_struct_or_union_specifier_2  s
    z%CParser.p_struct_or_union_specifier_2c             C   s8   | j |d ƒ}||d |d | j|jdƒƒd�|d< dS )zÙ struct_or_union_specifier   : struct_or_union ID brace_open struct_declaration_list brace_close
                                        | struct_or_union TYPEID brace_open struct_declaration_list brace_close
        r   rS   r†   )r/   r[   r0   r   N)re   r5   r‚   )r   ry   rœ   r   r   r    Úp_struct_or_union_specifier_3&  s
    z%CParser.p_struct_or_union_specifier_3c             C   s   |d |d< dS )zF struct_or_union : STRUCT
                            | UNION
        r   r   Nr   )r   ry   r   r   r    Úp_struct_or_union0  s    zCParser.p_struct_or_unionc             C   s,   t |ƒdkr|d n|d |d  |d< dS )z� struct_declaration_list     : struct_declaration
                                        | struct_declaration_list struct_declaration
        rS   r   r   N)r(   )r   ry   r   r   r    Úp_struct_declaration_list8  s    z!CParser.p_struct_declaration_listc             C   s¬   |d }d|d kst ‚|d dk	r8| j||d d�}nht|d ƒdkrˆ|d d }t|tjƒrf|}n
tj|ƒ}| j|t|d	�gd�}n| j|tddd
�gd�}||d< dS )zW struct_declaration : specifier_qualifier_list struct_declarator_list_opt SEMI
        r   rQ   rL   rS   N)rO   r[   r:   r   )r=   )r=   rU   )r)   r_   r(   r;   r   ZNoderG   r   )r   ry   rO   r[   ZnodeZ	decl_typer   r   r    Úp_struct_declaration_1>  s$    
zCParser.p_struct_declaration_1c             C   s(   | j |d t|d dd�gd�|d< dS )zP struct_declaration : specifier_qualifier_list abstract_declarator SEMI
        r   rS   N)r=   rU   )rO   r[   r   )r_   r   )r   ry   r   r   r    Úp_struct_declaration_2d  s    
zCParser.p_struct_declaration_2c             C   s0   t |ƒdkr|d |d g n|d g|d< dS )zŠ struct_declarator_list  : struct_declarator
                                    | struct_declarator_list COMMA struct_declarator
        r†   r   r„   r   N)r(   )r   ry   r   r   r    Úp_struct_declarator_listr  s    z CParser.p_struct_declarator_listc             C   s   |d ddœ|d< dS )z( struct_declarator : declarator
        r   N)r=   rR   r   r   )r   ry   r   r   r    Úp_struct_declarator_1{  s    zCParser.p_struct_declarator_1c             C   sD   t |ƒdkr$|d |d dœ|d< ntjdddƒ|d dœ|d< dS )z€ struct_declarator   : declarator COLON constant_expression
                                | COLON constant_expression
        r„   r   )r=   rR   r   NrS   )r(   r   r<   )r   ry   r   r   r    Úp_struct_declarator_2€  s    zCParser.p_struct_declarator_2c             C   s&   t j|d d| j|jdƒƒƒ|d< dS )zM enum_specifier  : ENUM ID
                            | ENUM TYPEID
        rS   Nr   r   )r   r‰   r5   r‚   )r   ry   r   r   r    Úp_enum_specifier_1‰  s    zCParser.p_enum_specifier_1c             C   s&   t jd|d | j|jdƒƒƒ|d< dS )zG enum_specifier  : ENUM brace_open enumerator_list brace_close
        Nr„   r   r   )r   r‰   r5   r‚   )r   ry   r   r   r    Úp_enum_specifier_2�  s    zCParser.p_enum_specifier_2c             C   s*   t j|d |d | j|jdƒƒƒ|d< dS )z› enum_specifier  : ENUM ID brace_open enumerator_list brace_close
                            | ENUM TYPEID brace_open enumerator_list brace_close
        rS   r†   r   r   N)r   r‰   r5   r‚   )r   ry   r   r   r    Úp_enum_specifier_3”  s    zCParser.p_enum_specifier_3c             C   sh   t |ƒdkr*tj|d g|d jƒ|d< n:t |ƒdkrD|d |d< n |d jj|d ƒ |d |d< dS )z™ enumerator_list : enumerator
                            | enumerator_list COMMA
                            | enumerator_list COMMA enumerator
        rS   r   r   r„   N)r(   r   ZEnumeratorListr0   Zenumeratorsr&   )r   ry   r   r   r    Úp_enumerator_listš  s    zCParser.p_enumerator_listc             C   sj   t |ƒdkr,tj|d d| j|jdƒƒƒ}n"tj|d |d | j|jdƒƒƒ}| j|j|jƒ ||d< dS )zR enumerator  : ID
                        | ID EQUALS constant_expression
        rS   r   Nr„   r   )r(   r   Z
Enumeratorr5   r‚   r2   r/   r0   )r   ry   Z
enumeratorr   r   r    Úp_enumerator§  s    zCParser.p_enumeratorc             C   s   |d |d< dS )z) declarator  : direct_declarator
        r   r   Nr   )r   ry   r   r   r    Úp_declarator_1·  s    zCParser.p_declarator_1c             C   s   | j |d |d ƒ|d< dS )z1 declarator  : pointer direct_declarator
        rS   r   r   N)r?   )r   ry   r   r   r    Úp_declarator_2¼  s    zCParser.p_declarator_2c             C   s:   t j|d dd| j|jdƒƒd�}| j||d ƒ|d< dS )z& declarator  : pointer TYPEID
        rS   N)rE   r:   rF   r0   r   r   )r   r<   r5   r‚   r?   )r   ry   r=   r   r   r    Úp_declarator_3Å  s    zCParser.p_declarator_3c             C   s*   t j|d dd| j|jdƒƒd�|d< dS )z" direct_declarator   : ID
        r   N)rE   r:   rF   r0   r   )r   r<   r5   r‚   )r   ry   r   r   r    Úp_direct_declarator_1Ð  s
    zCParser.p_direct_declarator_1c             C   s   |d |d< dS )z8 direct_declarator   : LPAREN declarator RPAREN
        rS   r   Nr   )r   ry   r   r   r    Úp_direct_declarator_2Ù  s    zCParser.p_direct_declarator_2c             C   sf   t |ƒdkr|d ng pg }tjdt |ƒdkr6|d n|d ||d jd�}| j|d |d�|d< dS )	zu direct_declarator   : direct_declarator LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET
        é   r„   Nr†   r   )r:   ÚdimÚ	dim_qualsr0   )r=   r>   r   )r(   r   Ú	ArrayDeclr0   r?   )r   ry   rF   Úarrr   r   r    Úp_direct_declarator_3Þ  s    zCParser.p_direct_declarator_3c             C   s^   dd„ |d |d gD ƒ}dd„ |D ƒ}t jd|d ||d jd	�}| j|d |d
�|d< dS )zï direct_declarator   : direct_declarator LBRACKET STATIC type_qualifier_list_opt assignment_expression RBRACKET
                                | direct_declarator LBRACKET type_qualifier_list STATIC assignment_expression RBRACKET
        c             S   s    g | ]}t |tƒr|n|g‘qS r   )r;   Úlist)rB   Úitemr   r   r    rD   ó  s   z1CParser.p_direct_declarator_4.<locals>.<listcomp>r„   r†   c             S   s"   g | ]}|D ]}|d k	r|‘qqS )Nr   )rB   ZsublistrK   r   r   r    rD   õ  s    
Nr±   r   )r:   r²   r³   r0   )r=   r>   r   )r   r´   r0   r?   )r   ry   Zlisted_qualsr³   rµ   r   r   r    Úp_direct_declarator_4ì  s    zCParser.p_direct_declarator_4c             C   s^   t jdt j|d | j|jdƒƒƒ|d dkr4|d ng |d jd�}| j|d |d�|d< dS )za direct_declarator   : direct_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET
        Nr†   r„   r   )r:   r²   r³   r0   )r=   r>   r   )r   r´   ÚIDr5   r‚   r0   r?   )r   ry   rµ   r   r   r    Úp_direct_declarator_5  s    zCParser.p_direct_declarator_5c             C   s|   t j|d d|d jd�}| jƒ jdkrb|jdk	rbx.|jjD ]"}t|t jƒrNP | j	|j
|jƒ q<W | j|d |d�|d< dS )z© direct_declarator   : direct_declarator LPAREN parameter_type_list RPAREN
                                | direct_declarator LPAREN identifier_list_opt RPAREN
        r„   Nr   )Úargsr:   r0   ÚLBRACE)r=   r>   r   )r   rH   r0   r9   r:   r¼   Úparamsr;   ÚEllipsisParamr2   r/   r?   )r   ry   ÚfuncZparamr   r   r    Úp_direct_declarator_6  s    
 zCParser.p_direct_declarator_6c             C   sr   | j |jdƒƒ}tj|d pg d|d�}t|ƒdkrf|d }x|jdk	rP|j}q>W ||_|d |d< n||d< dS )zm pointer : TIMES type_qualifier_list_opt
                    | TIMES type_qualifier_list_opt pointer
        r   rS   N)rF   r:   r0   r„   r   )r5   r‚   r   ZPtrDeclr(   r:   )r   ry   r0   Znested_typeZ	tail_typer   r   r    Ú	p_pointer(  s    
zCParser.p_pointerc             C   s0   t |ƒdkr|d gn|d |d g |d< dS )zs type_qualifier_list : type_qualifier
                                | type_qualifier_list type_qualifier
        rS   r   r   N)r(   )r   ry   r   r   r    Úp_type_qualifier_listF  s    zCParser.p_type_qualifier_listc             C   s>   t |ƒdkr.|d jjtj| j|jdƒƒƒƒ |d |d< dS )zn parameter_type_list : parameter_list
                                | parameter_list COMMA ELLIPSIS
        rS   r   r„   r   N)r(   r¾   r&   r   r¿   r5   r‚   )r   ry   r   r   r    Úp_parameter_type_listL  s    "zCParser.p_parameter_type_listc             C   sN   t |ƒdkr*tj|d g|d jƒ|d< n |d jj|d ƒ |d |d< dS )zz parameter_list  : parameter_declaration
                            | parameter_list COMMA parameter_declaration
        rS   r   r   r„   N)r(   r   Ú	ParamListr0   r¾   r&   )r   ry   r   r   r    Úp_parameter_listU  s    zCParser.p_parameter_listc             C   sX   |d }|d s2t jdg| j|jdƒƒd�g|d< | j|t|d d�gd�d |d< d	S )
zE parameter_declaration   : declaration_specifiers declarator
        r   r:   r@   )r0   rS   )r=   )rO   r[   r   N)r   rG   r5   r‚   r_   r   )r   ry   rO   r   r   r    Úp_parameter_declaration_1_  s    z!CParser.p_parameter_declaration_1c             C   sæ   |d }|d s2t jdg| j|jdƒƒd�g|d< t|d ƒdkr’t|d d jƒdkr’| j|d d jd ƒr’| j|t|d dd�gd	�d }nHt j	d
|d |d p²t j
dddƒ| j|jdƒƒd�}|d }| j||ƒ}||d< dS )zR parameter_declaration   : declaration_specifiers abstract_declarator_opt
        r   r:   r@   )r0   r   rS   N)r=   rU   )rO   r[   r   rK   )r/   rF   r:   r0   r,   r,   )r   rG   r5   r‚   r(   rA   r4   r_   r   ÚTypenamer<   rJ   )r   ry   rO   r=   rI   r   r   r    Úp_parameter_declaration_2j  s"    &z!CParser.p_parameter_declaration_2c             C   sN   t |ƒdkr*tj|d g|d jƒ|d< n |d jj|d ƒ |d |d< dS )ze identifier_list : identifier
                            | identifier_list COMMA identifier
        rS   r   r   r„   N)r(   r   rÅ   r0   r¾   r&   )r   ry   r   r   r    Úp_identifier_list‰  s    zCParser.p_identifier_listc             C   s   |d |d< dS )z- initializer : assignment_expression
        r   r   Nr   )r   ry   r   r   r    Úp_initializer_1“  s    zCParser.p_initializer_1c             C   s:   |d dkr*t jg | j|jdƒƒƒ|d< n|d |d< dS )z‹ initializer : brace_open initializer_list_opt brace_close
                        | brace_open initializer_list COMMA brace_close
        rS   Nr   r   )r   ÚInitListr5   r‚   )r   ry   r   r   r    Úp_initializer_2˜  s    zCParser.p_initializer_2c             C   s–   t |ƒdkrN|d dkr |d ntj|d |d ƒ}tj|g|d jƒ|d< nD|d dkrb|d ntj|d |d ƒ}|d jj|ƒ |d |d< dS )z� initializer_list    : designation_opt initializer
                                | initializer_list COMMA designation_opt initializer
        r„   r   NrS   r   r†   )r(   r   ZNamedInitializerrÌ   r0   Úexprsr&   )r   ry   rU   r   r   r    Úp_initializer_list¡  s    ((zCParser.p_initializer_listc             C   s   |d |d< dS )z. designation : designator_list EQUALS
        r   r   Nr   )r   ry   r   r   r    Úp_designation­  s    zCParser.p_designationc             C   s0   t |ƒdkr|d gn|d |d g |d< dS )z_ designator_list : designator
                            | designator_list designator
        rS   r   r   N)r(   )r   ry   r   r   r    Úp_designator_listµ  s    zCParser.p_designator_listc             C   s   |d |d< dS )zi designator  : LBRACKET constant_expression RBRACKET
                        | PERIOD identifier
        rS   r   Nr   )r   ry   r   r   r    Úp_designator»  s    zCParser.p_designatorc             C   sT   t jd|d d |d p$t jdddƒ| j|jdƒƒd�}| j||d d ƒ|d< dS )	zH type_name   : specifier_qualifier_list abstract_declarator_opt
        r   r   rK   rS   N)r/   rF   r:   r0   r:   r   )r   rÈ   r<   r5   r‚   rJ   )r   ry   rI   r   r   r    Úp_type_nameÁ  s    	
zCParser.p_type_namec             C   s(   t jdddƒ}| j||d d�|d< dS )z+ abstract_declarator     : pointer
        Nr   )r=   r>   r   )r   r<   r?   )r   ry   Z	dummytyper   r   r    Úp_abstract_declarator_1Ò  s    zCParser.p_abstract_declarator_1c             C   s   | j |d |d ƒ|d< dS )zF abstract_declarator     : pointer direct_abstract_declarator
        rS   r   r   N)r?   )r   ry   r   r   r    Úp_abstract_declarator_2Ú  s    zCParser.p_abstract_declarator_2c             C   s   |d |d< dS )z> abstract_declarator     : direct_abstract_declarator
        r   r   Nr   )r   ry   r   r   r    Úp_abstract_declarator_3ß  s    zCParser.p_abstract_declarator_3c             C   s   |d |d< dS )zA direct_abstract_declarator  : LPAREN abstract_declarator RPAREN rS   r   Nr   )r   ry   r   r   r    Úp_direct_abstract_declarator_1é  s    z&CParser.p_direct_abstract_declarator_1c             C   s6   t jd|d g |d jd�}| j|d |d�|d< dS )zn direct_abstract_declarator  : direct_abstract_declarator LBRACKET assignment_expression_opt RBRACKET
        Nr„   r   )r:   r²   r³   r0   )r=   r>   r   )r   r´   r0   r?   )r   ry   rµ   r   r   r    Úp_direct_abstract_declarator_2í  s    z&CParser.p_direct_abstract_declarator_2c             C   s4   t jt jdddƒ|d g | j|jdƒƒd�|d< dS )zS direct_abstract_declarator  : LBRACKET assignment_expression_opt RBRACKET
        NrS   r   )r:   r²   r³   r0   r   )r   r´   r<   r5   r‚   )r   ry   r   r   r    Úp_direct_abstract_declarator_3ø  s
    z&CParser.p_direct_abstract_declarator_3c             C   sJ   t jdt j|d | j|jdƒƒƒg |d jd�}| j|d |d�|d< dS )zZ direct_abstract_declarator  : direct_abstract_declarator LBRACKET TIMES RBRACKET
        Nr„   r   )r:   r²   r³   r0   )r=   r>   r   )r   r´   rº   r5   r‚   r0   r?   )r   ry   rµ   r   r   r    Úp_direct_abstract_declarator_4  s    z&CParser.p_direct_abstract_declarator_4c             C   sH   t jt jdddƒt j|d | j|jdƒƒƒg | j|jdƒƒd�|d< dS )z? direct_abstract_declarator  : LBRACKET TIMES RBRACKET
        Nr„   r   )r:   r²   r³   r0   r   )r   r´   r<   rº   r5   r‚   )r   ry   r   r   r    Úp_direct_abstract_declarator_5  s
    z&CParser.p_direct_abstract_declarator_5c             C   s4   t j|d d|d jd�}| j|d |d�|d< dS )zh direct_abstract_declarator  : direct_abstract_declarator LPAREN parameter_type_list_opt RPAREN
        r„   Nr   )r¼   r:   r0   )r=   r>   r   )r   rH   r0   r?   )r   ry   rÀ   r   r   r    Úp_direct_abstract_declarator_6  s
    z&CParser.p_direct_abstract_declarator_6c             C   s2   t j|d t jdddƒ| j|jdƒƒd�|d< dS )zM direct_abstract_declarator  : LPAREN parameter_type_list_opt RPAREN
        rS   Nr   )r¼   r:   r0   r   )r   rH   r<   r5   r‚   )r   ry   r   r   r    Úp_direct_abstract_declarator_7  s    z&CParser.p_direct_abstract_declarator_7c             C   s(   t |d tƒr|d n|d g|d< dS )zG block_item  : declaration
                        | statement
        r   r   N)r;   r·   )r   ry   r   r   r    Úp_block_item*  s    zCParser.p_block_itemc             C   s:   t |ƒdks|d dgkr"|d n|d |d  |d< dS )z_ block_item_list : block_item
                            | block_item_list block_item
        rS   Nr   r   )r(   )r   ry   r   r   r    Úp_block_item_list2  s    zCParser.p_block_item_listc             C   s&   t j|d | j|jdƒƒd�|d< dS )zA compound_statement : brace_open block_item_list_opt brace_close rS   r   )Zblock_itemsr0   r   N)r   ZCompoundr5   r‚   )r   ry   r   r   r    Úp_compound_statement_19  s    zCParser.p_compound_statement_1c             C   s*   t j|d |d | j|jdƒƒƒ|d< dS )z( labeled_statement : ID COLON statement r   r„   r   N)r   ZLabelr5   r‚   )r   ry   r   r   r    Úp_labeled_statement_1?  s    zCParser.p_labeled_statement_1c             C   s,   t j|d |d g| j|jdƒƒƒ|d< dS )z> labeled_statement : CASE constant_expression COLON statement rS   r†   r   r   N)r   ZCaser5   r‚   )r   ry   r   r   r    Úp_labeled_statement_2C  s    zCParser.p_labeled_statement_2c             C   s&   t j|d g| j|jdƒƒƒ|d< dS )z- labeled_statement : DEFAULT COLON statement r„   r   r   N)r   ZDefaultr5   r‚   )r   ry   r   r   r    Úp_labeled_statement_3G  s    zCParser.p_labeled_statement_3c             C   s,   t j|d |d d| j|jdƒƒƒ|d< dS )z= selection_statement : IF LPAREN expression RPAREN statement r„   r±   Nr   r   )r   ÚIfr5   r‚   )r   ry   r   r   r    Úp_selection_statement_1K  s    zCParser.p_selection_statement_1c             C   s0   t j|d |d |d | j|jdƒƒƒ|d< dS )zL selection_statement : IF LPAREN expression RPAREN statement ELSE statement r„   r±   é   r   r   N)r   rä   r5   r‚   )r   ry   r   r   r    Úp_selection_statement_2O  s    zCParser.p_selection_statement_2c             C   s.   t tj|d |d | j|jdƒƒƒƒ|d< dS )zA selection_statement : SWITCH LPAREN expression RPAREN statement r„   r±   r   r   N)r	   r   ZSwitchr5   r‚   )r   ry   r   r   r    Úp_selection_statement_3S  s    zCParser.p_selection_statement_3c             C   s*   t j|d |d | j|jdƒƒƒ|d< dS )z@ iteration_statement : WHILE LPAREN expression RPAREN statement r„   r±   r   r   N)r   ZWhiler5   r‚   )r   ry   r   r   r    Úp_iteration_statement_1X  s    zCParser.p_iteration_statement_1c             C   s*   t j|d |d | j|jdƒƒƒ|d< dS )zH iteration_statement : DO statement WHILE LPAREN expression RPAREN SEMI r±   rS   r   r   N)r   ZDoWhiler5   r‚   )r   ry   r   r   r    Úp_iteration_statement_2\  s    zCParser.p_iteration_statement_2c             C   s6   t j|d |d |d |d | j|jdƒƒƒ|d< dS )zj iteration_statement : FOR LPAREN expression_opt SEMI expression_opt SEMI expression_opt RPAREN statement r„   r±   ræ   é	   r   r   N)r   ÚForr5   r‚   )r   ry   r   r   r    Úp_iteration_statement_3`  s    zCParser.p_iteration_statement_3c             C   sJ   t jt j|d | j|jdƒƒƒ|d |d |d | j|jdƒƒƒ|d< dS )zb iteration_statement : FOR LPAREN declaration expression_opt SEMI expression_opt RPAREN statement r„   r   r†   é   é   r   N)r   rì   ZDeclListr5   r‚   )r   ry   r   r   r    Úp_iteration_statement_4d  s    zCParser.p_iteration_statement_4c             C   s$   t j|d | j|jdƒƒƒ|d< dS )z  jump_statement  : GOTO ID SEMI rS   r   r   N)r   ZGotor5   r‚   )r   ry   r   r   r    Úp_jump_statement_1i  s    zCParser.p_jump_statement_1c             C   s   t j| j|jdƒƒƒ|d< dS )z jump_statement  : BREAK SEMI r   r   N)r   ZBreakr5   r‚   )r   ry   r   r   r    Úp_jump_statement_2m  s    zCParser.p_jump_statement_2c             C   s   t j| j|jdƒƒƒ|d< dS )z! jump_statement  : CONTINUE SEMI r   r   N)r   ZContinuer5   r‚   )r   ry   r   r   r    Úp_jump_statement_3q  s    zCParser.p_jump_statement_3c             C   s4   t jt|ƒdkr|d nd| j|jdƒƒƒ|d< dS )z\ jump_statement  : RETURN expression SEMI
                            | RETURN SEMI
        r†   rS   Nr   r   )r   ZReturnr(   r5   r‚   )r   ry   r   r   r    Úp_jump_statement_4u  s    zCParser.p_jump_statement_4c             C   s8   |d dkr(t j| j|jdƒƒƒ|d< n|d |d< dS )z, expression_statement : expression_opt SEMI r   Nr   )r   ZEmptyStatementr5   r‚   )r   ry   r   r   r    Úp_expression_statement{  s    zCParser.p_expression_statementc             C   sj   t |ƒdkr|d |d< nLt|d tjƒsFtj|d g|d jƒ|d< |d jj|d ƒ |d |d< dS )zn expression  : assignment_expression
                        | expression COMMA assignment_expression
        rS   r   r   r„   N)r(   r;   r   ÚExprListr0   rÎ   r&   )r   ry   r   r   r    Úp_expression‚  s    zCParser.p_expressionc             C   s(   t j|d g| j|jdƒƒd�|d< dS )z typedef_name : TYPEID r   )r0   r   N)r   rG   r5   r‚   )r   ry   r   r   r    Úp_typedef_name�  s    zCParser.p_typedef_namec             C   sD   t |ƒdkr|d |d< n&tj|d |d |d |d jƒ|d< dS )z› assignment_expression   : conditional_expression
                                    | unary_expression assignment_operator assignment_expression
        rS   r   r   r„   N)r(   r   Z
Assignmentr0   )r   ry   r   r   r    Úp_assignment_expression“  s    zCParser.p_assignment_expressionc             C   s   |d |d< dS )aÞ   assignment_operator : EQUALS
                                | XOREQUAL
                                | TIMESEQUAL
                                | DIVEQUAL
                                | MODEQUAL
                                | PLUSEQUAL
                                | MINUSEQUAL
                                | LSHIFTEQUAL
                                | RSHIFTEQUAL
                                | ANDEQUAL
                                | OREQUAL
        r   r   Nr   )r   ry   r   r   r    Úp_assignment_operator¡  s    zCParser.p_assignment_operatorc             C   s   |d |d< dS )z. constant_expression : conditional_expression r   r   Nr   )r   ry   r   r   r    Úp_constant_expression°  s    zCParser.p_constant_expressionc             C   sD   t |ƒdkr|d |d< n&tj|d |d |d |d jƒ|d< dS )zœ conditional_expression  : binary_expression
                                    | binary_expression CONDOP expression COLON conditional_expression
        rS   r   r   r„   r±   N)r(   r   Z	TernaryOpr0   )r   ry   r   r   r    Úp_conditional_expression´  s    z CParser.p_conditional_expressionc             C   sD   t |ƒdkr|d |d< n&tj|d |d |d |d jƒ|d< dS )ak   binary_expression   : cast_expression
                                | binary_expression TIMES binary_expression
                                | binary_expression DIVIDE binary_expression
                                | binary_expression MOD binary_expression
                                | binary_expression PLUS binary_expression
                                | binary_expression MINUS binary_expression
                                | binary_expression RSHIFT binary_expression
                                | binary_expression LSHIFT binary_expression
                                | binary_expression LT binary_expression
                                | binary_expression LE binary_expression
                                | binary_expression GE binary_expression
                                | binary_expression GT binary_expression
                                | binary_expression EQ binary_expression
                                | binary_expression NE binary_expression
                                | binary_expression AND binary_expression
                                | binary_expression OR binary_expression
                                | binary_expression XOR binary_expression
                                | binary_expression LAND binary_expression
                                | binary_expression LOR binary_expression
        rS   r   r   r„   N)r(   r   ZBinaryOpr0   )r   ry   r   r   r    Úp_binary_expression½  s    zCParser.p_binary_expressionc             C   s   |d |d< dS )z$ cast_expression : unary_expression r   r   Nr   )r   ry   r   r   r    Úp_cast_expression_1×  s    zCParser.p_cast_expression_1c             C   s*   t j|d |d | j|jdƒƒƒ|d< dS )z; cast_expression : LPAREN type_name RPAREN cast_expression rS   r†   r   r   N)r   ZCastr5   r‚   )r   ry   r   r   r    Úp_cast_expression_2Û  s    zCParser.p_cast_expression_2c             C   s   |d |d< dS )z* unary_expression    : postfix_expression r   r   Nr   )r   ry   r   r   r    Úp_unary_expression_1ß  s    zCParser.p_unary_expression_1c             C   s$   t j|d |d |d jƒ|d< dS )z¸ unary_expression    : PLUSPLUS unary_expression
                                | MINUSMINUS unary_expression
                                | unary_operator cast_expression
        r   rS   r   N)r   ÚUnaryOpr0   )r   ry   r   r   r    Úp_unary_expression_2ã  s    zCParser.p_unary_expression_2c             C   s>   t j|d t|ƒdkr|d n|d | j|jdƒƒƒ|d< dS )zx unary_expression    : SIZEOF unary_expression
                                | SIZEOF LPAREN type_name RPAREN
        r   r„   rS   r   N)r   r  r(   r5   r‚   )r   ry   r   r   r    Úp_unary_expression_3ê  s    zCParser.p_unary_expression_3c             C   s   |d |d< dS )zÏ unary_operator  : AND
                            | TIMES
                            | PLUS
                            | MINUS
                            | NOT
                            | LNOT
        r   r   Nr   )r   ry   r   r   r    Úp_unary_operatoró  s    zCParser.p_unary_operatorc             C   s   |d |d< dS )z* postfix_expression  : primary_expression r   r   Nr   )r   ry   r   r   r    Úp_postfix_expression_1ý  s    zCParser.p_postfix_expression_1c             C   s$   t j|d |d |d jƒ|d< dS )zG postfix_expression  : postfix_expression LBRACKET expression RBRACKET r   r„   r   N)r   ZArrayRefr0   )r   ry   r   r   r    Úp_postfix_expression_2  s    zCParser.p_postfix_expression_2c             C   s4   t j|d t|ƒdkr|d nd|d jƒ|d< dS )zœ postfix_expression  : postfix_expression LPAREN argument_expression_list RPAREN
                                | postfix_expression LPAREN RPAREN
        r   r±   r„   Nr   )r   ÚFuncCallr(   r0   )r   ry   r   r   r    Úp_postfix_expression_3  s    zCParser.p_postfix_expression_3c             C   sB   t j|d | j|jdƒƒƒ}t j|d |d ||d jƒ|d< dS )zÿ postfix_expression  : postfix_expression PERIOD ID
                                | postfix_expression PERIOD TYPEID
                                | postfix_expression ARROW ID
                                | postfix_expression ARROW TYPEID
        r„   r   rS   r   N)r   rº   r5   r‚   Z	StructRefr0   )r   ry   Zfieldr   r   r    Úp_postfix_expression_4  s    zCParser.p_postfix_expression_4c             C   s(   t jd|d  |d |d jƒ|d< dS )z{ postfix_expression  : postfix_expression PLUSPLUS
                                | postfix_expression MINUSMINUS
        ry   rS   r   r   N)r   r  r0   )r   ry   r   r   r    Úp_postfix_expression_5  s    zCParser.p_postfix_expression_5c             C   s   t j|d |d ƒ|d< dS )zÇ postfix_expression  : LPAREN type_name RPAREN brace_open initializer_list brace_close
                                | LPAREN type_name RPAREN brace_open initializer_list COMMA brace_close
        rS   r±   r   N)r   ZCompoundLiteral)r   ry   r   r   r    Úp_postfix_expression_6  s    zCParser.p_postfix_expression_6c             C   s   |d |d< dS )z" primary_expression  : identifier r   r   Nr   )r   ry   r   r   r    Úp_primary_expression_1   s    zCParser.p_primary_expression_1c             C   s   |d |d< dS )z  primary_expression  : constant r   r   Nr   )r   ry   r   r   r    Úp_primary_expression_2$  s    zCParser.p_primary_expression_2c             C   s   |d |d< dS )zp primary_expression  : unified_string_literal
                                | unified_wstring_literal
        r   r   Nr   )r   ry   r   r   r    Úp_primary_expression_3(  s    zCParser.p_primary_expression_3c             C   s   |d |d< dS )z0 primary_expression  : LPAREN expression RPAREN rS   r   Nr   )r   ry   r   r   r    Úp_primary_expression_4.  s    zCParser.p_primary_expression_4c             C   sF   | j |jdƒƒ}tjtj|d |ƒtj|d |d g|ƒ|ƒ|d< dS )zQ primary_expression  : OFFSETOF LPAREN type_name COMMA identifier RPAREN
        r   r„   r±   r   N)r5   r‚   r   r  rº   rö   )r   ry   r0   r   r   r    Úp_primary_expression_52  s    zCParser.p_primary_expression_5c             C   sN   t |ƒdkr*tj|d g|d jƒ|d< n |d jj|d ƒ |d |d< dS )zœ argument_expression_list    : assignment_expression
                                        | argument_expression_list COMMA assignment_expression
        rS   r   r   r„   N)r(   r   rö   r0   rÎ   r&   )r   ry   r   r   r    Úp_argument_expression_list:  s    z"CParser.p_argument_expression_listc             C   s$   t j|d | j|jdƒƒƒ|d< dS )z identifier  : ID r   r   N)r   rº   r5   r‚   )r   ry   r   r   r    Úp_identifierD  s    zCParser.p_identifierc             C   s&   t jd|d | j|jdƒƒƒ|d< dS )z� constant    : INT_CONST_DEC
                        | INT_CONST_OCT
                        | INT_CONST_HEX
                        | INT_CONST_BIN
        r@   r   r   N)r   ÚConstantr5   r‚   )r   ry   r   r   r    Úp_constant_1H  s    zCParser.p_constant_1c             C   s&   t jd|d | j|jdƒƒƒ|d< dS )zM constant    : FLOAT_CONST
                        | HEX_FLOAT_CONST
        Úfloatr   r   N)r   r  r5   r‚   )r   ry   r   r   r    Úp_constant_2Q  s    zCParser.p_constant_2c             C   s&   t jd|d | j|jdƒƒƒ|d< dS )zH constant    : CHAR_CONST
                        | WCHAR_CONST
        Úcharr   r   N)r   r  r5   r‚   )r   ry   r   r   r    Úp_constant_3X  s    zCParser.p_constant_3c             C   sh   t |ƒdkr0tjd|d | j|jdƒƒƒ|d< n4|d jdd… |d dd…  |d _|d |d< dS )z~ unified_string_literal  : STRING_LITERAL
                                    | unified_string_literal STRING_LITERAL
        rS   Ústringr   r   Nr,   )r(   r   r  r5   r‚   Úvalue)r   ry   r   r   r    Úp_unified_string_literald  s
     (z CParser.p_unified_string_literalc             C   sl   t |ƒdkr0tjd|d | j|jdƒƒƒ|d< n8|d jjƒ dd… |d dd…  |d _|d |d< dS )z� unified_wstring_literal : WSTRING_LITERAL
                                    | unified_wstring_literal WSTRING_LITERAL
        rS   r  r   r   Nr,   )r(   r   r  r5   r‚   r  Úrstrip)r   ry   r   r   r    Úp_unified_wstring_literalo  s
     ,z!CParser.p_unified_wstring_literalc             C   s   |d |d< dS )z  brace_open  :   LBRACE
        r   r   Nr   )r   ry   r   r   r    Úp_brace_openz  s    zCParser.p_brace_openc             C   s   |d |d< dS )z  brace_close :   RBRACE
        r   r   Nr   )r   ry   r   r   r    Úp_brace_close  s    zCParser.p_brace_closec             C   s   d|d< dS )zempty : Nr   r   )r   ry   r   r   r    Úp_empty„  s    zCParser.p_emptyc             C   s<   |r,| j d|j | j|j| jj|ƒd�ƒ n| j ddƒ d S )Nz
before: %s)r‚   r8   zAt end of inputr   )r.   r  r5   r‚   r   Zfind_tok_column)r   ry   r   r   r    Úp_errorˆ  s    zCParser.p_errorN)Tr   Tr   Fr   )r   r   )F©rf   rg   ©rf   rh   ©rf   ri   ©rf   rj   ©rf   rk   ©rf   rl   rm   ©rf   rn   ro   rp   rq   ©rf   rr   rs   ©rf   rt   ru   ©rf   rv   rw   rx   )
r"  r#  r$  r%  r&  r'  r(  r)  r*  r+  )˜Ú__name__Ú
__module__Ú__qualname__r!   r$   r'   r+   r1   r2   r4   r   r   r   r   r9   r?   rJ   rP   r_   rb   re   Z
precedencerz   r{   r}   r~   r   r€   r�   rƒ   r…   r‡   rˆ   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r‘   r’   r“   r”   r•   r–   r—   r˜   r™   rš   r›   r�   rž   rŸ   r    r¡   r¢   r£   r¤   r¥   r¦   r§   r¨   r©   rª   r«   r¬   r­   r®   r¯   r°   r¶   r¹   r»   rÁ   rÂ   rÃ   rÄ   rÆ   rÇ   rÉ   rÊ   rË   rÍ   rÏ   rÐ   rÑ   rÒ   rÓ   rÔ   rÕ   rÖ   r×   rØ   rÙ   rÚ   rÛ   rÜ   rÝ   rÞ   rß   rà   rá   râ   rã   rå   rç   rè   ré   rê   rí   rð   rñ   rò   ró   rô   rõ   r÷   rø   rù   rú   rû   rü   rý   rþ   rÿ   r   r  r  r  r  r  r  r	  r
  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r!  r   r   r   r    r
      sF       c	

	)7-Y         		;		
	
&					

	
		
		
	
	r
   Ú__main__)ÚreZplyr   r   r   Zc_lexerr   Z	plyparserr   r   r   Zast_transformsr	   r
   r,  ÚpprintZtimeÚsysr   r   r   r    Ú<module>	   s,                