U
    ^f                    @   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dLd%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@dd ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMeNddddd ZOeNddddd ZPeNddddd ZQeNdddd ZReNddddd ZSeNddddd ZTeNddddd ZUeNddddd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd ZaddĄ ZbddƄ ZcddȄ Zdddʄ Zedd̄ Zfdd΄ ZgddЄ Zhdd҄ ZiddԄ Zjddք Zkdd؄ Zlddڄ Zmdd܄ Znddބ Zodd Zpdd Zqdd Zrdd Zsdd Ztdd Zudd Zvdd Zwdd Zxdd Zydd Zzdd Z{dd Z|dd Z}dd Z~dd 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 (M  CParserTzpycparser.lextabzpycparser.yacctabF c           
      C   s   || 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}|D ]}	| |	 qZt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.
        )Z
error_funcZon_lbrace_funcZon_rbrace_funcZtype_lookup_func)optimizelextab	outputdirZabstract_declaratorZassignment_expressionZdeclaration_listZdeclaration_specifiers_no_typeZdesignationZ
expressionZidentifier_listZinit_declarator_listZid_init_declarator_listZinitializer_listZparameter_type_listZblock_item_listZtype_qualifier_listZstruct_declarator_listZtranslation_unit_or_empty)modulestartdebugr   Z	tabmoduler   N)_lex_error_func_lex_on_lbrace_func_lex_on_rbrace_func_lex_type_lookup_funcclexbuildtokensZ_create_opt_ruler   cparserdict_scope_stack_last_yielded_token)
selfZlex_optimizelexerr   Zyacc_optimizeZyacctabZ
yacc_debugZtaboutputdirZrules_with_optZrule r!   9/tmp/pip-install-v5gamh74/pycparser/pycparser/c_parser.py__init__   sN    :

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)inputr    r   )r   filenameZreset_linenor   r   r   r   parse)r   textr%   
debuglevelr!   r!   r"   r&      s    

zCParser.parsec                 C   s   | 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  d S )Nr   )lenr   AssertionErrorpopr+   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r   get_parse_errorr   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
        r1   Fz;Non-typedef %r previously declared as typedef in this scopeNr2   r5   r!   r!   r"   _add_identifier   s    zCParser._add_identifierc                 C   s.   t | jD ]}||}|dk	r
|  S q
dS )z8 Is *name* a typedef-name in the current scope?
        NF)reversedr   r3   )r   r6   scopeZin_scoper!   r!   r"   _is_type_in_scope   s
    
 
zCParser._is_type_in_scopec                 C   s   |  || || d S r)   )r4   _coord)r   msglinecolumnr!   r!   r"   r      s    zCParser._lex_error_funcc                 C   s   |    d S r)   )r,   r+   r!   r!   r"   r      s    zCParser._lex_on_lbrace_funcc                 C   s   |    d S r)   )r0   r+   r!   r!   r"   r      s    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.
        )r<   )r   r6   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_tokenr+   r!   r!   r"   _get_yacc_lookahead_token   s    z!CParser._get_yacc_lookahead_tokenc                 C   s\   |}|}|j r|j }qt|tjr,||_ |S |}t|j tjsF|j }q0|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   |}t |tjs|j}q|j|_|j|_|D ]:}t |tjs,t|dkrX| 	d|j
 q,||_|  S q,|st |jtjs| 	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r7   c                 S   s   g | ]}|j D ]}|qqS r!   )names).0idr6   r!   r!   r"   
<listcomp>[  s       z/CParser._fix_decl_name_type.<locals>.<listcomp>r   )rC   r   rD   rB   declnamer6   qualsIdentifierTyper-   r4   r7   FuncDecl)r   rE   typenamerB   tnr!   r!   r"   _fix_decl_name_type2  s:     
 
zCParser._fix_decl_name_typec                 C   s<   |pt g g g g d}|r(|| | n|| 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storagerB   functionr   )r   r*   insert)r   ZdeclspecZnewspeckindr*   specr!   r!   r"   _add_declaration_specifier_  s
    z"CParser._add_declaration_specifierc                 C   sF  d|d k}g }|d  ddk	r&n,|d d dkrt|d dk stt|d d	 jd
kst| |d d	 jd sd}|d D ]}t|dr|j} qq| d| tj|d d	 jd dd|d d	 jd|d d< |d d	= nnt	|d d tj
tjtjfsR|d d }t	|tjs(|j}q|jdkrR|d d	 jd |_|d d	= |D ]}	|	d dk	slt|rt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 }|r4|r$| |j|j n| |j|j || qV|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.
        typedefrW   r   bitsizeNrE   rB      r1   r   ?r7   zInvalid declarationrN   rB   rO   r7   rV   )r6   rO   rW   rB   r7   rX   initr6   rO   rW   ZfuncspecrB   rb   r^   r7   )r3   r-   rJ   r<   hasattrr7   r4   r   rD   rC   StructUnionrP   rB   rN   r.   ZTypedefDeclrT   r8   r6   r9   r*   )r   r[   declstypedef_namespaceZ
is_typedefZdeclarationsr7   tZdecls_0_tailrE   declarationZ
fixed_declr!   r!   r"   _build_declarationsw  sz    &



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.
        r]   rW   NrE   rb   Tr[   rh   ri   r   )rE   param_declsbodyr7   )r.   rl   r   r   ZFuncDefr7   )r   r[   rE   ro   rp   rk   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   re   rf   )r   tokenr!   r!   r"   _select_struct_union_class  s    z"CParser._select_struct_union_class)
)leftZLOR)ru   ZLAND)ru   OR)ru   ZXOR)ru   AND)ru   ZEQZNE)ru   GTZGELTZLE)ru   ZRSHIFTZLSHIFT)ru   PLUSMINUS)ru   ZTIMESZDIVIDEZMODc                 C   s2   |d dkrt g |d< nt |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|   r!   r!   r"   p_translation_unit_1
  s    zCParser.p_translation_unit_1c                 C   s.   |d dk	r|d  |d  |d |d< dS )zE translation_unit    : translation_unit external_declaration
        r_   Nr   r   )extendr|   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|   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|   r!   r!   r"   p_external_declaration_2"  s    z CParser.p_external_declaration_2c                 C   s   |d g|d< dS )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   d|d< dS )z( external_declaration    : SEMI
        Nr   r!   r|   r!   r!   r"   p_external_declaration_4-  s    z CParser.p_external_declaration_4c                 C   s   |  d| |d dS )z  pp_directive  : PPHASH
        zDirectives not supported yetr   N)r4   _token_coordr|   r!   r!   r"   p_pp_directive2  s    
zCParser.p_pp_directivec                 C   sF   t |dkr*t|d | |d|d< ntd| |d|d< dS )zg pppragma_directive      : PPPRAGMA
                                    | PPPRAGMA PPPRAGMASTR
           r_   r   r   r   N)r-   r   Pragmar   r|   r!   r!   r"   p_pppragma_directive8  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
        rH   r   rI   rU   r_   r   r[   rE   ro   rp   r   N)r   r   rP   r   rq   r   r}   r[   r!   r!   r"   p_function_definition_1D  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)rq   r   r!   r!   r"   p_function_definition_2U  s    zCParser.p_function_definition_2c                 C   s   |d |d< dS )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   sT   t |d tjrDt|dkrDtj|d |d g| |dd|d< n|d |d< dS )zx pragmacomp_or_statement     : pppragma_directive statement
                                        | statement
        r   r   r_   Zblock_itemsr7   r   N)rC   r   r   r-   Compoundr   r|   r!   r!   r"   p_pragmacomp_or_statement  s    
z!CParser.p_pragmacomp_or_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 )z decl_body : declaration_specifiers init_declarator_list_opt
                      | declaration_specifiers_no_type id_init_declarator_list_opt
        r   r_   NrB   r   rV   rW   rX   rc   rm   Trn   )
r   re   rf   Enumr-   rC   rg   r7   rl   r   )r   r}   r[   tyZs_u_or_erh   r!   r!   r"   p_decl_body  s4    
zCParser.p_decl_bodyc                 C   s   |d |d< dS )z& declaration : decl_body SEMI
        r   r   Nr!   r|   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
        r_   r   r   Nr-   r|   r!   r!   r"   p_declaration_list  s    zCParser.p_declaration_listc                 C   s   |  |d |d d|d< dS )z] declaration_specifiers_no_type  : type_qualifier declaration_specifiers_no_type_opt
        r_   r   rV   r   Nr\   r|   r!   r!   r"   "p_declaration_specifiers_no_type_1  s    z*CParser.p_declaration_specifiers_no_type_1c                 C   s   |  |d |d d|d< dS )zf declaration_specifiers_no_type  : storage_class_specifier declaration_specifiers_no_type_opt
        r_   r   rW   r   Nr   r|   r!   r!   r"   "p_declaration_specifiers_no_type_2  s    z*CParser.p_declaration_specifiers_no_type_2c                 C   s   |  |d |d d|d< dS )za declaration_specifiers_no_type  : function_specifier declaration_specifiers_no_type_opt
        r_   r   rX   r   Nr   r|   r!   r!   r"   "p_declaration_specifiers_no_type_3  s    z*CParser.p_declaration_specifiers_no_type_3c                 C   s"   | j |d |d ddd|d< dS )zI declaration_specifiers  : declaration_specifiers type_qualifier
        r   r_   rV   Tr*   r   Nr   r|   r!   r!   r"   p_declaration_specifiers_1	  s    z"CParser.p_declaration_specifiers_1c                 C   s"   | j |d |d ddd|d< dS )zR declaration_specifiers  : declaration_specifiers storage_class_specifier
        r   r_   rW   Tr   r   Nr   r|   r!   r!   r"   p_declaration_specifiers_2  s    z"CParser.p_declaration_specifiers_2c                 C   s"   | j |d |d ddd|d< dS )zM declaration_specifiers  : declaration_specifiers function_specifier
        r   r_   rX   Tr   r   Nr   r|   r!   r!   r"   p_declaration_specifiers_3  s    z"CParser.p_declaration_specifiers_3c                 C   s"   | j |d |d ddd|d< dS )zS declaration_specifiers  : declaration_specifiers type_specifier_no_typeid
        r   r_   rB   Tr   r   Nr   r|   r!   r!   r"   p_declaration_specifiers_4  s    z"CParser.p_declaration_specifiers_4c                 C   s   |  d|d d|d< dS )z2 declaration_specifiers  : type_specifier
        Nr   rB   r   r   r|   r!   r!   r"   p_declaration_specifiers_5  s    z"CParser.p_declaration_specifiers_5c                 C   s"   | j |d |d ddd|d< dS )zQ declaration_specifiers  : declaration_specifiers_no_type type_specifier
        r   r_   rB   Tr   r   Nr   r|   r!   r!   r"   p_declaration_specifiers_6"  s    z"CParser.p_declaration_specifiers_6c                 C   s   |d |d< dS )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   s   |d |d< dS )z& function_specifier  : INLINE
        r   r   Nr!   r|   r!   r!   r"   p_function_specifier1  s    zCParser.p_function_specifierc                 C   s$   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   rI   r   Nr   rP   r   r|   r!   r!   r"   p_type_specifier_no_typeid6  s    z"CParser.p_type_specifier_no_typeidc                 C   s   |d |d< dS )z type_specifier  : typedef_name
                            | enum_specifier
                            | struct_or_union_specifier
                            | type_specifier_no_typeid
        r   r   Nr!   r|   r!   r!   r"   p_type_specifierF  s    zCParser.p_type_specifierc                 C   s   |d |d< dS )zo type_qualifier  : CONST
                            | RESTRICT
                            | VOLATILE
        r   r   Nr!   r|   r!   r!   r"   p_type_qualifierN  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   Nr   r|   r!   r!   r"   p_init_declarator_listU  s    zCParser.p_init_declarator_listc                 C   s,   t |d t|dkr|d ndd|d< dS )zb init_declarator : declarator
                            | declarator EQUALS initializer
        r   r_   r   Nrm   r   r   r-   r|   r!   r!   r"   p_init_declarator^  s    zCParser.p_init_declaratorc                 C   s0   t |dkr|d |d g n|d g|d< dS )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_listd  s    z!CParser.p_id_init_declarator_listc                 C   s,   t |d t|dkr|d ndd|d< dS )zn id_init_declarator : id_declarator
                               | id_declarator EQUALS initializer
        r   r_   r   Nrm   r   r   r|   r!   r!   r"   p_id_init_declaratorj  s    zCParser.p_id_init_declaratorc                 C   s"   | j |d |d ddd|d< dS )zY specifier_qualifier_list    : specifier_qualifier_list type_specifier_no_typeid
        r   r_   rB   Tr   r   Nr   r|   r!   r!   r"   p_specifier_qualifier_list_1r  s    z$CParser.p_specifier_qualifier_list_1c                 C   s"   | j |d |d ddd|d< dS )zO specifier_qualifier_list    : specifier_qualifier_list type_qualifier
        r   r_   rV   Tr   r   Nr   r|   r!   r!   r"   p_specifier_qualifier_list_2w  s    z$CParser.p_specifier_qualifier_list_2c                 C   s   |  d|d d|d< dS )z4 specifier_qualifier_list  : type_specifier
        Nr   rB   r   r   r|   r!   r!   r"   p_specifier_qualifier_list_3|  s    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   rU   r_   rB   Tr   r   N)r   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r6   rh   r7   r   )rt   r   r   r}   klassr!   r!   r"   p_struct_or_union_specifier_1  s    
z%CParser.p_struct_or_union_specifier_1c                 C   sX   |  |d }t|dkr6|dg | |dd|d< n|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   rt   r-   r   r   r!   r!   r"   p_struct_or_union_specifier_2  s    

z%CParser.p_struct_or_union_specifier_2c                 C   s`   |  |d }t|dkr:||d g | |dd|d< n"||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   s   |d |d< dS )zF struct_or_union : STRUCT
                            | UNION
        r   r   Nr!   r|   r!   r!   r"   p_struct_or_union  s    zCParser.p_struct_or_unionc                 C   s:   t |dkr|d pg |d< n|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 kst |d dk	r8| j||d d}nht|d dkr|d d }t|tjrf|}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]   rW   r_   Nr[   rh   rB   r   rE   rm   )r.   rl   r-   rC   r   NoderP   r   )r   r}   r[   rh   nodeZ	decl_typer!   r!   r"   p_struct_declaration_1  s*    

	zCParser.p_struct_declaration_1c                 C   s   d|d< dS )z# struct_declaration : SEMI
        Nr   r!   r|   r!   r!   r"   p_struct_declaration_2  s    zCParser.p_struct_declaration_2c                 C   s   |d g|d< dS )z1 struct_declaration : pppragma_directive
        r   r   Nr!   r|   r!   r!   r"   p_struct_declaration_3  s    zCParser.p_struct_declaration_3c                 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   Nr   r|   r!   r!   r"   p_struct_declarator_list  s    z CParser.p_struct_declarator_listc                 C   s   |d dd|d< dS )z( struct_declarator : declarator
        r   NrE   r^   r   r!   r|   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ddd|d d|d< dS )z struct_declarator   : declarator COLON constant_expression
                                | COLON constant_expression
        r   r   r   r   Nr_   )r-   r   rD   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  s    zCParser.p_enum_specifier_2c                 C   s&   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   sh   t |dkr*t|d g|d j|d< n:t |dkrD|d |d< n |d j|d  |d |d< dS )z enumerator_list : enumerator
                            | enumerator_list COMMA
                            | enumerator_list COMMA enumerator
        r_   r   r   r   N)r-   r   ZEnumeratorListr7   Zenumeratorsr*   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   )r-   r   Z
Enumeratorr   r9   r6   r7   )r   r}   Z
enumeratorr!   r!   r"   p_enumerator0  s     
 
zCParser.p_enumeratorc                 C   s   |d |d< dS )zQ declarator  : id_declarator
                        | typeid_declarator
        r   r   Nr!   r|   r!   r!   r"   p_declarator@  s    zCParser.p_declarator)rL   ID)ZtypeidTYPEID)Ztypeid_noparenr   c                 C   s   |d |d< dS )z1 xxx_declarator  : direct_xxx_declarator
        r   r   Nr!   r|   r!   r!   r"   p_xxx_declarator_1F  s    zCParser.p_xxx_declarator_1c                 C   s   |  |d |d |d< dS )z9 xxx_declarator  : pointer direct_xxx_declarator
        r_   r   r   NrG   r|   r!   r!   r"   p_xxx_declarator_2L  s    zCParser.p_xxx_declarator_2c                 C   s&   t j|d dd| |dd|d< dS )z' direct_xxx_declarator   : yyy
        r   Nra   r   )r   rD   r   r|   r!   r!   r"   p_direct_xxx_declarator_1R  s    
z!CParser.p_direct_xxx_declarator_1c                 C   s   |d |d< dS )z@ direct_xxx_declarator   : LPAREN xxx_declarator RPAREN
        r_   r   Nr!   r|   r!   r!   r"   p_direct_xxx_declarator_2\  s    z!CParser.p_direct_xxx_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 )	z} direct_xxx_declarator   : direct_xxx_declarator LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET
        r   r   Nr   r   rB   Zdim	dim_qualsr7   rE   rF   r   )r-   r   	ArrayDeclr7   rG   )r   r}   rO   arrr!   r!   r"   p_direct_xxx_declarator_3b  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!   rC   list)rK   itemr!   r!   r"   rM   y  s   z5CParser.p_direct_xxx_declarator_4.<locals>.<listcomp>r   r   c                 S   s"   g | ]}|D ]}|d k	r|qqS r)   r!   )rK   ZsublistrV   r!   r!   r"   rM   {  s
      Nr   r   r   r   r   r   r   r7   rG   )r   r}   Zlisted_qualsr   r   r!   r!   r"   p_direct_xxx_declarator_4q  s    z!CParser.p_direct_xxx_declarator_4c              	   C   sZ   t jdt |d | |d|d dkr0|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   r   r   r   r   r   r   r   r7   rG   r   r}   r   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r`|jdk	r`|jjD ]$}t|t jrN q`| 	|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   argsrB   r7   LBRACEr   r   )r   rQ   r7   rA   rB   r   paramsrC   EllipsisParamr9   r6   rG   )r   r}   funcparamr!   r!   r"   p_direct_xxx_declarator_6  s    
 z!CParser.p_direct_xxx_declarator_6c                 C   sj   |  |d}tj|d pg d|d}t|dkr^|d }|jdk	rJ|j}q8||_|d |d< n||d< dS )zm pointer : TIMES type_qualifier_list_opt
                    | TIMES type_qualifier_list_opt pointer
        r   r_   N)rO   rB   r7   r   r   )r   r   ZPtrDeclr-   rB   )r   r}   r7   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
        r_   r   r   Nr   r|   r!   r!   r"   p_type_qualifier_list  s    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)r-   r   r*   r   r   r   r|   r!   r!   r"   p_parameter_type_list  s    zCParser.p_parameter_type_listc                 C   sN   t |dkr*t|d g|d j|d< n |d j|d  |d |d< dS )zz parameter_list  : parameter_declaration
                            | parameter_list COMMA parameter_declaration
        r_   r   r   r   Nr-   r   Z	ParamListr7   r   r*   r|   r!   r!   r"   p_parameter_list  s    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   rB   rH   rI   r_   r   r   r   N)r   rP   r   rl   r   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rt|d d jdkr| |d d jd r| j|t|d dd	gd
d }nDt jd|d |d pt 	ddd| |dd}|d }| 
||}||d< dS )zR parameter_declaration   : declaration_specifiers abstract_declarator_opt
        r   rB   rH   rI   r1   r   r_   Nrm   r   r   rV   r6   rO   rB   r7   )r   rP   r   r-   rJ   r<   rl   r   TypenamerD   rT   )r   r}   r[   rE   rR   r!   r!   r"   p_parameter_declaration_2  s.    
&
z!CParser.p_parameter_declaration_2c                 C   sN   t |dkr*t|d g|d j|d< n |d j|d  |d |d< dS )ze identifier_list : identifier
                            | identifier_list COMMA identifier
        r_   r   r   r   Nr   r|   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|   r!   r!   r"   p_initializer_1&  s    zCParser.p_initializer_1c                 C   s6   |d dkr&t g | |d|d< n|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rN|d dkr |d nt|d |d }t|g|d j|d< nD|d dkrb|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   )r-   r   ZNamedInitializerr   r7   exprsr*   )r   r}   rb   r!   r!   r"   p_initializer_list4  s    ((zCParser.p_initializer_listc                 C   s   |d |d< dS )z. designation : designator_list EQUALS
        r   r   Nr!   r|   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
        r_   r   r   Nr   r|   r!   r!   r"   p_designator_listH  s    zCParser.p_designator_listc                 C   s   |d |d< dS )zi designator  : LBRACKET constant_expression RBRACKET
                        | PERIOD identifier
        r_   r   Nr!   r|   r!   r!   r"   p_designatorN  s    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   rV   r_   Nr   rB   r   )r   r   rD   r   rT   )r   r}   rR   r!   r!   r"   p_type_nameT  s    

zCParser.p_type_namec                 C   s(   t ddd}| j||d d|d< dS )z+ abstract_declarator     : pointer
        Nr   r   r   )r   rD   rG   )r   r}   Z	dummytyper!   r!   r"   p_abstract_declarator_1_  s
    zCParser.p_abstract_declarator_1c                 C   s   |  |d |d |d< dS )zF abstract_declarator     : pointer direct_abstract_declarator
        r_   r   r   Nr   r|   r!   r!   r"   p_abstract_declarator_2g  s    zCParser.p_abstract_declarator_2c                 C   s   |d |d< dS )z> abstract_declarator     : direct_abstract_declarator
        r   r   Nr!   r|   r!   r!   r"   p_abstract_declarator_3l  s    zCParser.p_abstract_declarator_3c                 C   s   |d |d< dS )zA direct_abstract_declarator  : LPAREN abstract_declarator RPAREN r_   r   Nr!   r|   r!   r!   r"   p_direct_abstract_declarator_1v  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   r   r   r!   r!   r"   p_direct_abstract_declarator_2z  s    z&CParser.p_direct_abstract_declarator_2c                 C   s0   t jt ddd|d g | |dd|d< dS )zS direct_abstract_declarator  : LBRACKET assignment_expression_opt RBRACKET
        Nr_   r   r   r   )r   r   rD   r   r|   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   r   r   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   r   r   )r   r   rD   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   r   r   r   )r   rQ   r7   rG   )r   r}   r   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   r   r   )r   rQ   rD   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   Nr   r|   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
        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   ZLabelr   r|   r!   r!   r"   p_labeled_statement_1  s    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   ZCaser   r|   r!   r!   r"   p_labeled_statement_2  s    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   Z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   ZIfr   r|   r!   r!   r"   p_selection_statement_1  s    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   ZSwitchr   r|   r!   r!   r"   p_selection_statement_3  s    zCParser.p_selection_statement_3c                 C   s&   t |d |d | |d|d< dS )zN iteration_statement : WHILE LPAREN expression RPAREN pragmacomp_or_statement r   r   r   r   N)r   ZWhiler   r|   r!   r!   r"   p_iteration_statement_1  s    zCParser.p_iteration_statement_1c                 C   s&   t |d |d | |d|d< dS )zV iteration_statement : DO pragmacomp_or_statement WHILE LPAREN expression RPAREN SEMI r   r_   r   r   N)r   ZDoWhiler   r|   r!   r!   r"   p_iteration_statement_2  s    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    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  Z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   ZGotor   r|   r!   r!   r"   p_jump_statement_1  s    zCParser.p_jump_statement_1c                 C   s   t | |d|d< dS )z jump_statement  : BREAK SEMI r   r   N)r   ZBreakr   r|   r!   r!   r"   p_jump_statement_2  s    zCParser.p_jump_statement_2c                 C   s   t | |d|d< dS )z! jump_statement  : CONTINUE SEMI r   r   N)r   Continuer   r|   r!   r!   r"   p_jump_statement_3  s    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   ZReturnr-   r   r|   r!   r!   r"   p_jump_statement_4  s    zCParser.p_jump_statement_4c                 C   s4   |d dkr$t | |d|d< n|d |d< dS )z, expression_statement : expression_opt SEMI r   Nr_   r   )r   ZEmptyStatementr   r|   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|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)r-   rC   r   ExprListr7   r   r*   r|   r!   r!   r"   p_expression  s    zCParser.p_expressionc                 C   s$   t j|d g| |dd|d< dS )z typedef_name : TYPEID r   rI   r   Nr   r|   r!   r!   r"   p_typedef_name  s    zCParser.p_typedef_namec                 C   sD   t |dkr|d |d< n&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)r-   r   Z
Assignmentr7   r|   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|   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|   r!   r!   r"   p_constant_expression=  s    zCParser.p_constant_expressionc                 C   sD   t |dkr|d |d< n&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)r-   r   Z	TernaryOpr7   r|   r!   r!   r"   p_conditional_expressionA  s    z CParser.p_conditional_expressionc                 C   sD   t |dkr|d |d< n&t|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
        r_   r   r   r   N)r-   r   ZBinaryOpr7   r|   r!   r!   r"   p_binary_expressionJ  s    zCParser.p_binary_expressionc                 C   s   |d |d< dS )z$ cast_expression : unary_expression r   r   Nr!   r|   r!   r!   r"   p_cast_expression_1d  s    zCParser.p_cast_expression_1c                 C   s&   t |d |d | |d|d< dS )z; cast_expression : LPAREN type_name RPAREN cast_expression r_   r   r   r   N)r   ZCastr   r|   r!   r!   r"   p_cast_expression_2h  s    zCParser.p_cast_expression_2c                 C   s   |d |d< dS )z* unary_expression    : postfix_expression r   r   Nr!   r|   r!   r!   r"   p_unary_expression_1l  s    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   UnaryOpr7   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/  r-   r   r|   r!   r!   r"   p_unary_expression_3w  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|   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|   r!   r!   r"   p_postfix_expression_1  s    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   ArrayRefr7   r|   r!   r!   r"   p_postfix_expression_2  s    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   FuncCallr-   r7   r|   r!   r!   r"   p_postfix_expression_3  s    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   	StructRefr7   r   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  s    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   ZCompoundLiteralr|   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|   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|   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|   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 r_   r   Nr!   r|   r!   r!   r"   p_primary_expression_4  s    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   r6  r   r#  )r   r}   r7   r!   r!   r"   p_primary_expression_5  s
    zCParser.p_primary_expression_5c                 C   s   t |dkr|d |d< nt |dkrbt|d | |d}t|d |d ||d j|d< n>t |dkrt|d |d |d j|d< ntdt | dS )	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)r-   r   r   r   r8  r7   r4  NotImplementedErrorr9  r!   r!   r"   p_offsetof_member_designator  s    $"z$CParser.p_offsetof_member_designatorc                 C   sN   t |dkr*t|d g|d j|d< n |d j|d  |d |d< dS )z argument_expression_list    : assignment_expression
                                        | argument_expression_list COMMA assignment_expression
        r_   r   r   r   N)r-   r   r#  r7   r   r*   r|   r!   r!   r"   p_argument_expression_list  s    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  s    zCParser.p_identifierc                 C   s"   t d|d | |d|d< dS )z constant    : INT_CONST_DEC
                        | INT_CONST_OCT
                        | INT_CONST_HEX
                        | INT_CONST_BIN
        rH   r   r   Nr   Constantr   r|   r!   r!   r"   p_constant_1  s
      
zCParser.p_constant_1c                 C   sh   d|d   krd}n0|d d dkr,d}n|d d dkrBd}nd}t||d | |d|d	< d
S )zM constant    : FLOAT_CONST
                        | HEX_FLOAT_CONST
        xr   floatr1   )fF)lLzlong doubledoubler   N)lowerr   rH  r   )r   r}   rj   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   NrG  r|   r!   r!   r"   p_constant_3  s
      
zCParser.p_constant_3c                 C   sd   t |dkr,td|d | |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
        r_   stringr   r   Nr1   )r-   r   rH  r   valuer|   r!   r!   r"   p_unified_string_literal
  s      

(z CParser.p_unified_string_literalc                 C   sh   t |dkr,td|d | |d|d< n8|d j dd |d dd  |d _|d |d< dS )z unified_wstring_literal : WSTRING_LITERAL
                                    | unified_wstring_literal WSTRING_LITERAL
        r_   rU  r   r   Nr1   )r-   r   rH  r   rV  rstripr|   r!   r!   r"   p_unified_wstring_literal  s      

,z!CParser.p_unified_wstring_literalc                 C   s"   |d |d< | d|d dS )z  brace_open  :   LBRACE
        r   r   NZ
set_linenolinenor|   r!   r!   r"   p_brace_open   s    zCParser.p_brace_openc                 C   s"   |d |d< | d|d dS )z  brace_close :   RBRACE
        r   r   NrZ  r|   r!   r!   r"   p_brace_close&  s    zCParser.p_brace_closec                 C   s   d|d< dS )zempty : Nr   r!   r|   r!   r!   r"   p_empty,  s    zCParser.p_emptyc                 C   s@   |r,|  d|j | j|j| j|d n|  d| jj d S )Nz
before: %s)r[  r@   zAt end of input)r4   rV  r=   r[  r   Zfind_tok_columnr%   r|   r!   r!   r"   p_error0  s    
zCParser.p_errorN)r   r   )F)F)__name__
__module____qualname__r   r#   r&   r,   r0   r8   r9   r<   r   r   r   r   rA   rG   rT   r\   rl   rq   rt   
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   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-  r0  r1  r2  r3  r5  r7  r;  r<  r=  r>  r?  r@  rA  rB  rD  rE  rF  rI  rR  rT  rW  rY  r\  r]  r^  r_  r!   r!   r!   r"   r      s^  
o	

	)7-Y	5<					&		





	








	
	
		

		
	
	r   )reZplyr   r   r   Zc_lexerr   Z	plyparserr   r   r   r	   r
   Zast_transformsr   r   r!   r!   r!   r"   <module>	   s   