o
    Uh*"                    @   sd   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
 d dlmZmZ e
G dd deZdS )	   )yacc)c_ast)CLexer)	PLYParser
ParseErrorparameterizedtemplate)fix_switch_casesfix_atomic_specifiersc                   @   s  e Zd ZdedddddfddZd_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"d#Zd`d$d%Zd&d' Zd(d) Zd*Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Zd=d> Z d?d@ Z!dAdB Z"dCdD Z#dEdF Z$dGdH Z%dIdJ Z&dKdL Z'dMdN Z(dOdP Z)dQdR Z*dSdT Z+dUdV Z,dWdX Z-dYdZ Z.d[d\ Z/d]d^ Z0d_d` Z1dadb Z2dcdd Z3dedf Z4dgdh Z5didj Z6dkdl Z7dmdn Z8dodp Z9dqdr Z:dsdt Z;dudv Z<dwdx Z=dydz Z>d{d| Z?d}d~ Z@dd ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWeXddddd ZYeXddddd ZZeXddddd Z[eXdddd Z\eXddddd Z]eXddddd Z^eXddddd Z_eXddd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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d0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Zd>d? Zd@dA ZdBdC ZdDdE ZdFdG ZdHdI ZdJdK ZdLdM ZdNdO ZdPdQ ZdRdS ZdTdU ZdVdW ZdXdY ZdZd[ Zd\d] Zd^S (a  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<   f/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/pycparser/c_parser.py__init__   s2   :


zCParser.__init__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)

            debug:
                Debug flag to YACC
        N)inputr5   r%   )r+   filenamereset_linenor0   r1   r2   r/   parse)r3   textr@   r%   r<   r<   r=   rB      s   

zCParser.parsec                 C   s   | j t  d S N)r1   appendr0   r3   r<   r<   r=   _push_scope   s   zCParser._push_scopec                 C   s    t | jdks	J | j  d S )Nr   )lenr1   poprF   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r1   get_parse_errorr3   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
        rK   Fz;Non-typedef %r previously declared as typedef in this scopeNrL   rO   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)reversedr1   rM   )r3   rP   scopein_scoper<   r<   r=   _is_type_in_scope   s   
zCParser._is_type_in_scopec                 C   s   |  || || d S rD   )rN   _coord)r3   msglinecolumnr<   r<   r=   r'      s   zCParser._lex_error_funcc                 C      |    d S rD   )rG   rF   r<   r<   r=   r(         zCParser._lex_on_lbrace_funcc                 C   r\   rD   )rJ   rF   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.
        )rW   )r3   rP   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_tokenrF   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)r3   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d |_|D ]}t |tjs<t|dkr5| 	d|j
 q||_|  S q|sYt |jtjsM| 	d|j
 tjdg|j
d|_|S tjdd |D |d	 j
d|_|S )
z- Fixes a declaration. Modifies decl.
        Nr   z Invalid multiple types specifiedzMissing type in declarationintrQ   c                 S   s   g | ]
}|j D ]}|qqS r<   )names).0idrP   r<   r<   r=   
<listcomp>S  s    z/CParser._fix_decl_name_type.<locals>.<listcomp>    )rb   r   rc   ra   declnamerP   qualsIdentifierTyperH   rN   rQ   FuncDecl)r3   rd   typenamera   tnr<   r<   r=   _fix_decl_name_type+  s<   
zCParser._fix_decl_name_typec                 C   s@   |p
t g 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
            * alignment: a list of alignment 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storagera   function	alignmentrp   )r0   rE   insert)r3   declspecnewspeckindrE   specr<   r<   r=   _add_declaration_specifierW  s   z"CParser._add_declaration_specifierc                 C   s\  d|d v }g }|d  ddurn|d d du rtt|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 d	 jd|d d< |d d	= n:t	|d d tj
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 ]{}	|	d dusJ |rtjd|d |d |	d |	d jd}
n!tjd|d |d |d |d |	d |	 d|	 d|	d jd	}
t	|
jtj
tjtjtjfr|
}n| |
|d }|r"|r| |j|j n| |j|j t|}|| 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.
        typedefry   rp   bitsizeNrd   ra      rK   r   ?rQ   zInvalid declarationr{   rq   ra   rr   alignrQ   rx   )rP   rr   ry   ra   rQ   rz   init	rP   rr   r   ry   funcspecra   r   r   rQ   )rM   rH   rl   rW   hasattrrQ   rN   r   rc   rb   EnumStructUnionrs   ra   rq   TypedefDeclrw   rR   rP   rS   r
   rE   )r3   r   declstypedef_namespace
is_typedefdeclarationsrQ   tdecls_0_tailrd   declaration
fixed_declr<   r<   r=   _build_declarationsp  s   &


zCParser._build_declarationsc                 C   sL   d|d v r|  d|j | j|t|ddgddd }tj||||jd	S )
z' Builds a function definition.
        r   ry   zInvalid typedefNrd   r   Tr   r   r   rp   )rd   param_declsbodyrQ   )rN   rQ   r   r0   r   FuncDef)r3   r   rd   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   )r3   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   Nrp   )r   FileASTr3   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   rp   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   rp   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   rp   Nr<   r   r<   r<   r=   p_external_declaration_1     z CParser.p_external_declaration_1c                 C   r   )z/ external_declaration    : declaration
        r   rp   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   rp   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
        rp   Nr<   r   r<   r<   r=   p_external_declaration_4%     z CParser.p_external_declaration_4c                 C   r   )z1 external_declaration    : static_assert
        r   rp   Nr<   r   r<   r<   r=   p_external_declaration_5*  r   z CParser.p_external_declaration_5c                 C   sX   t |dkrt|d d| |dg|d< dS t|d |d | |dg|d< dS )z static_assert           : _STATIC_ASSERT LPAREN constant_expression COMMA unified_string_literal RPAREN
                                    | _STATIC_ASSERT LPAREN constant_expression RPAREN
              Nr   rp   )rH   r   StaticAssert_token_coordr   r<   r<   r=   p_static_assert_declaration/  s   $(z#CParser.p_static_assert_declarationc                 C   s   |  d| |d dS )z  pp_directive  : PPHASH
        zDirectives not supported yetr   N)rN   r   r   r<   r<   r=   p_pp_directive8  s   
zCParser.p_pp_directivec                 C   st   t |dkrt|d | |d|d< dS t |dkr,t|d | |d|d< dS td| |d|d< dS )z pppragma_directive      : PPPRAGMA
                                    | PPPRAGMA PPPRAGMASTR
                                    | _PRAGMA LPAREN unified_string_literal RPAREN
        r   r   r   rp   r   r   N)rH   r   Pragmar   r   r<   r<   r=   p_pppragma_directiveC  s
     zCParser.p_pppragma_directivec                 C   0   t |dkr|d gn|d |d g |d< dS )z pppragma_directive_list : pppragma_directive
                                    | pppragma_directive_list pppragma_directive
        r   r   rp   NrH   r   r<   r<   r=   p_pppragma_directive_listO     0z!CParser.p_pppragma_directive_listc              
   C   sN   t g 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
        rj   r   rk   rx   r{   ry   ra   rz   r   r   r   rd   r   r   rp   N)r0   r   rs   r   r   r3   r   r   r<   r<   r=   p_function_definition_1W  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   rp   N)r   r   r<   r<   r=   p_function_definition_2i  s   zCParser.p_function_definition_2c                 C   r   )a_   statement   : labeled_statement
                        | expression_statement
                        | compound_statement
                        | selection_statement
                        | iteration_statement
                        | jump_statement
                        | pppragma_directive
                        | static_assert
        r   rp   Nr<   r   r<   r<   r=   p_statementx  s   
zCParser.p_statementc                 C   sH   t |dkrtj|d |d g | |dd|d< dS |d |d< dS )z} pragmacomp_or_statement     : pppragma_directive_list statement
                                        | statement
        r   r   r   block_itemsrQ   rp   N)rH   r   Compoundr   r   r<   r<   r=   p_pragmacomp_or_statement  s   
z!CParser.p_pragmacomp_or_statementc                 C   s   |d }|d du rN|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|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   Nra   rp   rx   r{   ry   rz   r   r   Tr   )
r   r   r   r   rH   rb   r   rQ   r   r0   )r3   r   r   tys_u_or_er   r<   r<   r=   p_decl_body  s6   
zCParser.p_decl_bodyc                 C   r   )z& declaration : decl_body SEMI
        r   rp   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   rp   Nr   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   rx   rp   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   ry   rp   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   rz   rp   Nr   r   r<   r<   r=   "p_declaration_specifiers_no_type_3  r   z*CParser.p_declaration_specifiers_no_type_3c                 C   r   )z_ declaration_specifiers_no_type  : atomic_specifier declaration_specifiers_no_type_opt
        r   r   ra   rp   Nr   r   r<   r<   r=   "p_declaration_specifiers_no_type_4%  r   z*CParser.p_declaration_specifiers_no_type_4c                 C   r   )zb declaration_specifiers_no_type  : alignment_specifier declaration_specifiers_no_type_opt
        r   r   r{   rp   Nr   r   r<   r<   r=   "p_declaration_specifiers_no_type_5*  r   z*CParser.p_declaration_specifiers_no_type_5c                 C   "   | j |d |d ddd|d< dS )zI declaration_specifiers  : declaration_specifiers type_qualifier
        r   r   rx   TrE   rp   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   ry   Tr   rp   Nr   r   r<   r<   r=   p_declaration_specifiers_24  r   z"CParser.p_declaration_specifiers_2c                 C   r   )zM declaration_specifiers  : declaration_specifiers function_specifier
        r   r   rz   Tr   rp   Nr   r   r<   r<   r=   p_declaration_specifiers_39  r   z"CParser.p_declaration_specifiers_3c                 C   r   )zS declaration_specifiers  : declaration_specifiers type_specifier_no_typeid
        r   r   ra   Tr   rp   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   ra   rp   r   r   r<   r<   r=   p_declaration_specifiers_5C     z"CParser.p_declaration_specifiers_5c                 C   r   )zQ declaration_specifiers  : declaration_specifiers_no_type type_specifier
        r   r   ra   Tr   rp   Nr   r   r<   r<   r=   p_declaration_specifiers_6H  r   z"CParser.p_declaration_specifiers_6c                 C   r   )zN declaration_specifiers  : declaration_specifiers alignment_specifier
        r   r   r{   Tr   rp   Nr   r   r<   r<   r=   p_declaration_specifiers_7M  r   z"CParser.p_declaration_specifiers_7c                 C   r   )a   storage_class_specifier : AUTO
                                    | REGISTER
                                    | STATIC
                                    | EXTERN
                                    | TYPEDEF
                                    | _THREAD_LOCAL
        r   rp   Nr<   r   r<   r<   r=   p_storage_class_specifierR     z!CParser.p_storage_class_specifierc                 C   r   )zR function_specifier  : INLINE
                                | _NORETURN
        r   rp   Nr<   r   r<   r<   r=   p_function_specifier\  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   rk   rp   Nr   rs   r   r   r<   r<   r=   p_type_specifier_no_typeidb  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
                            | atomic_specifier
        r   rp   Nr<   r   r<   r<   r=   p_type_specifierr  s   zCParser.p_type_specifierc                 C   s    |d }|j d ||d< dS )z= atomic_specifier  : _ATOMIC LPAREN type_name RPAREN
        r   _Atomicrp   N)rr   rE   )r3   r   typr<   r<   r=   p_atomic_specifier|  s   zCParser.p_atomic_specifierc                 C   r   )z type_qualifier  : CONST
                            | RESTRICT
                            | VOLATILE
                            | _ATOMIC
        r   rp   Nr<   r   r<   r<   r=   p_type_qualifier  s   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   rp   Nr   r   r<   r<   r=   p_init_declarator_list  r   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   rp   r0   rH   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   rp   Nr   r   r<   r<   r=   p_id_init_declarator_list  r   z!CParser.p_id_init_declarator_listc                 C   r  )zn id_init_declarator : id_declarator
                               | id_declarator EQUALS initializer
        r   r   r   Nr   rp   r  r   r<   r<   r=   p_id_init_declarator  r   zCParser.p_id_init_declaratorc                 C   r   )zY specifier_qualifier_list    : specifier_qualifier_list type_specifier_no_typeid
        r   r   ra   Tr   rp   Nr   r   r<   r<   r=   p_specifier_qualifier_list_1  r   z$CParser.p_specifier_qualifier_list_1c                 C   r   )zO specifier_qualifier_list    : specifier_qualifier_list type_qualifier
        r   r   rx   Tr   rp   Nr   r   r<   r<   r=   p_specifier_qualifier_list_2  r   z$CParser.p_specifier_qualifier_list_2c                 C   r   )z4 specifier_qualifier_list  : type_specifier
        Nr   ra   rp   r   r   r<   r<   r=   p_specifier_qualifier_list_3  r   z$CParser.p_specifier_qualifier_list_3c                 C   s$   t |d g g |d gg d|d< dS )zH specifier_qualifier_list  : type_qualifier_list type_specifier
        r   r   r   rp   Nr0   r   r<   r<   r=   p_specifier_qualifier_list_4  s   $z$CParser.p_specifier_qualifier_list_4c                 C   s    t g |d gg g g d|d< dS )z9 specifier_qualifier_list  : alignment_specifier
        r   r   rp   Nr  r   r<   r<   r=   p_specifier_qualifier_list_5  s    z$CParser.p_specifier_qualifier_list_5c                 C   r   )zR specifier_qualifier_list  : specifier_qualifier_list alignment_specifier
        r   r   r{   rp   Nr   r   r<   r<   r=   p_specifier_qualifier_list_6  r   z$CParser.p_specifier_qualifier_list_6c                 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rP   r   rQ   rp   )r   r   r3   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  rp   r   r   rH   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  rp   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   rp   Nr<   r   r<   r<   r=   p_struct_or_union  r   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   rp   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   ry   r   Nr   r   ra   rp   rd   r   )r   rH   rb   r   Noders   r0   )r3   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
        Nrp   r<   r   r<   r<   r=   p_struct_declaration_20  r   zCParser.p_struct_declaration_2c                 C   r   )z1 struct_declaration : pppragma_directive
        r   rp   Nr<   r   r<   r<   r=   p_struct_declaration_35  r   zCParser.p_struct_declaration_3c                 C   r  )z struct_declarator_list  : struct_declarator
                                    | struct_declarator_list COMMA struct_declarator
        r   r   r   rp   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rd   r   rp   r<   r   r<   r<   r=   p_struct_declarator_1C  s   zCParser.p_struct_declarator_1c                 C   sH   t |dkr|d |d d|d< dS tdddd|d d|d< dS )z struct_declarator   : declarator COLON constant_expression
                                | COLON constant_expression
        r   r   r%  rp   Nr   )rH   r   rc   r   r<   r<   r=   p_struct_declarator_2H  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   rp   r   r   r   r   r<   r<   r=   p_enum_specifier_1Q  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   rp   r(  r   r<   r<   r=   p_enum_specifier_2W  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   rp   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   rp   r   N)rH   r   EnumeratorListrQ   enumeratorsrE   r   r<   r<   r=   p_enumerator_listb  s    zCParser.p_enumerator_listc                 C       t |d | |d|d< dS )z alignment_specifier  : _ALIGNAS LPAREN type_name RPAREN
                                 | _ALIGNAS LPAREN constant_expression RPAREN
        r   r   rp   N)r   Alignasr   r   r<   r<   r=   p_alignment_specifiero  s    zCParser.p_alignment_specifierc                 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   rp   )rH   r   
Enumeratorr   rS   rP   rQ   )r3   r   
enumeratorr<   r<   r=   p_enumeratoru  s   

zCParser.p_enumeratorc                 C   r   )zQ declarator  : id_declarator
                        | typeid_declarator
        r   rp   Nr<   r   r<   r<   r=   p_declarator  r   zCParser.p_declarator)rn   ID)typeidTYPEID)typeid_noparenr9  c                 C   r   )z1 xxx_declarator  : direct_xxx_declarator
        r   rp   Nr<   r   r<   r<   r=   p_xxx_declarator_1  r   zCParser.p_xxx_declarator_1c                 C      |  |d |d |d< dS )z9 xxx_declarator  : pointer direct_xxx_declarator
        r   r   rp   Nri   r   r<   r<   r=   p_xxx_declarator_2     zCParser.p_xxx_declarator_2c              	   C   s(   t j|d ddd| |dd|d< dS )z' direct_xxx_declarator   : yyy
        r   Nr   rp   )r   rc   r   r   r<   r<   r=   p_direct_xxx_declarator_1  s   
z!CParser.p_direct_xxx_declarator_1c                 C   r   )z@ direct_xxx_declarator   : LPAREN xxx_declarator RPAREN
        r   rp   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   ra   dim	dim_qualsrQ   rd   re   rp   )rH   r   	ArrayDeclrQ   ri   )r3   r   rr   arrr<   r<   r=   p_direct_xxx_declarator_3  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<   rb   list)rm   itemr<   r<   r=   ro     s    z5CParser.p_direct_xxx_declarator_4.<locals>.<listcomp>r   r   c                 S   s"   g | ]}|D ]}|d ur|qqS rD   r<   )rm   sublistrx   r<   r<   r=   ro     s    Nr   r   rB  rE  rp   r   rF  rQ   ri   )r3   r   listed_qualsrD  rG  r<   r<   r=   p_direct_xxx_declarator_4  s   z!CParser.p_direct_xxx_declarator_4c              	   C   sZ   t jdt |d | |d|d du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   rB  rE  rp   r   rF  r7  r   rQ   ri   r3   r   rG  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   argsra   rQ   LBRACErE  rp   )r   rt   rQ   r`   ra   rT  paramsrb   EllipsisParamrS   rP   ri   )r3   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)rr   ra   rQ   r   rp   )r   r   PtrDeclrH   ra   )r3   r   rQ   nested_type	tail_typer<   r<   r=   	p_pointer  s   

zCParser.p_pointerc                 C   r   )zs type_qualifier_list : type_qualifier
                                | type_qualifier_list type_qualifier
        r   r   rp   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   rp   N)rH   rV  rE   r   rW  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   rp   r   NrH   r   	ParamListrQ   rV  rE   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   ra   rj   rk   r   r  r  rp   N)r   rs   r   r   r0   r   r<   r<   r=   p_parameter_declaration_17  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|d pYt 	dddd| |dd}|d }| 
||}||d< dS )zR parameter_declaration   : declaration_specifiers abstract_declarator_opt
        r   ra   rj   rk   rK   rp   r   Nr   r  r   rx   rP   rr   r   ra   rQ   )r   rs   r   rH   rl   rW   r   r0   Typenamerc   rw   )r3   r   r   rd   ru   r<   r<   r=   p_parameter_declaration_2C  s0   
&
z!CParser.p_parameter_declaration_2c                 C   ra  )ze identifier_list : identifier
                            | identifier_list COMMA identifier
        r   r   rp   r   Nrb  r   r<   r<   r=   p_identifier_listc  re  zCParser.p_identifier_listc                 C   r   )z- initializer : assignment_expression
        r   rp   Nr<   r   r<   r<   r=   p_initializer_1m  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   rp   )r   InitListr   r   r<   r<   r=   p_initializer_2r  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   rp   r   )rH   r   NamedInitializerrl  rQ   exprsrE   )r3   r   r   r<   r<   r=   p_initializer_list{  s   ((zCParser.p_initializer_listc                 C   r   )z. designation : designator_list EQUALS
        r   rp   Nr<   r   r<   r<   r=   p_designation  r   zCParser.p_designationc                 C   r   )z_ designator_list : designator
                            | designator_list designator
        r   r   rp   Nr   r   r<   r<   r=   p_designator_list  r   zCParser.p_designator_listc                 C   r   )zi designator  : LBRACKET constant_expression RBRACKET
                        | PERIOD identifier
        r   rp   Nr<   r   r<   r<   r=   p_designator  r   zCParser.p_designatorc              
   C   s\   t jd|d d dd d|d pt dddd| |dd}| ||d d |d< dS )	zH type_name   : specifier_qualifier_list abstract_declarator_opt
        r   r   rx   Nr   rg  ra   rp   )r   rh  rc   r   rw   )r3   r   ru   r<   r<   r=   p_type_name  s   
zCParser.p_type_namec                 C   s*   t dddd}| j||d d|d< dS )z+ abstract_declarator     : pointer
        Nr   rE  rp   )r   rc   ri   )r3   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   rp   Nr=  r   r<   r<   r=   p_abstract_declarator_2  s   zCParser.p_abstract_declarator_2c                 C   r   )z> abstract_declarator     : direct_abstract_declarator
        r   rp   Nr<   r   r<   r<   r=   p_abstract_declarator_3  r   zCParser.p_abstract_declarator_3c                 C   r   )zA direct_abstract_declarator  : LPAREN abstract_declarator RPAREN r   rp   Nr<   r   r<   r<   r=   p_direct_abstract_declarator_1     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   rB  rE  rp   rM  rQ  r<   r<   r=   p_direct_abstract_declarator_2  s   z&CParser.p_direct_abstract_declarator_2c                 C   sb   t |dkr
|d ng pg }tjtd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   rB  rp   )rH   r   rF  rc   r   )r3   r   rr   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   rB  rE  rp   rP  rQ  r<   r<   r=   p_direct_abstract_declarator_4  s   z&CParser.p_direct_abstract_declarator_4c              	   C   sB   t jt ddddt |d | |dg | |dd|d< dS )z? direct_abstract_declarator  : LBRACKET TIMES RBRACKET
        Nr   r   rB  rp   )r   rF  rc   r7  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   rS  rE  rp   )r   rt   rQ   ri   )r3   r   rX  r<   r<   r=   p_direct_abstract_declarator_6  s   z&CParser.p_direct_abstract_declarator_6c                 C   s0   t j|d t dddd| |dd|d< dS )zM direct_abstract_declarator  : LPAREN parameter_type_list_opt RPAREN
        r   Nr   rS  rp   )r   rt   rc   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   rp   NrI  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   rp   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   rp   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   rp   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   rp   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   rp   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   rp   r   Ifr   r   r<   r<   r=   p_selection_statement_1!  r  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   rp   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   rp   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   rp   N)r   Whiler   r   r<   r<   r=   p_iteration_statement_1.  r  zCParser.p_iteration_statement_1c                 C   r+  )zV iteration_statement : DO pragmacomp_or_statement WHILE LPAREN expression RPAREN SEMI r   r   r   rp   N)r   DoWhiler   r   r<   r<   r=   p_iteration_statement_22  r  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   rp   N)r   Forr   r   r<   r<   r=   p_iteration_statement_36  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         rp   N)r   r  DeclListr   r   r<   r<   r=   p_iteration_statement_4:  s   zCParser.p_iteration_statement_4c                 C   r0  )z  jump_statement  : GOTO ID SEMI r   r   rp   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   rp   N)r   Breakr   r   r<   r<   r=   p_jump_statement_2C     zCParser.p_jump_statement_2c                 C   r  )z! jump_statement  : CONTINUE SEMI r   rp   N)r   Continuer   r   r<   r<   r=   p_jump_statement_3G  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   rp   )r   ReturnrH   r   r   r<   r<   r=   p_jump_statement_4K  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   rp   )r   EmptyStatementr   r   r<   r<   r=   p_expression_statementQ  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   rp   r   N)rH   rb   r   ExprListrQ   ro  rE   r   r<   r<   r=   p_expressionX  s   zCParser.p_expressionc                 C   r   )z: assignment_expression : LPAREN compound_statement RPAREN r   rp   Nr<   r   r<   r<   r=   #p_parenthesized_compound_expressione  rz  z+CParser.p_parenthesized_compound_expressionc                 C   r   )z typedef_name : TYPEID r   rk   rp   Nr   r   r<   r<   r=   p_typedef_namei     $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   rp   r   N)rH   r   
AssignmentrQ   r   r<   r<   r=   p_assignment_expressionm     *zCParser.p_assignment_expressionc                 C   r   )a   assignment_operator : EQUALS
                                | XOREQUAL
                                | TIMESEQUAL
                                | DIVEQUAL
                                | MODEQUAL
                                | PLUSEQUAL
                                | MINUSEQUAL
                                | LSHIFTEQUAL
                                | RSHIFTEQUAL
                                | ANDEQUAL
                                | OREQUAL
        r   rp   Nr<   r   r<   r<   r=   p_assignment_operator{  s   zCParser.p_assignment_operatorc                 C   r   )z. constant_expression : conditional_expression r   rp   Nr<   r   r<   r<   r=   p_constant_expression  rz  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   rp   r   r   N)rH   r   	TernaryOprQ   r   r<   r<   r=   p_conditional_expression  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   rp   r   N)rH   r   BinaryOprQ   r   r<   r<   r=   p_binary_expression  s   *zCParser.p_binary_expressionc                 C   r   )z$ cast_expression : unary_expression r   rp   Nr<   r   r<   r<   r=   p_cast_expression_1  rz  zCParser.p_cast_expression_1c                 C   r+  )z; cast_expression : LPAREN type_name RPAREN cast_expression r   r   r   rp   N)r   Castr   r   r<   r<   r=   p_cast_expression_2  r  zCParser.p_cast_expression_2c                 C   r   )z* unary_expression    : postfix_expression r   rp   Nr<   r   r<   r<   r=   p_unary_expression_1  rz  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   rp   Nr   UnaryOprQ   r   r<   r<   r=   p_unary_expression_2  s   $zCParser.p_unary_expression_2c                 C   s:   t |d t|dkr|d n|d | |d|d< dS )z unary_expression    : SIZEOF unary_expression
                                | SIZEOF LPAREN type_name RPAREN
                                | _ALIGNOF LPAREN type_name RPAREN
        r   r   r   rp   N)r   r  rH   r   r   r<   r<   r=   p_unary_expression_3  s
   
zCParser.p_unary_expression_3c                 C   r   )z unary_operator  : AND
                            | TIMES
                            | PLUS
                            | MINUS
                            | NOT
                            | LNOT
        r   rp   Nr<   r   r<   r<   r=   p_unary_operator  r   zCParser.p_unary_operatorc                 C   r   )z* postfix_expression  : primary_expression r   rp   Nr<   r   r<   r<   r=   p_postfix_expression_1  rz  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   rp   N)r   ArrayRefrQ   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   Nrp   )r   FuncCallrH   rQ   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   rp   N)r   r7  r   	StructRefrQ   )r3   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   rp   Nr  r   r<   r<   r=   p_postfix_expression_5  r  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   rp   N)r   CompoundLiteralr   r<   r<   r=   p_postfix_expression_6  r?  zCParser.p_postfix_expression_6c                 C   r   )z" primary_expression  : identifier r   rp   Nr<   r   r<   r<   r=   p_primary_expression_1  rz  zCParser.p_primary_expression_1c                 C   r   )z  primary_expression  : constant r   rp   Nr<   r   r<   r<   r=   p_primary_expression_2  rz  zCParser.p_primary_expression_2c                 C   r   )zp primary_expression  : unified_string_literal
                                | unified_wstring_literal
        r   rp   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   rp   Nr<   r   r<   r<   r=   p_primary_expression_4	  rz  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   rp   N)r   r   r  r7  r  )r3   r   rQ   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   rp   r   r   r   z$Unexpected parsing state. len(p): %uN)rH   r   r  rQ   r  NotImplementedErrorr   r<   r<   r=   p_offsetof_member_designator  s   *$z$CParser.p_offsetof_member_designatorc                 C   ra  )z argument_expression_list    : assignment_expression
                                        | argument_expression_list COMMA assignment_expression
        r   r   rp   r   N)rH   r   r  rQ   ro  rE   r   r<   r<   r=   p_argument_expression_list#  re  z"CParser.p_argument_expression_listc                 C   s    t |d | |d|d< dS )z identifier  : ID r   rp   N)r   r7  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
        rp   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 rj   )
ValueErrorr   Constantr   )r3   r   uCountlCountxr   prefixr<   r<   r=   p_constant_11  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   floatrK   )fFr  zlong doubledoublerp   N)lowerr   r  r   )r3   r   r   r<   r<   r=   p_constant_2H  s   zCParser.p_constant_2c                 C   s"   t d|d | |d|d< dS )z constant    : CHAR_CONST
                        | WCHAR_CONST
                        | U8CHAR_CONST
                        | U16CHAR_CONST
                        | U32CHAR_CONST
        charr   rp   N)r   r  r   r   r<   r<   r=   p_constant_3Y  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   rp   NrK   )rH   r   r  r   valuer   r<   r<   r=   p_unified_string_literalh  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 )a   unified_wstring_literal : WSTRING_LITERAL
                                    | U8STRING_LITERAL
                                    | U16STRING_LITERAL
                                    | U32STRING_LITERAL
                                    | unified_wstring_literal WSTRING_LITERAL
                                    | unified_wstring_literal U8STRING_LITERAL
                                    | unified_wstring_literal U16STRING_LITERAL
                                    | unified_wstring_literal U32STRING_LITERAL
        r   r  r   rp   NrK   )rH   r   r  r   r  rstripr   r<   r<   r=   p_unified_wstring_literals  s   
,z!CParser.p_unified_wstring_literalc                 C   "   |d |d< | d|d dS )z  brace_open  :   LBRACE
        r   rp   N
set_linenolinenor   r<   r<   r=   p_brace_open     zCParser.p_brace_openc                 C   r  )z  brace_close :   RBRACE
        r   rp   Nr  r   r<   r<   r=   p_brace_close  r  zCParser.p_brace_closec                 C   r!  )zempty : Nrp   r<   r   r<   r<   r=   p_empty  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)rN   r  rX   r  r+   find_tok_columnr@   r   r<   r<   r=   p_error  s   
zCParser.p_errorN)r   F)F)__name__
__module____qualname__r   r>   rB   rG   rJ   rR   rS   rW   r'   r(   r)   r*   r`   ri   rw   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*  r,  r/  r2  r5  r6  r   r;  r>  r@  rA  rH  rO  rR  rZ  r^  r_  r`  rd  rf  ri  rj  rk  rm  rp  rq  rr  rs  rt  rv  rw  rx  ry  r{  r|  r}  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r<   r<   r<   r=   r      sv   
o	

	)2,Y	
	7=	

		&		















	 
	

	
	

	
r   N)plyr   r   r   c_lexerr   	plyparserr   r   r   r   ast_transformsr	   r
   r   r<   r<   r<   r=   <module>   s   