o
    w¨Êhr ã                   @   sl   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
mZmZ ddlmZ eG dd	„ d	eƒƒZdS )
é    Né   )Úyacc)Úc_ast)ÚCLexer)Ú	PLYParserÚCoordÚ
ParseErrorÚparameterizedÚtemplate)Úfix_switch_casesc                   @   s  e Zd Zdedddddfdd„Z�dJd	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�dKd#d$„Z�dKd%d&„Zd'd(„ Zd)d*„ Zd+Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ 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„ Z*dTdU„ Z+dVdW„ Z,dXdY„ Z-dZd[„ Z.d\d]„ Z/d^d_„ Z0d`da„ Z1dbdc„ Z2ddde„ Z3dfdg„ Z4dhdi„ Z5djdk„ Z6dldm„ Z7dndo„ Z8dpdq„ Z9drds„ Z:dtdu„ Z;dvdw„ Z<dxdy„ Z=dzd{„ 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™„ ZMeNdšd›dœƒd�dž„ ƒZOeNdšd›dœƒdŸd „ ƒZPeNdšd›dœƒd¡d¢„ ƒZQeNdšd›ƒd£d¤„ ƒZReNdšd›dœƒd¥d¦„ ƒZSeNdšd›dœƒd§d¨„ ƒZTeNdšd›dœƒd©dª„ ƒZUeNdšd›dœƒd«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ì„ 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„ 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”�d)�d*„ Z•�d+�d,„ Z–�d-�d.„ Z—�d/�d0„ Z˜�d1�d2„ Z™�d3�d4„ Zš�d5�d6„ Z›�d7�d8„ Zœ�d9�d:„ Z��d;�d<„ Zž�d=�d>„ ZŸ�d?�d@„ Z �dA�dB„ Z¡�dC�dD„ Z¢�dE�dF„ Z£�dG�dH„ Z¤�dIS (L  ÚCParserTzpycparser.lextabzpycparser.yacctabFÚ c           
      C   s~   || j | j| j| jd�| _| jj|||d� | jj| _g d¢}|D ]}	|  |	¡ q!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.

            lexer:
                Set this parameter to define the lexer to use if
                you're not using the default CLexer.

            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.
        )Ú
error_funcÚon_lbrace_funcÚon_rbrace_funcÚtype_lookup_func)ÚoptimizeÚlextabÚ	outputdir)Úabstract_declaratorÚassignment_expressionÚdeclaration_listÚdeclaration_specifiers_no_typeÚdesignationÚ
expressionÚidentifier_listÚinit_declarator_listÚid_init_declarator_listÚinitializer_listÚparameter_type_listÚblock_item_listÚtype_qualifier_listÚstruct_declarator_listÚtranslation_unit_or_empty)ÚmoduleÚstartÚdebugr   Ú	tabmoduler   N)Ú_lex_error_funcÚ_lex_on_lbrace_funcÚ_lex_on_rbrace_funcÚ_lex_type_lookup_funcÚclexÚbuildÚtokensÚ_create_opt_ruler   ÚcparserÚdictÚ_scope_stackÚ_last_yielded_token)
ÚselfÚlex_optimizeÚlexerr   Úyacc_optimizeÚyacctabÚ
yacc_debugÚtaboutputdirÚrules_with_optÚrule© r=   úD/var/www/html/env/lib/python3.10/site-packages/pycparser/c_parser.pyÚ__init__   s2   :üý
ú

zCParser.__init__r   c                 C   s6   || 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)Úinputr6   r&   )r,   ÚfilenameÚreset_linenor1   r2   r3   r0   Úparse)r4   ÚtextrA   Ú
debuglevelr=   r=   r>   rC   „   s   

ýzCParser.parsec                 C   s   | j  tƒ ¡ d S ©N)r2   Úappendr1   ©r4   r=   r=   r>   Ú_push_scopeœ   s   zCParser._push_scopec                 C   s    t | jƒdks	J ‚| j ¡  d S )Nr   )Úlenr2   ÚpoprH   r=   r=   r>   Ú
_pop_scopeŸ   s   zCParser._pop_scopec                 C   s4   | j d  |d¡s|  d| |¡ d| j d |< dS )zC Add a new typedef name (ie a TYPEID) to the current scope
        éÿÿÿÿTz;Typedef %r previously declared as non-typedef in this scopeN©r2   ÚgetÚ_parse_error©r4   ÚnameÚcoordr=   r=   r>   Ú_add_typedef_name£   s   ÿþzCParser._add_typedef_namec                 C   s4   | j d  |d¡r|  d| |¡ d| j d |< dS )ze Add a new object, function, or enum member name (ie an ID) to the
            current scope
        rM   Fz;Non-typedef %r previously declared as typedef in this scopeNrN   rQ   r=   r=   r>   Ú_add_identifier¬   s   ÿþzCParser._add_identifierc                 C   s.   t | jƒD ]}| |¡}|dur|  S qdS )z8 Is *name* a typedef-name in the current scope?
        NF)Úreversedr2   rO   )r4   rR   ÚscopeÚin_scoper=   r=   r>   Ú_is_type_in_scope¶   s   
zCParser._is_type_in_scopec                 C   s   |   ||  ||¡¡ d S rF   )rP   Ú_coord)r4   ÚmsgÚlineÚcolumnr=   r=   r>   r(   À   s   zCParser._lex_error_funcc                 C   ó   |   ¡  d S rF   )rI   rH   r=   r=   r>   r)   Ã   ó   zCParser._lex_on_lbrace_funcc                 C   r^   rF   )rL   rH   r=   r=   r>   r*   Æ   r_   zCParser._lex_on_rbrace_funcc                 C   s   |   |¡}|S )z§ Looks up types that were previously defined with
            typedef.
            Passed to the lexer for recognizing identifiers that
            are types.
        )rY   )r4   rR   Ú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,   Ú
last_tokenrH   r=   r=   r>   Ú_get_yacc_lookahead_tokenÒ   s   z!CParser._get_yacc_lookahead_tokenc                 C   sh   |}|}|j r|j }|j st|tjƒr||_ |S |}t|j tjƒs+|j }t|j tjƒr!|j |_ ||_ |S )z  Tacks a type modifier on a declarator, and returns
            the modified declarator.

            Note: the declarator and modifier may be modified
        )ÚtypeÚ
isinstancer   ÚTypeDecl)r4   ÚdeclÚmodifierÚmodifier_headÚmodifier_tailÚ	decl_tailr=   r=   r>   Ú_type_modify_declû   s   ÿÿzCParser._type_modify_declc                 C   sÎ   |}t |tjƒs|j}t |tjƒr|j|_|j|_|D ]}t |tjƒs8t|ƒdkr1|  	d|j
¡ q||_|  S q|sUt |jtjƒsI|  	d|j
¡ tjdg|j
d�|_|S 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©rS   c                 S   s   g | ]
}|j D ]}|‘qqS r=   )Únames)Ú.0ÚidrR   r=   r=   r>   Ú
<listcomp>[  s    z/CParser._fix_decl_name_type.<locals>.<listcomp>r   )rd   r   re   rc   ÚdeclnamerR   ÚqualsÚIdentifierTyperJ   rP   rS   ÚFuncDecl)r4   rf   Útypenamerc   Útnr=   r=   r>   Ú_fix_decl_name_type2  s<   ÿÿúÿþ
ýþzCParser._fix_decl_name_typec                 C   s>   |p	t g g g g d�}|r||  |¡ |S ||  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.
            If `append` is True, the new specifier is added to the end of
            the specifiers list, otherwise it's added at the beginning.
            Returns the declaration specifier, with the new
            specifier incorporated.
        ©ÚqualÚstoragerc   Úfunctionr   )r1   rG   Úinsert)r4   ÚdeclspecÚnewspecÚkindrG   Úspecr=   r=   r>   Ú_add_declaration_specifier_  s   þz"CParser._add_declaration_specifierc                 C   s>  d|d v }g }|d   d¡durn—|d d du rqt|d ƒdk s9t|d d	 jƒd
ks9|  |d d	 jd ¡sRd}|d D ]}t|dƒrK|j} nq?|  d|¡ tj|d d	 jd dd|d d	 jd�|d d< |d d	= n8t	|d d tj
tjtjfƒs©|d d }t	|tjƒs•|j}t	|tjƒrŒ|jdu r©|d d	 jd |_|d d	= |D ]q}	|	d dusµJ ‚|rËtjd|d |d |	d |	d jd�}
ntjd|d |d |d |	d |	  d¡|	  d¡|	d jd�}
t	|
jtj
tjtjfƒrø|
}n|  |
|d ¡}|�r|�r|  |j|j¡ n|  |j|j¡ | |¡ q«|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.
        Útypedefr{   r   ÚbitsizeNrf   rc   é   rM   r   ú?rS   zInvalid declaration©rr   rc   rs   rS   rz   )rR   rs   r{   rc   rS   r|   Úinit©rR   rs   r{   Úfuncspecrc   rˆ   r„   rS   )rO   rJ   rn   rY   ÚhasattrrS   rP   r   re   rd   ÚStructÚUnionrt   rc   rr   ÚTypedefÚDeclrx   rT   rR   rU   rG   )r4   r�   ÚdeclsÚtypedef_namespaceÚ
is_typedefÚdeclarationsrS   ÚtÚdecls_0_tailrf   ÚdeclarationÚ
fixed_declr=   r=   r>   Ú_build_declarationsw  s~   &ÿ
þüÿÿ

ûø
ÿzCParser._build_declarationsc                 C   sB   d|d vsJ ‚| j |t|dd�gdd�d }tj||||jd�S )	z' Builds a function definition.
        rƒ   r{   N©rf   rˆ   T©r�   r�   r‘   r   )rf   Úparam_declsÚbodyrS   )r˜   r1   r   ÚFuncDefrS   )r4   r�   rf   r›   rœ   r–   r=   r=   r>   Ú_build_function_definitionÐ  s   ýýüz"CParser._build_function_definitionc                 C   s   |dkrt jS t jS )z` Given a token (either STRUCT or UNION), selects the
            appropriate AST class.
        Ústruct)r   rŒ   r�   )r4   Útokenr=   r=   r>   Ú_select_struct_union_classà  s   z"CParser._select_struct_union_class)
)ÚleftÚLOR)r¢   ÚLAND)r¢   ÚOR)r¢   ÚXOR)r¢   ÚAND)r¢   ÚEQÚNE)r¢   ÚGTÚGEÚLTÚLE)r¢   ÚRSHIFTÚLSHIFT)r¢   ÚPLUSÚMINUS)r¢   ÚTIMESÚDIVIDEÚMODc                 C   s4   |d du rt  g ¡|d< dS t  |d ¡|d< dS )zh translation_unit_or_empty   : translation_unit
                                        | empty
        r   Nr   )r   ÚFileAST©r4   Úpr=   r=   r>   Úp_translation_unit_or_empty  s   z#CParser.p_translation_unit_or_emptyc                 C   ó   |d |d< dS )z4 translation_unit    : external_declaration
        r   r   Nr=   r¶   r=   r=   r>   Úp_translation_unit_1
  ó   zCParser.p_translation_unit_1c                 C   s"   |d   |d ¡ |d |d< dS )zE translation_unit    : translation_unit external_declaration
        r   r…   r   N)Úextendr¶   r=   r=   r>   Úp_translation_unit_2  s   zCParser.p_translation_unit_2c                 C   ó   |d g|d< dS )z7 external_declaration    : function_definition
        r   r   Nr=   r¶   r=   r=   r>   Úp_external_declaration_1  ó   z CParser.p_external_declaration_1c                 C   r¹   )z/ external_declaration    : declaration
        r   r   Nr=   r¶   r=   r=   r>   Úp_external_declaration_2!  ó   z CParser.p_external_declaration_2c                 C   r¾   )zi external_declaration    : pp_directive
                                    | pppragma_directive
        r   r   Nr=   r¶   r=   r=   r>   Úp_external_declaration_3&  s   z CParser.p_external_declaration_3c                 C   s   g |d< dS )z( external_declaration    : SEMI
        r   Nr=   r¶   r=   r=   r>   Úp_external_declaration_4,  ó   z CParser.p_external_declaration_4c                 C   s   |   d|  |d¡¡ dS )z  pp_directive  : PPHASH
        zDirectives not supported yetr   N)rP   Ú_token_coordr¶   r=   r=   r>   Úp_pp_directive1  s   
ÿzCParser.p_pp_directivec                 C   sH   t |ƒdkrt |d |  |d¡¡|d< dS t d|  |d¡¡|d< dS )zg pppragma_directive      : PPPRAGMA
                                    | PPPRAGMA PPPRAGMASTR
        é   r…   r   r   r   N)rJ   r   ÚPragmarÆ   r¶   r=   r=   r>   Úp_pppragma_directive7  s    zCParser.p_pppragma_directivec              	   C   sL   t g g tjdg|  |d¡d�gg d�}| j||d |d |d d�|d< d	S )
zU function_definition : id_declarator declaration_list_opt compound_statement
        rl   r   rm   ry   r…   rÈ   ©r�   rf   r›   rœ   r   N)r1   r   rt   rÆ   rž   ©r4   r·   r�   r=   r=   r>   Úp_function_definition_1C  s   
ÿûüzCParser.p_function_definition_1c                 C   s.   |d }| j ||d |d |d d�|d< dS )zl function_definition : declaration_specifiers id_declarator declaration_list_opt compound_statement
        r   r…   rÈ   é   rË   r   N)rž   rÌ   r=   r=   r>   Úp_function_definition_2T  s   üzCParser.p_function_definition_2c                 C   r¹   )a7   statement   : labeled_statement
                        | expression_statement
                        | compound_statement
                        | selection_statement
                        | iteration_statement
                        | jump_statement
                        | pppragma_directive
        r   r   Nr=   r¶   r=   r=   r>   Úp_statement_  s   	zCParser.p_statementc                 C   sV   t |d tjƒr#t|ƒdkr#tj|d |d g|  |d¡d�|d< dS |d |d< dS )zx pragmacomp_or_statement     : pppragma_directive statement
                                        | statement
        r   rÈ   r…   ©Úblock_itemsrS   r   N)rd   r   rÉ   rJ   ÚCompoundrÆ   r¶   r=   r=   r>   Úp_pragmacomp_or_statement”  s   
þz!CParser.p_pragmacomp_or_statementc              
   C   s¶   |d }|d du rK|d }t jt jt jf}t|ƒdkr=t|d |ƒr=t jd|d |d |d |d dd|d jd	�g}n| j|t	ddd
�gdd�}n
| j||d dd�}||d< dS )z˜ decl_body : declaration_specifiers init_declarator_list_opt
                      | declaration_specifiers_no_type id_init_declarator_list_opt
        r   r…   Nrc   r   rz   r{   r|   r‰   r™   Trš   )
r   rŒ   r�   ÚEnumrJ   rd   r�   rS   r˜   r1   )r4   r·   r�   ÚtyÚs_u_or_er�   r=   r=   r>   Úp_decl_body¨  s4   
øýýzCParser.p_decl_bodyc                 C   r¹   )z& declaration : decl_body SEMI
        r   r   Nr=   r¶   r=   r=   r>   Úp_declarationä  rÂ   zCParser.p_declarationc                 C   s,   t |ƒdkr
|d n|d |d  |d< dS )zj declaration_list    : declaration
                                | declaration_list declaration
        r…   r   r   N©rJ   r¶   r=   r=   r>   Úp_declaration_listí  ó   ,zCParser.p_declaration_listc                 C   ó   |   |d |d d¡|d< dS )z] declaration_specifiers_no_type  : type_qualifier declaration_specifiers_no_type_opt
        r…   r   rz   r   N©r‚   r¶   r=   r=   r>   Ú"p_declaration_specifiers_no_type_1ø  ó   z*CParser.p_declaration_specifiers_no_type_1c                 C   rÝ   )zf declaration_specifiers_no_type  : storage_class_specifier declaration_specifiers_no_type_opt
        r…   r   r{   r   NrÞ   r¶   r=   r=   r>   Ú"p_declaration_specifiers_no_type_2ý  rà   z*CParser.p_declaration_specifiers_no_type_2c                 C   rÝ   )za declaration_specifiers_no_type  : function_specifier declaration_specifiers_no_type_opt
        r…   r   r|   r   NrÞ   r¶   r=   r=   r>   Ú"p_declaration_specifiers_no_type_3  rà   z*CParser.p_declaration_specifiers_no_type_3c                 C   ó"   | j |d |d ddd�|d< dS )zI declaration_specifiers  : declaration_specifiers type_qualifier
        r   r…   rz   T©rG   r   NrÞ   r¶   r=   r=   r>   Úp_declaration_specifiers_1  ó   "z"CParser.p_declaration_specifiers_1c                 C   rã   )zR declaration_specifiers  : declaration_specifiers storage_class_specifier
        r   r…   r{   Trä   r   NrÞ   r¶   r=   r=   r>   Úp_declaration_specifiers_2  ræ   z"CParser.p_declaration_specifiers_2c                 C   rã   )zM declaration_specifiers  : declaration_specifiers function_specifier
        r   r…   r|   Trä   r   NrÞ   r¶   r=   r=   r>   Úp_declaration_specifiers_3  ræ   z"CParser.p_declaration_specifiers_3c                 C   rã   )zS declaration_specifiers  : declaration_specifiers type_specifier_no_typeid
        r   r…   rc   Trä   r   NrÞ   r¶   r=   r=   r>   Úp_declaration_specifiers_4  ræ   z"CParser.p_declaration_specifiers_4c                 C   ó   |   d|d d¡|d< dS )z2 declaration_specifiers  : type_specifier
        Nr   rc   r   rÞ   r¶   r=   r=   r>   Úp_declaration_specifiers_5  ó   z"CParser.p_declaration_specifiers_5c                 C   rã   )zQ declaration_specifiers  : declaration_specifiers_no_type type_specifier
        r   r…   rc   Trä   r   NrÞ   r¶   r=   r=   r>   Úp_declaration_specifiers_6!  ræ   z"CParser.p_declaration_specifiers_6c                 C   r¹   )zß storage_class_specifier : AUTO
                                    | REGISTER
                                    | STATIC
                                    | EXTERN
                                    | TYPEDEF
        r   r   Nr=   r¶   r=   r=   r>   Úp_storage_class_specifier'  s   z!CParser.p_storage_class_specifierc                 C   r¹   )z& function_specifier  : INLINE
        r   r   Nr=   r¶   r=   r=   r>   Úp_function_specifier0  rÂ   zCParser.p_function_specifierc                 C   ó$   t j|d g|  |d¡d�|d< dS )a+   type_specifier_no_typeid  : VOID
                                      | _BOOL
                                      | CHAR
                                      | SHORT
                                      | INT
                                      | LONG
                                      | FLOAT
                                      | DOUBLE
                                      | _COMPLEX
                                      | SIGNED
                                      | UNSIGNED
                                      | __INT128
        r   rm   r   N©r   rt   rÆ   r¶   r=   r=   r>   Úp_type_specifier_no_typeid5  s   $z"CParser.p_type_specifier_no_typeidc                 C   r¹   )zÄ type_specifier  : typedef_name
                            | enum_specifier
                            | struct_or_union_specifier
                            | type_specifier_no_typeid
        r   r   Nr=   r¶   r=   r=   r>   Úp_type_specifierE  s   zCParser.p_type_specifierc                 C   r¹   )zo type_qualifier  : CONST
                            | RESTRICT
                            | VOLATILE
        r   r   Nr=   r¶   r=   r=   r>   Úp_type_qualifierM  r»   zCParser.p_type_qualifierc                 C   ó0   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   NrÚ   r¶   r=   r=   r>   Úp_init_declarator_listT  ó   0zCParser.p_init_declarator_listc                 C   ó,   t |d t|ƒdkr|d ndd�|d< dS )zb init_declarator : declarator
                            | declarator EQUALS initializer
        r   r…   rÈ   Nr™   r   ©r1   rJ   r¶   r=   r=   r>   Úp_init_declarator]  rÜ   zCParser.p_init_declaratorc                 C   rõ   )z� id_init_declarator_list    : id_init_declarator
                                       | id_init_declarator_list COMMA init_declarator
        rÎ   r   rÈ   r   NrÚ   r¶   r=   r=   r>   Úp_id_init_declarator_listc  r÷   z!CParser.p_id_init_declarator_listc                 C   rø   )zn id_init_declarator : id_declarator
                               | id_declarator EQUALS initializer
        r   r…   rÈ   Nr™   r   rù   r¶   r=   r=   r>   Úp_id_init_declaratori  rÜ   zCParser.p_id_init_declaratorc                 C   rã   )zY specifier_qualifier_list    : specifier_qualifier_list type_specifier_no_typeid
        r   r…   rc   Trä   r   NrÞ   r¶   r=   r=   r>   Úp_specifier_qualifier_list_1q  ræ   z$CParser.p_specifier_qualifier_list_1c                 C   rã   )zO specifier_qualifier_list    : specifier_qualifier_list type_qualifier
        r   r…   rz   Trä   r   NrÞ   r¶   r=   r=   r>   Úp_specifier_qualifier_list_2v  ræ   z$CParser.p_specifier_qualifier_list_2c                 C   rê   )z4 specifier_qualifier_list  : type_specifier
        Nr   rc   r   rÞ   r¶   r=   r=   r>   Úp_specifier_qualifier_list_3{  rì   z$CParser.p_specifier_qualifier_list_3c                 C   s2   t |d g g g d�}| j||d ddd�|d< dS )	zH specifier_qualifier_list  : type_qualifier_list type_specifier
        r   ry   r…   rc   Trä   r   N)r1   r‚   rÌ   r=   r=   r>   Úp_specifier_qualifier_list_4€  s   z$CParser.p_specifier_qualifier_list_4c                 C   s0   |   |d ¡}||d d|  |d¡d�|d< dS )z{ struct_or_union_specifier   : struct_or_union ID
                                        | struct_or_union TYPEID
        r   r…   N©rR   r�   rS   r   )r¡   rÆ   ©r4   r·   Úklassr=   r=   r>   Úp_struct_or_union_specifier_1‰  s   
ýz%CParser.p_struct_or_union_specifier_1c                 C   sZ   |   |d ¡}t|ƒdkr|dg |  |d¡d�|d< dS |d|d |  |d¡d�|d< dS )z³ struct_or_union_specifier : struct_or_union brace_open struct_declaration_list brace_close
                                      | struct_or_union brace_open brace_close
        r   rÎ   Nr…   r  r   rÈ   ©r¡   rJ   rÆ   r  r=   r=   r>   Úp_struct_or_union_specifier_2”  s   
ý
ýz%CParser.p_struct_or_union_specifier_2c                 C   sb   |   |d ¡}t|ƒdkr||d g |  |d¡d�|d< dS ||d |d |  |d¡d�|d< dS )a…   struct_or_union_specifier   : struct_or_union ID brace_open struct_declaration_list brace_close
                                        | struct_or_union ID brace_open brace_close
                                        | struct_or_union TYPEID brace_open struct_declaration_list brace_close
                                        | struct_or_union TYPEID brace_open brace_close
        r   é   r…   r  r   rÎ   Nr  r  r=   r=   r>   Úp_struct_or_union_specifier_3¦  s   
ý
ýz%CParser.p_struct_or_union_specifier_3c                 C   r¹   )zF struct_or_union : STRUCT
                            | UNION
        r   r   Nr=   r¶   r=   r=   r>   Úp_struct_or_union¹  ó   zCParser.p_struct_or_unionc                 C   s<   t |ƒdkr|d pg |d< dS |d |d pg  |d< dS )z� struct_declaration_list     : struct_declaration
                                        | struct_declaration_list struct_declaration
        r…   r   r   NrÚ   r¶   r=   r=   r>   Úp_struct_declaration_listÁ  s   z!CParser.p_struct_declaration_listc                 C   s¬   |d }d|d vsJ ‚|d dur| j ||d d�}n4t|d ƒdkrD|d d }t|tjƒr3|}nt |¡}| 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   rƒ   r{   r…   N©r�   r�   rc   r   ©rf   r™   )r˜   rJ   rd   r   ÚNodert   r1   )r4   r·   r�   r�   ÚnodeÚ	decl_typer=   r=   r>   Úp_struct_declaration_1Ê  s*   þ

þ	þzCParser.p_struct_declaration_1c                 C   ó   d|d< dS )z# struct_declaration : SEMI
        Nr   r=   r¶   r=   r=   r>   Úp_struct_declaration_2ð  rÅ   zCParser.p_struct_declaration_2c                 C   r¾   )z1 struct_declaration : pppragma_directive
        r   r   Nr=   r¶   r=   r=   r>   Úp_struct_declaration_3õ  rÀ   zCParser.p_struct_declaration_3c                 C   rõ   )zŠ struct_declarator_list  : struct_declarator
                                    | struct_declarator_list COMMA struct_declarator
        rÎ   r   rÈ   r   NrÚ   r¶   r=   r=   r>   Úp_struct_declarator_listú  r÷   z CParser.p_struct_declarator_listc                 C   s   |d ddœ|d< dS )z( struct_declarator : declarator
        r   N©rf   r„   r   r=   r¶   r=   r=   r>   Úp_struct_declarator_1  s   zCParser.p_struct_declarator_1c                 C   sF   t |ƒdkr|d |d dœ|d< dS t ddd¡|d dœ|d< dS )z€ struct_declarator   : declarator COLON constant_expression
                                | COLON constant_expression
        rÈ   r   r  r   Nr…   )rJ   r   re   r¶   r=   r=   r>   Úp_struct_declarator_2  s    zCParser.p_struct_declarator_2c                 C   s"   t  |d d|  |d¡¡|d< dS )zM enum_specifier  : ENUM ID
                            | ENUM TYPEID
        r…   Nr   r   ©r   rÕ   rÆ   r¶   r=   r=   r>   Úp_enum_specifier_1  s   "zCParser.p_enum_specifier_1c                 C   s"   t  d|d |  |d¡¡|d< dS )zG enum_specifier  : ENUM brace_open enumerator_list brace_close
        NrÈ   r   r   r  r¶   r=   r=   r>   Úp_enum_specifier_2  ræ   zCParser.p_enum_specifier_2c                 C   ó&   t  |d |d |  |d¡¡|d< dS )z› enum_specifier  : ENUM ID brace_open enumerator_list brace_close
                            | ENUM TYPEID brace_open enumerator_list brace_close
        r…   rÎ   r   r   Nr  r¶   r=   r=   r>   Úp_enum_specifier_3  s   &zCParser.p_enum_specifier_3c                 C   sl   t |ƒdkrt |d g|d j¡|d< dS t |ƒdkr$|d |d< dS |d j |d ¡ |d |d< dS )z™ enumerator_list : enumerator
                            | enumerator_list COMMA
                            | enumerator_list COMMA enumerator
        r…   r   r   rÈ   N)rJ   r   ÚEnumeratorListrS   ÚenumeratorsrG   r¶   r=   r=   r>   Úp_enumerator_list"  s    zCParser.p_enumerator_listc                 C   sb   t |ƒdkrt |d d|  |d¡¡}nt |d |d |  |d¡¡}|  |j|j¡ ||d< dS )zR enumerator  : ID
                        | ID EQUALS constant_expression
        r…   r   NrÈ   r   )rJ   r   Ú
EnumeratorrÆ   rU   rR   rS   )r4   r·   Ú
enumeratorr=   r=   r>   Úp_enumerator/  s   
þ
þzCParser.p_enumeratorc                 C   r¹   )zQ declarator  : id_declarator
                        | typeid_declarator
        r   r   Nr=   r¶   r=   r=   r>   Úp_declarator?  r
  zCParser.p_declarator)rp   ÚID)ÚtypeidÚTYPEID)Útypeid_noparenr'  c                 C   r¹   )z1 xxx_declarator  : direct_xxx_declarator
        r   r   Nr=   r¶   r=   r=   r>   Úp_xxx_declarator_1E  r
  zCParser.p_xxx_declarator_1c                 C   ó   |   |d |d ¡|d< dS )z9 xxx_declarator  : pointer direct_xxx_declarator
        r…   r   r   N©rk   r¶   r=   r=   r>   Úp_xxx_declarator_2K  ó   zCParser.p_xxx_declarator_2c                 C   s&   t j|d dd|  |d¡d�|d< dS )z' direct_xxx_declarator   : yyy
        r   Nr‡   r   )r   re   rÆ   r¶   r=   r=   r>   Úp_direct_xxx_declarator_1Q  s   
üz!CParser.p_direct_xxx_declarator_1c                 C   r¹   )z@ direct_xxx_declarator   : LPAREN xxx_declarator RPAREN
        r…   r   Nr=   r¶   r=   r=   r>   Úp_direct_xxx_declarator_2[  r
  z!CParser.p_direct_xxx_declarator_2c                 C   sf   t |ƒdkr
|d ng pg }tjdt |ƒdkr|d n|d ||d jd�}| j|d |d�|d< dS )	z} direct_xxx_declarator   : direct_xxx_declarator LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET
        r  rÈ   NrÎ   r   ©rc   ÚdimÚ	dim_qualsrS   ©rf   rg   r   )rJ   r   Ú	ArrayDeclrS   rk   )r4   r·   rs   Úarrr=   r=   r>   Úp_direct_xxx_declarator_3a  s   üz!CParser.p_direct_xxx_declarator_3c                 C   s^   dd„ |d |d fD ƒ}dd„ |D ƒ}t jd|d ||d jd	�}| j|d |d
�|d< dS )zÿ direct_xxx_declarator   : direct_xxx_declarator LBRACKET STATIC type_qualifier_list_opt assignment_expression RBRACKET
                                    | direct_xxx_declarator LBRACKET type_qualifier_list STATIC assignment_expression RBRACKET
        c                 S   s    g | ]}t |tƒr|n|g‘qS r=   ©rd   Úlist)ro   Úitemr=   r=   r>   rq   x  s    ÿz5CParser.p_direct_xxx_declarator_4.<locals>.<listcomp>rÈ   rÎ   c                 S   s"   g | ]}|D ]}|d ur|‘qqS rF   r=   )ro   Úsublistrz   r=   r=   r>   rq   z  s    ÿNr  r   r0  r3  r   ©r   r4  rS   rk   )r4   r·   Úlisted_qualsr2  r5  r=   r=   r>   Úp_direct_xxx_declarator_4p  s   ÿüz!CParser.p_direct_xxx_declarator_4c              	   C   sZ   t jdt  |d |  |d¡¡|d dkr|d ng |d jd�}| j|d |d�|d< dS )zi direct_xxx_declarator   : direct_xxx_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET
        NrÎ   rÈ   r   r0  r3  r   ©r   r4  r%  rÆ   rS   rk   ©r4   r·   r5  r=   r=   r>   Úp_direct_xxx_declarator_5†  s   üz!CParser.p_direct_xxx_declarator_5c                 C   sz   t j|d d|d jd�}|  ¡ jdkr0|jdur0|jjD ]}t|t jƒr' n	|  	|j
|j¡ q| j|d |d�|d< dS )z¹ direct_xxx_declarator   : direct_xxx_declarator LPAREN parameter_type_list RPAREN
                                    | direct_xxx_declarator LPAREN identifier_list_opt RPAREN
        rÈ   Nr   ©Úargsrc   rS   ÚLBRACEr3  r   )r   ru   rS   rb   rc   rB  Úparamsrd   ÚEllipsisParamrU   rR   rk   )r4   r·   ÚfuncÚparamr=   r=   r>   Úp_direct_xxx_declarator_6’  s   ý
z!CParser.p_direct_xxx_declarator_6c                 C   st   |   |d¡}tj|d pg d|d�}t|ƒdkr4|d }|jdur)|j}|jdus!||_|d |d< dS ||d< dS )zm pointer : TIMES type_qualifier_list_opt
                    | TIMES type_qualifier_list_opt pointer
        r   r…   N)rs   rc   rS   rÈ   r   )rÆ   r   ÚPtrDeclrJ   rc   )r4   r·   rS   Únested_typeÚ	tail_typer=   r=   r>   Ú	p_pointer¯  s   

ÿzCParser.p_pointerc                 C   ó0   t |ƒdkr|d gn|d |d g |d< dS )zs type_qualifier_list : type_qualifier
                                | type_qualifier_list type_qualifier
        r…   r   r   NrÚ   r¶   r=   r=   r>   Úp_type_qualifier_listÍ  r÷   zCParser.p_type_qualifier_listc                 C   s:   t |ƒdkr|d j t |  |d¡¡¡ |d |d< dS )zn parameter_type_list : parameter_list
                                | parameter_list COMMA ELLIPSIS
        r…   r   rÈ   r   N)rJ   rD  rG   r   rE  rÆ   r¶   r=   r=   r>   Úp_parameter_type_listÓ  s   zCParser.p_parameter_type_listc                 C   óP   t |ƒdkrt |d g|d j¡|d< dS |d j |d ¡ |d |d< dS )zz parameter_list  : parameter_declaration
                            | parameter_list COMMA parameter_declaration
        r…   r   r   rÈ   N©rJ   r   Ú	ParamListrS   rD  rG   r¶   r=   r=   r>   Úp_parameter_listÜ  ó    zCParser.p_parameter_listc                 C   sT   |d }|d st jdg|  |d¡d�g|d< | j|t|d d�gd�d |d< d	S )
zŸ parameter_declaration   : declaration_specifiers id_declarator
                                    | declaration_specifiers typeid_noparen_declarator
        r   rc   rl   rm   r…   r  r  r   N)r   rt   rÆ   r˜   r1   rÌ   r=   r=   r>   Úp_parameter_declaration_1ð  s   
ÿþþz!CParser.p_parameter_declaration_1c                 C   sÞ   |d }|d st jdg|  |d¡d�g|d< t|d ƒdkrGt|d d jƒdkrG|  |d d jd ¡rG| j|t|d dd	�gd
�d }n"t jd|d |d pWt  	ddd¡|  |d¡d�}|d }|  
||¡}||d< dS )zR parameter_declaration   : declaration_specifiers abstract_declarator_opt
        r   rc   rl   rm   rM   r   r…   Nr™   r  r   rz   ©rR   rs   rc   rS   )r   rt   rÆ   rJ   rn   rY   r˜   r1   ÚTypenamere   rx   )r4   r·   r�   rf   rv   r=   r=   r>   Úp_parameter_declaration_2ü  s.   
ÿ&ÿþþ
üz!CParser.p_parameter_declaration_2c                 C   rP  )ze identifier_list : identifier
                            | identifier_list COMMA identifier
        r…   r   r   rÈ   NrQ  r¶   r=   r=   r>   Úp_identifier_list  rT  zCParser.p_identifier_listc                 C   r¹   )z- initializer : assignment_expression
        r   r   Nr=   r¶   r=   r=   r>   Úp_initializer_1%  rÂ   zCParser.p_initializer_1c                 C   s8   |d du rt  g |  |d¡¡|d< dS |d |d< dS )z‹ initializer : brace_open initializer_list_opt brace_close
                        | brace_open initializer_list COMMA brace_close
        r…   Nr   r   )r   ÚInitListrÆ   r¶   r=   r=   r>   Úp_initializer_2*  s   zCParser.p_initializer_2c                 C   s˜   t |ƒdkr(|d du r|d n	t |d |d ¡}t |g|d j¡|d< dS |d du r2|d n	t |d |d ¡}|d j |¡ |d |d< dS )z� initializer_list    : designation_opt initializer
                                | initializer_list COMMA designation_opt initializer
        rÈ   r   Nr…   r   rÎ   )rJ   r   ÚNamedInitializerr[  rS   ÚexprsrG   )r4   r·   rˆ   r=   r=   r>   Úp_initializer_list3  s   ((zCParser.p_initializer_listc                 C   r¹   )z. designation : designator_list EQUALS
        r   r   Nr=   r¶   r=   r=   r>   Úp_designation?  rÂ   zCParser.p_designationc                 C   rM  )z_ designator_list : designator
                            | designator_list designator
        r…   r   r   NrÚ   r¶   r=   r=   r>   Úp_designator_listG  r÷   zCParser.p_designator_listc                 C   r¹   )zi designator  : LBRACKET constant_expression RBRACKET
                        | PERIOD identifier
        r…   r   Nr=   r¶   r=   r=   r>   Úp_designatorM  r
  zCParser.p_designatorc                 C   sP   t jd|d d |d pt  ddd¡|  |d¡d�}|  ||d d ¡|d< dS )	zH type_name   : specifier_qualifier_list abstract_declarator_opt
        r   r   rz   r…   NrV  rc   r   )r   rW  re   rÆ   rx   )r4   r·   rv   r=   r=   r>   Úp_type_nameS  s   

üzCParser.p_type_namec                 C   s(   t  ddd¡}| j||d d�|d< dS )z+ abstract_declarator     : pointer
        Nr   r3  r   )r   re   rk   )r4   r·   Ú	dummytyper=   r=   r>   Úp_abstract_declarator_1^  s
   þzCParser.p_abstract_declarator_1c                 C   r*  )zF abstract_declarator     : pointer direct_abstract_declarator
        r…   r   r   Nr+  r¶   r=   r=   r>   Úp_abstract_declarator_2f  s   zCParser.p_abstract_declarator_2c                 C   r¹   )z> abstract_declarator     : direct_abstract_declarator
        r   r   Nr=   r¶   r=   r=   r>   Úp_abstract_declarator_3k  rÂ   zCParser.p_abstract_declarator_3c                 C   r¹   )zA direct_abstract_declarator  : LPAREN abstract_declarator RPAREN r…   r   Nr=   r¶   r=   r=   r>   Úp_direct_abstract_declarator_1u  ó   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   r0  r3  r   r;  r?  r=   r=   r>   Úp_direct_abstract_declarator_2y  s   üz&CParser.p_direct_abstract_declarator_2c                 C   s`   t |ƒdkr
|d ng pg }tjt ddd¡t |ƒdkr |d n|d ||  |d¡d�|d< dS )zk direct_abstract_declarator  : LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET
        rÎ   r…   NrÈ   r   r0  r   )rJ   r   r4  re   rÆ   )r4   r·   rs   r=   r=   r>   Úp_direct_abstract_declarator_3„  s   
üz&CParser.p_direct_abstract_declarator_3c              	   C   sF   t jdt  |d |  |d¡¡g |d jd�}| j|d |d�|d< dS )zZ direct_abstract_declarator  : direct_abstract_declarator LBRACKET TIMES RBRACKET
        NrÈ   r   r0  r3  r   r>  r?  r=   r=   r>   Úp_direct_abstract_declarator_4Ž  s   üz&CParser.p_direct_abstract_declarator_4c              	   C   s@   t jt  ddd¡t  |d |  |d¡¡g |  |d¡d�|d< dS )z? direct_abstract_declarator  : LBRACKET TIMES RBRACKET
        NrÈ   r   r0  r   )r   r4  re   r%  rÆ   r¶   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   rA  r3  r   )r   ru   rS   rk   )r4   r·   rF  r=   r=   r>   Úp_direct_abstract_declarator_6¢  s   ýz&CParser.p_direct_abstract_declarator_6c                 C   s.   t j|d t  ddd¡|  |d¡d�|d< dS )zM direct_abstract_declarator  : LPAREN parameter_type_list_opt RPAREN
        r…   Nr   rA  r   )r   ru   re   rÆ   r¶   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   Nr7  r¶   r=   r=   r>   Úp_block_item·  ó   (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
        r…   Nr   r   rÚ   r¶   r=   r=   r>   Úp_block_item_list¿  s   :zCParser.p_block_item_listc                 C   s"   t j|d |  |d¡d�|d< dS )zA compound_statement : brace_open block_item_list_opt brace_close r…   r   rÑ   r   N)r   rÓ   rÆ   r¶   r=   r=   r>   Úp_compound_statement_1Æ  s   
þzCParser.p_compound_statement_1c                 C   s&   t  |d |d |  |d¡¡|d< dS )z6 labeled_statement : ID COLON pragmacomp_or_statement r   rÈ   r   N)r   ÚLabelrÆ   r¶   r=   r=   r>   Úp_labeled_statement_1Ì  ó   &zCParser.p_labeled_statement_1c                 C   s(   t  |d |d g|  |d¡¡|d< dS )zL labeled_statement : CASE constant_expression COLON pragmacomp_or_statement r…   rÎ   r   r   N)r   ÚCaserÆ   r¶   r=   r=   r>   Úp_labeled_statement_2Ð  ó   (zCParser.p_labeled_statement_2c                 C   s"   t  |d g|  |d¡¡|d< dS )z; labeled_statement : DEFAULT COLON pragmacomp_or_statement rÈ   r   r   N)r   ÚDefaultrÆ   r¶   r=   r=   r>   Úp_labeled_statement_3Ô  s   "zCParser.p_labeled_statement_3c              	   C   s(   t  |d |d d|  |d¡¡|d< dS )zK selection_statement : IF LPAREN expression RPAREN pragmacomp_or_statement rÈ   r  Nr   r   ©r   ÚIfrÆ   r¶   r=   r=   r>   Úp_selection_statement_1Ø  ry  zCParser.p_selection_statement_1c              	   C   s,   t  |d |d |d |  |d¡¡|d< dS )zZ selection_statement : IF LPAREN expression RPAREN statement ELSE pragmacomp_or_statement rÈ   r  é   r   r   Nr|  r¶   r=   r=   r>   Úp_selection_statement_2Ü  s   ,zCParser.p_selection_statement_2c              	   C   s*   t t |d |d |  |d¡¡ƒ|d< dS )zO selection_statement : SWITCH LPAREN expression RPAREN pragmacomp_or_statement rÈ   r  r   r   N)r   r   ÚSwitchrÆ   r¶   r=   r=   r>   Úp_selection_statement_3à  s   ÿzCParser.p_selection_statement_3c                 C   r  )zN iteration_statement : WHILE LPAREN expression RPAREN pragmacomp_or_statement rÈ   r  r   r   N)r   ÚWhilerÆ   r¶   r=   r=   r>   Úp_iteration_statement_1å  rv  zCParser.p_iteration_statement_1c                 C   r  )zV iteration_statement : DO pragmacomp_or_statement WHILE LPAREN expression RPAREN SEMI r  r…   r   r   N)r   ÚDoWhilerÆ   r¶   r=   r=   r>   Úp_iteration_statement_2é  rv  zCParser.p_iteration_statement_2c              
   C   s2   t  |d |d |d |d |  |d¡¡|d< dS )zx iteration_statement : FOR LPAREN expression_opt SEMI expression_opt SEMI expression_opt RPAREN pragmacomp_or_statement rÈ   r  r  é	   r   r   N)r   ÚForrÆ   r¶   r=   r=   r>   Úp_iteration_statement_3í  s   2zCParser.p_iteration_statement_3c              
   C   sB   t  t  |d |  |d¡¡|d |d |d |  |d¡¡|d< dS )zp iteration_statement : FOR LPAREN declaration expression_opt SEMI expression_opt RPAREN pragmacomp_or_statement rÈ   r   rÎ   é   é   r   N)r   rˆ  ÚDeclListrÆ   r¶   r=   r=   r>   Úp_iteration_statement_4ñ  s   ÿzCParser.p_iteration_statement_4c                 C   s    t  |d |  |d¡¡|d< dS )z  jump_statement  : GOTO ID SEMI r…   r   r   N)r   ÚGotorÆ   r¶   r=   r=   r>   Úp_jump_statement_1ö  ó    zCParser.p_jump_statement_1c                 C   ó   t  |  |d¡¡|d< dS )z jump_statement  : BREAK SEMI r   r   N)r   ÚBreakrÆ   r¶   r=   r=   r>   Úp_jump_statement_2ú  ó   zCParser.p_jump_statement_2c                 C   r‘  )z! jump_statement  : CONTINUE SEMI r   r   N)r   ÚContinuerÆ   r¶   r=   r=   r>   Úp_jump_statement_3þ  r”  zCParser.p_jump_statement_3c                 C   s0   t  t|ƒdkr|d nd|  |d¡¡|d< dS )z\ jump_statement  : RETURN expression SEMI
                            | RETURN SEMI
        rÎ   r…   Nr   r   )r   ÚReturnrJ   rÆ   r¶   r=   r=   r>   Úp_jump_statement_4  r÷   zCParser.p_jump_statement_4c                 C   s6   |d du rt  |  |d¡¡|d< dS |d |d< dS )z, expression_statement : expression_opt SEMI r   Nr…   r   )r   ÚEmptyStatementrÆ   r¶   r=   r=   r>   Úp_expression_statement  s   zCParser.p_expression_statementc                 C   sl   t |ƒdkr|d |d< dS t|d tjƒs$t |d g|d j¡|d< |d j |d ¡ |d |d< dS )zn expression  : assignment_expression
                        | expression COMMA assignment_expression
        r…   r   r   rÈ   N)rJ   rd   r   ÚExprListrS   r^  rG   r¶   r=   r=   r>   Úp_expression  s   zCParser.p_expressionc                 C   rð   )z typedef_name : TYPEID r   rm   r   Nrñ   r¶   r=   r=   r>   Úp_typedef_name  ó   $zCParser.p_typedef_namec                 C   óF   t |ƒdkr|d |d< dS t |d |d |d |d j¡|d< dS )z› assignment_expression   : conditional_expression
                                    | unary_expression assignment_operator assignment_expression
        r…   r   r   rÈ   N)rJ   r   Ú
AssignmentrS   r¶   r=   r=   r>   Úp_assignment_expression   ó   *zCParser.p_assignment_expressionc                 C   r¹   )aÞ   assignment_operator : EQUALS
                                | XOREQUAL
                                | TIMESEQUAL
                                | DIVEQUAL
                                | MODEQUAL
                                | PLUSEQUAL
                                | MINUSEQUAL
                                | LSHIFTEQUAL
                                | RSHIFTEQUAL
                                | ANDEQUAL
                                | OREQUAL
        r   r   Nr=   r¶   r=   r=   r>   Úp_assignment_operator.  s   zCParser.p_assignment_operatorc                 C   r¹   )z. constant_expression : conditional_expression r   r   Nr=   r¶   r=   r=   r>   Úp_constant_expression=  ri  zCParser.p_constant_expressionc                 C   sF   t |ƒdkr|d |d< dS t |d |d |d |d j¡|d< dS )zœ conditional_expression  : binary_expression
                                    | binary_expression CONDOP expression COLON conditional_expression
        r…   r   r   rÈ   r  N)rJ   r   Ú	TernaryOprS   r¶   r=   r=   r>   Úp_conditional_expressionA  r¢  z CParser.p_conditional_expressionc                 C   rŸ  )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
        r…   r   r   rÈ   N)rJ   r   ÚBinaryOprS   r¶   r=   r=   r>   Úp_binary_expressionJ  s   *zCParser.p_binary_expressionc                 C   r¹   )z$ cast_expression : unary_expression r   r   Nr=   r¶   r=   r=   r>   Úp_cast_expression_1d  ri  zCParser.p_cast_expression_1c                 C   r  )z; cast_expression : LPAREN type_name RPAREN cast_expression r…   rÎ   r   r   N)r   ÚCastrÆ   r¶   r=   r=   r>   Úp_cast_expression_2h  rv  zCParser.p_cast_expression_2c                 C   r¹   )z* unary_expression    : postfix_expression r   r   Nr=   r¶   r=   r=   r>   Úp_unary_expression_1l  ri  zCParser.p_unary_expression_1c                 C   s$   t  |d |d |d j¡|d< dS )z¸ unary_expression    : PLUSPLUS unary_expression
                                | MINUSMINUS unary_expression
                                | unary_operator cast_expression
        r   r…   r   N©r   ÚUnaryOprS   r¶   r=   r=   r>   Úp_unary_expression_2p  s   $zCParser.p_unary_expression_2c                 C   s:   t  |d t|ƒdkr|d n|d |  |d¡¡|d< dS )zx unary_expression    : SIZEOF unary_expression
                                | SIZEOF LPAREN type_name RPAREN
        r   rÈ   r…   r   N)r   r®  rJ   rÆ   r¶   r=   r=   r>   Úp_unary_expression_3w  s
   
ýzCParser.p_unary_expression_3c                 C   r¹   )zÏ unary_operator  : AND
                            | TIMES
                            | PLUS
                            | MINUS
                            | NOT
                            | LNOT
        r   r   Nr=   r¶   r=   r=   r>   Úp_unary_operator€  s   zCParser.p_unary_operatorc                 C   r¹   )z* postfix_expression  : primary_expression r   r   Nr=   r¶   r=   r=   r>   Úp_postfix_expression_1Š  ri  zCParser.p_postfix_expression_1c                 C   s$   t  |d |d |d j¡|d< dS )zG postfix_expression  : postfix_expression LBRACKET expression RBRACKET r   rÈ   r   N)r   ÚArrayRefrS   r¶   r=   r=   r>   Úp_postfix_expression_2Ž  rž  zCParser.p_postfix_expression_2c                 C   s4   t  |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   ÚFuncCallrJ   rS   r¶   r=   r=   r>   Úp_postfix_expression_3’  s   4zCParser.p_postfix_expression_3c                 C   s>   t  |d |  |d¡¡}t  |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   r…   r   N)r   r%  rÆ   Ú	StructRefrS   )r4   r·   Úfieldr=   r=   r>   Úp_postfix_expression_4˜  s   &zCParser.p_postfix_expression_4c                 C   s(   t  d|d  |d |d j¡|d< dS )z{ postfix_expression  : postfix_expression PLUSPLUS
                                | postfix_expression MINUSMINUS
        r·   r…   r   r   Nr­  r¶   r=   r=   r>   Úp_postfix_expression_5¡  rq  zCParser.p_postfix_expression_5c                 C   s   t  |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
        r…   r  r   N)r   ÚCompoundLiteralr¶   r=   r=   r>   Úp_postfix_expression_6§  r-  zCParser.p_postfix_expression_6c                 C   r¹   )z" primary_expression  : identifier r   r   Nr=   r¶   r=   r=   r>   Úp_primary_expression_1­  ri  zCParser.p_primary_expression_1c                 C   r¹   )z  primary_expression  : constant r   r   Nr=   r¶   r=   r=   r>   Úp_primary_expression_2±  ri  zCParser.p_primary_expression_2c                 C   r¹   )zp primary_expression  : unified_string_literal
                                | unified_wstring_literal
        r   r   Nr=   r¶   r=   r=   r>   Úp_primary_expression_3µ  r
  zCParser.p_primary_expression_3c                 C   r¹   )z0 primary_expression  : LPAREN expression RPAREN r…   r   Nr=   r¶   r=   r=   r>   Úp_primary_expression_4»  ri  zCParser.p_primary_expression_4c                 C   sB   |   |d¡}t t |d |¡t |d |d g|¡|¡|d< dS )za primary_expression  : OFFSETOF LPAREN type_name COMMA offsetof_member_designator RPAREN
        r   rÈ   r  r   N)rÆ   r   rµ  r%  r›  )r4   r·   rS   r=   r=   r>   Úp_primary_expression_5¿  s
   þzCParser.p_primary_expression_5c                 C   s’   t |ƒdkr|d |d< dS t |ƒdkr)t |d |d |d |d j¡|d< dS t |ƒdkrAt |d |d |d j¡|d< dS tdt |ƒ ƒ‚)	zì offsetof_member_designator : identifier
                                         | offsetof_member_designator PERIOD identifier
                                         | offsetof_member_designator LBRACKET expression RBRACKET
        r…   r   r   rÎ   rÈ   r  z$Unexpected parsing state. len(p): %uN)rJ   r   r·  rS   r³  ÚNotImplementedErrorr¶   r=   r=   r>   Úp_offsetof_member_designatorÇ  s   *$z$CParser.p_offsetof_member_designatorc                 C   rP  )zœ argument_expression_list    : assignment_expression
                                        | argument_expression_list COMMA assignment_expression
        r…   r   r   rÈ   N)rJ   r   r›  rS   r^  rG   r¶   r=   r=   r>   Úp_argument_expression_listÕ  rT  z"CParser.p_argument_expression_listc                 C   s    t  |d |  |d¡¡|d< dS )z identifier  : ID r   r   N)r   r%  rÆ   r¶   r=   r=   r>   Úp_identifierß  r�  zCParser.p_identifierc                 C   sš   d}d}|d dd… D ]}|dv r|d7 }q|dv r|d7 }qd}|dkr*t dƒ‚|d	kr2t d
ƒ‚d| d|  }t |d |d |  |d¡¡|d< dS )zÆ constant    : INT_CONST_DEC
                        | INT_CONST_OCT
                        | INT_CONST_HEX
                        | INT_CONST_BIN
                        | INT_CONST_CHAR
        r   r   éýÿÿÿN©ÚlÚL)ÚuÚUr   z.Constant cannot have more than one u/U suffix.r…   z.Constant cannot have more than two l/L suffix.z	unsigned zlong rl   )Ú
ValueErrorr   ÚConstantrÆ   )r4   r·   ÚuCountÚlCountÚxr”   Úprefixr=   r=   r>   Úp_constant_1ã  s"   
€ÿzCParser.p_constant_1c                 C   sh   d|d   ¡ v rd}n|d d dv rd}n|d d dv r!d}nd}t ||d |  |d¡¡|d	< d
S )zM constant    : FLOAT_CONST
                        | HEX_FLOAT_CONST
        rÐ  r   ÚfloatrM   )ÚfÚFrÇ  zlong doubleÚdoubler   N)Úlowerr   rÍ  rÆ   )r4   r·   r”   r=   r=   r>   Úp_constant_2ú  s   ÿzCParser.p_constant_2c                 C   s"   t  d|d |  |d¡¡|d< dS )zH constant    : CHAR_CONST
                        | WCHAR_CONST
        Úcharr   r   N)r   rÍ  rÆ   r¶   r=   r=   r>   Úp_constant_3  s   ÿzCParser.p_constant_3c                 C   sf   t |ƒdkrt d|d |  |d¡¡|d< dS |d jdd… |d dd…  |d _|d |d< dS )z~ unified_string_literal  : STRING_LITERAL
                                    | unified_string_literal STRING_LITERAL
        r…   Ústringr   r   NrM   )rJ   r   rÍ  rÆ   Úvaluer¶   r=   r=   r>   Úp_unified_string_literal  s   ÿ(z CParser.p_unified_string_literalc                 C   sj   t |ƒdkrt d|d |  |d¡¡|d< dS |d j ¡ dd… |d dd…  |d _|d |d< dS )z� unified_wstring_literal : WSTRING_LITERAL
                                    | unified_wstring_literal WSTRING_LITERAL
        r…   rÛ  r   r   NrM   )rJ   r   rÍ  rÆ   rÜ  Úrstripr¶   r=   r=   r>   Úp_unified_wstring_literal"  s   ÿ,z!CParser.p_unified_wstring_literalc                 C   ó"   |d |d< |  d| d¡¡ dS )z  brace_open  :   LBRACE
        r   r   N©Ú
set_linenoÚlinenor¶   r=   r=   r>   Úp_brace_open-  ó   zCParser.p_brace_openc                 C   rà  )z  brace_close :   RBRACE
        r   r   Nrá  r¶   r=   r=   r>   Úp_brace_close3  rå  zCParser.p_brace_closec                 C   r  )zempty : Nr   r=   r¶   r=   r=   r>   Úp_empty9  s   zCParser.p_emptyc                 C   sB   |r|   d|j | j|j| j |¡d�¡ d S |   d| jj¡ d S )Nz
before: %s)rã  r]   zAt end of input)rP   rÜ  rZ   rã  r,   Úfind_tok_columnrA   r¶   r=   r=   r>   Úp_error=  s   
ÿþzCParser.p_errorN)r   r   )F)¥Ú__name__Ú
__module__Ú__qualname__r   r?   rC   rI   rL   rT   rU   rY   r(   r)   r*   r+   rb   rk   rx   r‚   r˜   rž   r¡   Ú
precedencer¸   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/  r6  r=  r@  rH  rL  rN  rO  rS  rU  rX  rY  rZ  r\  r_  r`  ra  rb  rc  re  rf  rg  rh  rj  rk  rl  rm  rn  ro  rp  rr  rs  ru  rx  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      s`   
øo	

	)7-Y	5<					&		





	








	
	

	

		
	
r   )ÚreÚplyr   r   r   Úc_lexerr   Ú	plyparserr   r   r   r	   r
   Úast_transformsr   r   r=   r=   r=   r>   Ú<module>   s   