403Webshell
Server IP : 192.158.238.246  /  Your IP : 3.142.201.222
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python38/lib/python3.8/site-packages/pycparser/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python38/lib/python3.8/site-packages/pycparser/__pycache__/c_parser.cpython-38.pyc
U

ӗ_��@s�ddlZddlmZddlmZddlmZddlmZm	Z	m
Z
ddlmZGdd	�d	e�Z
ed
kr|ddlZddlZddlZdS)�N)�yacc�)�c_ast)�CLexer)�	PLYParser�Coord�
ParseError)�fix_switch_casesc@seZdZ�d1dd�Z�d2d	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd �Zd!d"�Zd#d$�Z�d3d%d&�Zd'd(�Zd)d*�Zd+Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Zd>d?�Zd@dA�Z dBdC�Z!dDdE�Z"dFdG�Z#dHdI�Z$dJdK�Z%dLdM�Z&dNdO�Z'dPdQ�Z(dRdS�Z)dTdU�Z*dVdW�Z+dXdY�Z,dZd[�Z-d\d]�Z.d^d_�Z/d`da�Z0dbdc�Z1ddde�Z2dfdg�Z3dhdi�Z4djdk�Z5dldm�Z6dndo�Z7dpdq�Z8drds�Z9dtdu�Z:dvdw�Z;dxdy�Z<dzd{�Z=d|d}�Z>d~d�Z?d�d��Z@d�d��ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVd�d��ZWd�d��ZXd�d��ZYd�d��ZZd�d��Z[d�d��Z\d�d��Z]d�d��Z^d�d��Z_d�d��Z`d�dÄZad�dńZbd�dDŽZcd�dɄZdd�d˄Zed�d̈́Zfd�dτZgd�dфZhd�dӄZid�dՄZjd�dׄZkd�dلZld�dۄZmd�d݄Znd�d߄Zod�d�Zpd�d�Zqd�d�Zrd�d�Zsd�d�Ztd�d�Zud�d�Zvd�d�Zwd�d�Zxd�d�Zyd�d��Zzd�d��Z{d�d��Z|d�d��Z}d�d��Z~d�d��Z�d�d�Z��d�d�Z��d�d�Z��d�d�Z��d�d	�Z��d
�d�Z��d�d
�Z��d�d�Z��d�d�Z��d�d�Z��d�d�Z��d�d�Z��d�d�Z��d�d�Z��d�d�Z��d�d�Z��d �d!�Z��d"�d#�Z��d$�d%�Z��d&�d'�Z��d(�d)�Z��d*�d+�Z��d,�d-�Z��d.�d/�Z��d0S(4�CParserT�pycparser.lextab�pycparser.yacctabF�c	Cs�t|j|j|j|jd�|_|jj|||d�|jj|_ddddddd	d
ddd
dddg}|D]}|�|�qZt	j	|d||||d�|_
t�g|_d|_
dS)a� Create a new CParser.

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

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

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

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

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

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

            taboutputdir:
                Set this parameter to control the location of generated
                lextab and yacctab files.
        )Z
error_funcZon_lbrace_funcZon_rbrace_funcZtype_lookup_func)�optimize�lextab�	outputdirZabstract_declaratorZassignment_expressionZdeclaration_listZdeclaration_specifiersZdesignationZ
expressionZidentifier_listZinit_declarator_listZinitializer_listZparameter_type_listZspecifier_qualifier_listZblock_item_listZtype_qualifier_listZstruct_declarator_listZtranslation_unit_or_empty)�module�start�debugrZ	tabmodulerN)r�_lex_error_func�_lex_on_lbrace_func�_lex_on_rbrace_func�_lex_type_lookup_func�clexZbuildZtokensZ_create_opt_ruler�cparser�dict�_scope_stack�_last_yielded_token)	�self�lex_optimizer�
yacc_optimize�yacctab�
yacc_debugZtaboutputdirZrules_with_optZrule�r"�../pycparser/c_parser.py�__init__sN5��
��
zCParser.__init__rcCs6||j_|j��t�g|_d|_|jj||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)�inputZlexerr)r�filenameZreset_linenorrrr�parse)r�textr&Z
debuglevelr"r"r#r'~s


�z
CParser.parsecCs|j�t��dS�N)r�appendr�rr"r"r#�_push_scope�szCParser._push_scopecCs t|j�dkst�|j��dS)Nr)�lenr�AssertionError�popr+r"r"r#�
_pop_scope�szCParser._pop_scopecCs4|jd�|d�s"|�d||�d|jd|<dS)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��zCParser._add_typedef_namecCs4|jd�|d�r"|�d||�d|jd|<dS)ze Add a new object, function, or enum member name (ie an ID) to the
            current scope
        r1Fz;Non-typedef %r previously declared as typedef in this scopeNr2r5r"r"r#�_add_identifier�s��zCParser._add_identifiercCs.t|j�D]}|�|�}|dk	r
|Sq
dS)z8 Is *name* a typedef-name in the current scope?
        NF)�reversedrr3)rr6ZscopeZin_scoper"r"r#�_is_type_in_scope�s


zCParser._is_type_in_scopecCs|�||�||��dSr))r4�_coord)r�msg�line�columnr"r"r#r�szCParser._lex_error_funccCs|��dSr))r,r+r"r"r#r�szCParser._lex_on_lbrace_funccCs|��dSr))r0r+r"r"r#r�szCParser._lex_on_rbrace_funccCs|�|�}|S)z� Looks up types that were previously defined with
            typedef.
            Passed to the lexer for recognizing identifiers that
            are types.
        )r;)rr6Zis_typer"r"r#r�s
zCParser._lex_type_lookup_funccCs|jjS)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.
        )rZ
last_tokenr+r"r"r#�_get_yacc_lookahead_token�sz!CParser._get_yacc_lookahead_tokencCs\|}|}|jr|j}qt|tj�r,||_|S|}t|jtj�sF|j}q0|j|_||_|SdS)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zCParser._type_modify_declcCs�|}t|tj�s|j}q|j|_|j|_|D]:}t|tj�s,t|�dkrX|�	d|j
�q,||_|Sq,|s�t|jtj�s�|�	d|j
�tjdg|j
d�|_n tjdd�|D�|dj
d�|_|S)	z- Fixes a declaration. Modifies decl.
        rz Invalid multiple types specifiedzMissing type in declaration�int�r7cSsg|]}|jD]}|�qqSr")�names)�.0�idr6r"r"r#�
<listcomp>Usz/CParser._fix_decl_name_type.<locals>.<listcomp>r)rBrrCrA�declnamer6�quals�IdentifierTyper-r4r7�FuncDecl)rrD�typenamerAZtnr"r"r#�_fix_decl_name_type,s:�
��
�zCParser._fix_decl_name_typecCs(|ptggggd�}||�d|�|S)a� Declaration specifiers are represented by a dictionary
            with the entries:
            * qual: a list of type qualifiers
            * storage: a list of storage type qualifiers
            * type: a list of type specifiers
            * function: a list of function specifiers

            This method is given a declaration specifier, and a
            new specifier of a given kind.
            Returns the declaration specifier, with the new
            specifier incorporated.
        ��qual�storagerA�functionr)r�insert)rZdeclspecZnewspecZkind�specr"r"r#�_add_declaration_specifierYs
z"CParser._add_declaration_specifiercCsFd|dk}g}|d�d�dk	r&�n,|dddkr�t|d�dkstt|dd	j�d
kst|�|dd	jd�s�d}|dD]}t|d�r�|j}q�q�|�d
|�tj|dd	jddd|dd	jd�|dd<|dd	=nnt	|ddtj
tjtjf��sR|dd}t	|tj��s(|j
}�q|jdk�rR|dd	jd|_|dd	=|D]�}	|	ddk	�slt�|�r�tjd|d|d|	d|	djd�}
n<tjd|d|d|d|	d|	�d�|	�d�|	djd�}
t	|
j
tj
tjtj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.
        �typedefrUr�bitsizeNrDrA�r1r�?r7zInvalid declaration�rMrArNr7rT)r6rNrUrAr7rV�init�r6rNrUZfuncspecrAr_r[r7)r3r-rIr;�hasattrr7r4rrCrB�Struct�UnionrOrArMr.ZTypedef�DeclrRr8r6r9r*)rrX�decls�typedef_namespaceZ
is_typedefZdeclarationsr7�tZdecls_0_tailrD�declarationZ
fixed_declr"r"r#�_build_declarationsjsz&�
��

��
�zCParser._build_declarationscCsBd|dkst�|j|t|dd�gdd�d}tj||||jd�S)	z' Builds a function definition.
        rZrUN�rDr_T�rXrerfr)rD�param_decls�bodyr7)r.rirrZFuncDefr7)rrXrDrlrmrhr"r"r#�_build_function_definition�s���z"CParser._build_function_definitioncCs|dkrtjStjSdS)z` Given a token (either STRUCT or UNION), selects the
            appropriate AST class.
        ZstructN)rrbrc)rZtokenr"r"r#�_select_struct_union_class�sz"CParser._select_struct_union_class)
)�leftZLOR)rpZLAND)rp�OR)rpZXOR)rpZAND)rpZEQZNE)rpZGTZGEZLTZLE)rpZRSHIFTZLSHIFT)rpZPLUSZMINUS)rpZTIMESZDIVIDEZMODcCs2|ddkrt�g�|d<nt�|d�|d<dS)zh translation_unit_or_empty   : translation_unit
                                        | empty
        rNr)rZFileAST�r�pr"r"r#�p_translation_unit_or_empty�sz#CParser.p_translation_unit_or_emptycCs|d|d<dS)z4 translation_unit    : external_declaration
        rrNr"rrr"r"r#�p_translation_unit_1�szCParser.p_translation_unit_1cCs.|ddk	r|d�|d�|d|d<dS)zE translation_unit    : translation_unit external_declaration
        r\Nrr)�extendrrr"r"r#�p_translation_unit_2szCParser.p_translation_unit_2cCs|dg|d<dS)z7 external_declaration    : function_definition
        rrNr"rrr"r"r#�p_external_declaration_1sz CParser.p_external_declaration_1cCs|d|d<dS)z/ external_declaration    : declaration
        rrNr"rrr"r"r#�p_external_declaration_2sz CParser.p_external_declaration_2cCs|d|d<dS)z0 external_declaration    : pp_directive
        rrNr"rrr"r"r#�p_external_declaration_3sz CParser.p_external_declaration_3cCsd|d<dS)z( external_declaration    : SEMI
        Nrr"rrr"r"r#�p_external_declaration_4sz CParser.p_external_declaration_4cCs|�d|�|�d���dS)z  pp_directive  : PPHASH
        zDirectives not supported yetrN)r4r<�linenorrr"r"r#�p_pp_directive$s�zCParser.p_pp_directivec
CsPtggtjdg|�|�d��d�ggd�}|j||d|d|dd�|d<d	S)
zR function_definition : declarator declaration_list_opt compound_statement
        rGrrHrSr\��rXrDrlrmrN)rrrOr<r|rn�rrsrXr"r"r#�p_function_definition_1-s���zCParser.p_function_definition_1cCs.|d}|j||d|d|dd�|d<dS)zi function_definition : declaration_specifiers declarator declaration_list_opt compound_statement
        rr\r~�rrN)rnr�r"r"r#�p_function_definition_2>s�zCParser.p_function_definition_2cCs|d|d<dS)a
 statement   : labeled_statement
                        | expression_statement
                        | compound_statement
                        | selection_statement
                        | iteration_statement
                        | jump_statement
        rrNr"rrr"r"r#�p_statementIszCParser.p_statementc
Cs�|d}|ddkr�|d}tjtjtjf}t|�dkrzt|d|�rztjd|d|d|d|ddd|djd	�g}q�|j|t	ddd
�gdd�}n|j||ddd�}||d<dS)
zE decl_body : declaration_specifiers init_declarator_list_opt
        rr\NrArrTrUrVr`rjTrk)
rrbrc�Enumr-rBrdr7rir)rrsrXZtyZs_u_or_erer"r"r#�p_decl_body\s4�
��zCParser.p_decl_bodycCs|d|d<dS)z& declaration : decl_body SEMI
        rrNr"rrr"r"r#�
p_declaration�szCParser.p_declarationcCs,t|�dkr|dn|d|d|d<dS)zj declaration_list    : declaration
                                | declaration_list declaration
        r\rrN�r-rrr"r"r#�p_declaration_list�szCParser.p_declaration_listcCs|�|d|dd�|d<dS)zM declaration_specifiers  : type_qualifier declaration_specifiers_opt
        r\rrTrN�rYrrr"r"r#�p_declaration_specifiers_1�sz"CParser.p_declaration_specifiers_1cCs|�|d|dd�|d<dS)zM declaration_specifiers  : type_specifier declaration_specifiers_opt
        r\rrArNr�rrr"r"r#�p_declaration_specifiers_2�sz"CParser.p_declaration_specifiers_2cCs|�|d|dd�|d<dS)zV declaration_specifiers  : storage_class_specifier declaration_specifiers_opt
        r\rrUrNr�rrr"r"r#�p_declaration_specifiers_3�sz"CParser.p_declaration_specifiers_3cCs|�|d|dd�|d<dS)zQ declaration_specifiers  : function_specifier declaration_specifiers_opt
        r\rrVrNr�rrr"r"r#�p_declaration_specifiers_4�sz"CParser.p_declaration_specifiers_4cCs|d|d<dS)z� storage_class_specifier : AUTO
                                    | REGISTER
                                    | STATIC
                                    | EXTERN
                                    | TYPEDEF
        rrNr"rrr"r"r#�p_storage_class_specifier�sz!CParser.p_storage_class_specifiercCs|d|d<dS)z& function_specifier  : INLINE
        rrNr"rrr"r"r#�p_function_specifier�szCParser.p_function_specifiercCs(tj|dg|�|�d��d�|d<dS)a� type_specifier  : VOID
                            | _BOOL
                            | CHAR
                            | SHORT
                            | INT
                            | LONG
                            | FLOAT
                            | DOUBLE
                            | _COMPLEX
                            | SIGNED
                            | UNSIGNED
        rrHrN�rrOr<r|rrr"r"r#�p_type_specifier_1�s
zCParser.p_type_specifier_1cCs|d|d<dS)z� type_specifier  : typedef_name
                            | enum_specifier
                            | struct_or_union_specifier
        rrNr"rrr"r"r#�p_type_specifier_2�szCParser.p_type_specifier_2cCs|d|d<dS)zo type_qualifier  : CONST
                            | RESTRICT
                            | VOLATILE
        rrNr"rrr"r"r#�p_type_qualifier�szCParser.p_type_qualifiercCs0t|�dkr|d|dgn|dg|d<dS)z� init_declarator_list    : init_declarator
                                    | init_declarator_list COMMA init_declarator
        r�rr~rNr�rrr"r"r#�p_init_declarator_list_1�sz CParser.p_init_declarator_list_1cCstd|dd�g|d<dS)z6 init_declarator_list    : EQUALS initializer
        Nr\rjr�rrrr"r"r#�p_init_declarator_list_2�sz CParser.p_init_declarator_list_2cCst|ddd�g|d<dS)z7 init_declarator_list    : abstract_declarator
        rNrjrr�rrr"r"r#�p_init_declarator_list_3�sz CParser.p_init_declarator_list_3cCs,t|dt|�dkr|dndd�|d<dS)zb init_declarator : declarator
                            | declarator EQUALS initializer
        rr\r~Nrjr)rr-rrr"r"r#�p_init_declaratorszCParser.p_init_declaratorcCs|�|d|dd�|d<dS)zS specifier_qualifier_list    : type_qualifier specifier_qualifier_list_opt
        r\rrTrNr�rrr"r"r#�p_specifier_qualifier_list_1sz$CParser.p_specifier_qualifier_list_1cCs|�|d|dd�|d<dS)zS specifier_qualifier_list    : type_specifier specifier_qualifier_list_opt
        r\rrArNr�rrr"r"r#�p_specifier_qualifier_list_2sz$CParser.p_specifier_qualifier_list_2cCs4|�|d�}||dd|�|�d��d�|d<dS)z{ struct_or_union_specifier   : struct_or_union ID
                                        | struct_or_union TYPEID
        rr\N�r6rer7r�ror<r|�rrs�klassr"r"r#�p_struct_or_union_specifier_1s�z%CParser.p_struct_or_union_specifier_1cCs4|�|d�}|d|d|�|�d��d�|d<dS)zd struct_or_union_specifier : struct_or_union brace_open struct_declaration_list brace_close
        rNr~r\r�rr�r�r"r"r#�p_struct_or_union_specifier_2s�z%CParser.p_struct_or_union_specifier_2cCs8|�|d�}||d|d|�|�d��d�|d<dS)z� struct_or_union_specifier   : struct_or_union ID brace_open struct_declaration_list brace_close
                                        | struct_or_union TYPEID brace_open struct_declaration_list brace_close
        rr\r�r�rNr�r�r"r"r#�p_struct_or_union_specifier_3&s�z%CParser.p_struct_or_union_specifier_3cCs|d|d<dS)zF struct_or_union : STRUCT
                            | UNION
        rrNr"rrr"r"r#�p_struct_or_union0szCParser.p_struct_or_unioncCs,t|�dkr|dn|d|d|d<dS)z� struct_declaration_list     : struct_declaration
                                        | struct_declaration_list struct_declaration
        r\rrNr�rrr"r"r#�p_struct_declaration_list8sz!CParser.p_struct_declaration_listcCs�|d}d|dkst�|ddk	r8|j||dd�}nht|d�dkr�|dd}t|tj�rf|}n
t�|�}|j|t|d	�gd�}n|j|tddd
�gd�}||d<dS)zW struct_declaration : specifier_qualifier_list struct_declarator_list_opt SEMI
        rrZrUr\N�rXrerAr�rDrj)r.rir-rBrZNoderOr)rrsrXreZnodeZ	decl_typer"r"r#�p_struct_declaration_1>s*�

�	�zCParser.p_struct_declaration_1cCs(|j|dt|ddd�gd�|d<dS)zP struct_declaration : specifier_qualifier_list abstract_declarator SEMI
        rr\Nrjr�r)rirrrr"r"r#�p_struct_declaration_2ds
�zCParser.p_struct_declaration_2cCs0t|�dkr|d|dgn|dg|d<dS)z� struct_declarator_list  : struct_declarator
                                    | struct_declarator_list COMMA struct_declarator
        r�rr~rNr�rrr"r"r#�p_struct_declarator_listrsz CParser.p_struct_declarator_listcCs|ddd�|d<dS)z( struct_declarator : declarator
        rN�rDr[rr"rrr"r"r#�p_struct_declarator_1{szCParser.p_struct_declarator_1cCsDt|�dkr$|d|dd�|d<nt�ddd�|dd�|d<dS)z� struct_declarator   : declarator COLON constant_expression
                                | COLON constant_expression
        r~rr�rNr\)r-rrCrrr"r"r#�p_struct_declarator_2�szCParser.p_struct_declarator_2c	Cs&t�|dd|�|�d���|d<dS)zM enum_specifier  : ENUM ID
                            | ENUM TYPEID
        r\Nrr�rr�r<r|rrr"r"r#�p_enum_specifier_1�szCParser.p_enum_specifier_1c	Cs&t�d|d|�|�d���|d<dS)zG enum_specifier  : ENUM brace_open enumerator_list brace_close
        Nr~rrr�rrr"r"r#�p_enum_specifier_2�szCParser.p_enum_specifier_2c	Cs*t�|d|d|�|�d���|d<dS)z� enum_specifier  : ENUM ID brace_open enumerator_list brace_close
                            | ENUM TYPEID brace_open enumerator_list brace_close
        r\r�rrNr�rrr"r"r#�p_enum_specifier_3�szCParser.p_enum_specifier_3cCsht|�dkr*t�|dg|dj�|d<n:t|�dkrD|d|d<n |dj�|d�|d|d<dS)z� enumerator_list : enumerator
                            | enumerator_list COMMA
                            | enumerator_list COMMA enumerator
        r\rrr~N)r-rZEnumeratorListr7Zenumeratorsr*rrr"r"r#�p_enumerator_list�szCParser.p_enumerator_listc	Csjt|�dkr,t�|dd|�|�d���}n"t�|d|d|�|�d���}|�|j|j�||d<dS)zR enumerator  : ID
                        | ID EQUALS constant_expression
        r\rNr~r)r-rZ
Enumeratorr<r|r9r6r7)rrsZ
enumeratorr"r"r#�p_enumerator�s��zCParser.p_enumeratorcCs|d|d<dS)z) declarator  : direct_declarator
        rrNr"rrr"r"r#�p_declarator_1�szCParser.p_declarator_1cCs|�|d|d�|d<dS)z1 declarator  : pointer direct_declarator
        r\rrN�rFrrr"r"r#�p_declarator_2�szCParser.p_declarator_2c	Cs:tj|ddd|�|�d��d�}|�||d�|d<dS)z& declarator  : pointer TYPEID
        r\Nr^rr)rrCr<r|rF)rrsrDr"r"r#�p_declarator_3�s�zCParser.p_declarator_3c	Cs*tj|ddd|�|�d��d�|d<dS)z" direct_declarator   : ID
        rNr^r)rrCr<r|rrr"r"r#�p_direct_declarator_1�s�zCParser.p_direct_declarator_1cCs|d|d<dS)z8 direct_declarator   : LPAREN declarator RPAREN
        r\rNr"rrr"r"r#�p_direct_declarator_2�szCParser.p_direct_declarator_2cCsft|�dkr|dngpg}tjdt|�dkr6|dn|d||djd�}|j|d|d�|d<dS)	zu direct_declarator   : direct_declarator LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET
        �r~Nr�r�rAZdim�	dim_qualsr7�rDrEr)r-r�	ArrayDeclr7rF)rrsrN�arrr"r"r#�p_direct_declarator_3�s�zCParser.p_direct_declarator_3cCs^dd�|d|dfD�}dd�|D�}tjd|d||djd	�}|j|d|d
�|d<dS)z� direct_declarator   : direct_declarator LBRACKET STATIC type_qualifier_list_opt assignment_expression RBRACKET
                                | direct_declarator LBRACKET type_qualifier_list STATIC assignment_expression RBRACKET
        cSs g|]}t|t�r|n|g�qSr"�rB�list)rJ�itemr"r"r#rL�s�z1CParser.p_direct_declarator_4.<locals>.<listcomp>r~r�cSs"g|]}|D]}|dk	r|�qqSr)r")rJZsublistrTr"r"r#rL�s
�Nr�rr�r�r�rr�r7rF)rrsZlisted_qualsr�r�r"r"r#�p_direct_declarator_4�s��zCParser.p_direct_declarator_4c
Cs^tjdt�|d|�|�d���|ddkr4|dng|djd�}|j|d|d�|d<dS)za direct_declarator   : direct_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET
        Nr�r~rr�r�r�rr��IDr<r|r7rF�rrsr�r"r"r#�p_direct_declarator_5s�zCParser.p_direct_declarator_5cCsztj|dd|djd�}|��jdkr`|jdk	r`|jjD]$}t|tj�rNq`|�	|j
|j�q:|j|d|d�|d<dS)z� direct_declarator   : direct_declarator LPAREN parameter_type_list RPAREN
                                | direct_declarator LPAREN identifier_list_opt RPAREN
        r~Nr��argsrAr7ZLBRACEr�r)rrPr7r@rAr��paramsrB�
EllipsisParamr9r6rF)rrs�funcZparamr"r"r#�p_direct_declarator_6s�
zCParser.p_direct_declarator_6cCsn|�|�d��}tj|dpgd|d�}t|�dkrb|d}|jdk	rN|j}q<||_|d|d<n||d<dS)zm pointer : TIMES type_qualifier_list_opt
                    | TIMES type_qualifier_list_opt pointer
        rr\N)rNrAr7r~r)r<r|rZPtrDeclr-rA)rrsr7Znested_typeZ	tail_typer"r"r#�	p_pointer(s
zCParser.p_pointercCs0t|�dkr|dgn|d|dg|d<dS)zs type_qualifier_list : type_qualifier
                                | type_qualifier_list type_qualifier
        r\rrNr�rrr"r"r#�p_type_qualifier_listFszCParser.p_type_qualifier_listc	Cs>t|�dkr.|dj�t�|�|�d����|d|d<dS)zn parameter_type_list : parameter_list
                                | parameter_list COMMA ELLIPSIS
        r\rr~rN)r-r�r*rr�r<r|rrr"r"r#�p_parameter_type_listLs"zCParser.p_parameter_type_listcCsNt|�dkr*t�|dg|dj�|d<n |dj�|d�|d|d<dS)zz parameter_list  : parameter_declaration
                            | parameter_list COMMA parameter_declaration
        r\rrr~N�r-rZ	ParamListr7r�r*rrr"r"r#�p_parameter_listUszCParser.p_parameter_listcCsX|d}|ds2tjdg|�|�d��d�g|d<|j|t|dd�gd�d|d<d	S)
zE parameter_declaration   : declaration_specifiers declarator
        rrArGrHr\r�r�rN)rrOr<r|rirr�r"r"r#�p_parameter_declaration_1_s���z!CParser.p_parameter_declaration_1c	Cs�|d}|ds2tjdg|�|�d��d�g|d<t|d�dkr�t|ddj�dkr�|�|ddjd�r�|j|t|ddd	�gd
�d}nHtj	d|d|dp�t�
ddd�|�|�d��d
�}|d}|�||�}||d<dS)zR parameter_declaration   : declaration_specifiers abstract_declarator_opt
        rrArGrHr1rr\Nrjr�r
rT�r6rNrAr7)rrOr<r|r-rIr;rir�TypenamerCrR)rrsrXrDrQr"r"r#�p_parameter_declaration_2js.�&����z!CParser.p_parameter_declaration_2cCsNt|�dkr*t�|dg|dj�|d<n |dj�|d�|d|d<dS)ze identifier_list : identifier
                            | identifier_list COMMA identifier
        r\rrr~Nr�rrr"r"r#�p_identifier_list�szCParser.p_identifier_listcCs|d|d<dS)z- initializer : assignment_expression
        rrNr"rrr"r"r#�p_initializer_1�szCParser.p_initializer_1cCs:|ddkr*t�g|�|�d���|d<n|d|d<dS)z� initializer : brace_open initializer_list_opt brace_close
                        | brace_open initializer_list COMMA brace_close
        r\Nrr)r�InitListr<r|rrr"r"r#�p_initializer_2�szCParser.p_initializer_2cCs�t|�dkrN|ddkr |dnt�|d|d�}t�|g|dj�|d<nD|ddkrb|dnt�|d|d�}|dj�|�|d|d<dS)z� initializer_list    : designation_opt initializer
                                | initializer_list COMMA designation_opt initializer
        r~rNr\rr�)r-rZNamedInitializerr�r7�exprsr*)rrsr_r"r"r#�p_initializer_list�s((zCParser.p_initializer_listcCs|d|d<dS)z. designation : designator_list EQUALS
        rrNr"rrr"r"r#�
p_designation�szCParser.p_designationcCs0t|�dkr|dgn|d|dg|d<dS)z_ designator_list : designator
                            | designator_list designator
        r\rrNr�rrr"r"r#�p_designator_list�szCParser.p_designator_listcCs|d|d<dS)zi designator  : LBRACKET constant_expression RBRACKET
                        | PERIOD identifier
        r\rNr"rrr"r"r#�p_designator�szCParser.p_designatorc	CsTtjd|dd|dp$t�ddd�|�|�d��d�}|�||dd�|d<dS)	zH type_name   : specifier_qualifier_list abstract_declarator_opt
        r
rrTr\Nr�rAr)rr�rCr<r|rR)rrsrQr"r"r#�p_type_name�s	
�zCParser.p_type_namecCs(t�ddd�}|j||dd�|d<dS)z+ abstract_declarator     : pointer
        Nrr�r)rrCrF)rrsZ	dummytyper"r"r#�p_abstract_declarator_1�s
�zCParser.p_abstract_declarator_1cCs|�|d|d�|d<dS)zF abstract_declarator     : pointer direct_abstract_declarator
        r\rrNr�rrr"r"r#�p_abstract_declarator_2�szCParser.p_abstract_declarator_2cCs|d|d<dS)z> abstract_declarator     : direct_abstract_declarator
        rrNr"rrr"r"r#�p_abstract_declarator_3�szCParser.p_abstract_declarator_3cCs|d|d<dS)zA direct_abstract_declarator  : LPAREN abstract_declarator RPAREN r\rNr"rrr"r"r#�p_direct_abstract_declarator_1�sz&CParser.p_direct_abstract_declarator_1cCs6tjd|dg|djd�}|j|d|d�|d<dS)zn direct_abstract_declarator  : direct_abstract_declarator LBRACKET assignment_expression_opt RBRACKET
        Nr~rr�r�rr�r�r"r"r#�p_direct_abstract_declarator_2�s�z&CParser.p_direct_abstract_declarator_2c	Cs4tjt�ddd�|dg|�|�d��d�|d<dS)zS direct_abstract_declarator  : LBRACKET assignment_expression_opt RBRACKET
        Nr\rr�r)rr�rCr<r|rrr"r"r#�p_direct_abstract_declarator_3�s�z&CParser.p_direct_abstract_declarator_3c
CsJtjdt�|d|�|�d���g|djd�}|j|d|d�|d<dS)zZ direct_abstract_declarator  : direct_abstract_declarator LBRACKET TIMES RBRACKET
        Nr~rr�r�rr�r�r"r"r#�p_direct_abstract_declarator_4s�z&CParser.p_direct_abstract_declarator_4c
CsHtjt�ddd�t�|d|�|�d���g|�|�d��d�|d<dS)z? direct_abstract_declarator  : LBRACKET TIMES RBRACKET
        Nr~rr�r)rr�rCr�r<r|rrr"r"r#�p_direct_abstract_declarator_5s�z&CParser.p_direct_abstract_declarator_5cCs4tj|dd|djd�}|j|d|d�|d<dS)zh direct_abstract_declarator  : direct_abstract_declarator LPAREN parameter_type_list_opt RPAREN
        r~Nrr�r�r)rrPr7rF)rrsr�r"r"r#�p_direct_abstract_declarator_6s�z&CParser.p_direct_abstract_declarator_6cCs2tj|dt�ddd�|�|�d��d�|d<dS)zM direct_abstract_declarator  : LPAREN parameter_type_list_opt RPAREN
        r\Nrr�r)rrPrCr<r|rrr"r"r#�p_direct_abstract_declarator_7s
�z&CParser.p_direct_abstract_declarator_7cCs(t|dt�r|dn|dg|d<dS)zG block_item  : declaration
                        | statement
        rrNr�rrr"r"r#�p_block_item*szCParser.p_block_itemcCs:t|�dks|ddgkr"|dn|d|d|d<dS)z_ block_item_list : block_item
                            | block_item_list block_item
        r\Nrrr�rrr"r"r#�p_block_item_list2szCParser.p_block_item_listcCs&tj|d|�|�d��d�|d<dS)zA compound_statement : brace_open block_item_list_opt brace_close r\r)Zblock_itemsr7rN)rZCompoundr<r|rrr"r"r#�p_compound_statement_19s�zCParser.p_compound_statement_1c	Cs*t�|d|d|�|�d���|d<dS)z( labeled_statement : ID COLON statement rr~rN)rZLabelr<r|rrr"r"r#�p_labeled_statement_1?szCParser.p_labeled_statement_1c	Cs,t�|d|dg|�|�d���|d<dS)z> labeled_statement : CASE constant_expression COLON statement r\r�rrN)rZCaser<r|rrr"r"r#�p_labeled_statement_2CszCParser.p_labeled_statement_2cCs&t�|dg|�|�d���|d<dS)z- labeled_statement : DEFAULT COLON statement r~rrN)rZDefaultr<r|rrr"r"r#�p_labeled_statement_3GszCParser.p_labeled_statement_3c
Cs,t�|d|dd|�|�d���|d<dS)z= selection_statement : IF LPAREN expression RPAREN statement r~r�Nrr�rZIfr<r|rrr"r"r#�p_selection_statement_1KszCParser.p_selection_statement_1c
Cs0t�|d|d|d|�|�d���|d<dS)zL selection_statement : IF LPAREN expression RPAREN statement ELSE statement r~r��rrNr�rrr"r"r#�p_selection_statement_2OszCParser.p_selection_statement_2c
Cs.tt�|d|d|�|�d����|d<dS)zA selection_statement : SWITCH LPAREN expression RPAREN statement r~r�rrN)r	rZSwitchr<r|rrr"r"r#�p_selection_statement_3Ss �zCParser.p_selection_statement_3c	Cs*t�|d|d|�|�d���|d<dS)z@ iteration_statement : WHILE LPAREN expression RPAREN statement r~r�rrN)rZWhiler<r|rrr"r"r#�p_iteration_statement_1XszCParser.p_iteration_statement_1c	Cs*t�|d|d|�|�d���|d<dS)zH iteration_statement : DO statement WHILE LPAREN expression RPAREN SEMI r�r\rrN)rZDoWhiler<r|rrr"r"r#�p_iteration_statement_2\szCParser.p_iteration_statement_2cCs6t�|d|d|d|d|�|�d���|d<dS)zj iteration_statement : FOR LPAREN expression_opt SEMI expression_opt SEMI expression_opt RPAREN statement r~r�r��	rrN)r�Forr<r|rrr"r"r#�p_iteration_statement_3`szCParser.p_iteration_statement_3cCsJt�t�|d|�|�d���|d|d|d|�|�d���|d<dS)zb iteration_statement : FOR LPAREN declaration expression_opt SEMI expression_opt RPAREN statement r~rr���rN)rr�ZDeclListr<r|rrr"r"r#�p_iteration_statement_4ds�zCParser.p_iteration_statement_4cCs$t�|d|�|�d���|d<dS)z  jump_statement  : GOTO ID SEMI r\rrN)rZGotor<r|rrr"r"r#�p_jump_statement_1iszCParser.p_jump_statement_1cCst�|�|�d���|d<dS)z jump_statement  : BREAK SEMI rrN)rZBreakr<r|rrr"r"r#�p_jump_statement_2mszCParser.p_jump_statement_2cCst�|�|�d���|d<dS)z! jump_statement  : CONTINUE SEMI rrN)rZContinuer<r|rrr"r"r#�p_jump_statement_3qszCParser.p_jump_statement_3cCs4t�t|�dkr|dnd|�|�d���|d<dS)z\ jump_statement  : RETURN expression SEMI
                            | RETURN SEMI
        r�r\Nrr)rZReturnr-r<r|rrr"r"r#�p_jump_statement_4uszCParser.p_jump_statement_4cCs8|ddkr(t�|�|�d���|d<n|d|d<dS)z, expression_statement : expression_opt SEMI rNr)rZEmptyStatementr<r|rrr"r"r#�p_expression_statement{szCParser.p_expression_statementcCsjt|�dkr|d|d<nLt|dtj�sFt�|dg|dj�|d<|dj�|d�|d|d<dS)zn expression  : assignment_expression
                        | expression COMMA assignment_expression
        r\rrr~N)r-rBr�ExprListr7r�r*rrr"r"r#�p_expression�szCParser.p_expressioncCs(tj|dg|�|�d��d�|d<dS)z typedef_name : TYPEID rrHrNr�rrr"r"r#�p_typedef_name�szCParser.p_typedef_namecCsDt|�dkr|d|d<n&t�|d|d|d|dj�|d<dS)z� assignment_expression   : conditional_expression
                                    | unary_expression assignment_operator assignment_expression
        r\rrr~N)r-rZ
Assignmentr7rrr"r"r#�p_assignment_expression�szCParser.p_assignment_expressioncCs|d|d<dS)a� assignment_operator : EQUALS
                                | XOREQUAL
                                | TIMESEQUAL
                                | DIVEQUAL
                                | MODEQUAL
                                | PLUSEQUAL
                                | MINUSEQUAL
                                | LSHIFTEQUAL
                                | RSHIFTEQUAL
                                | ANDEQUAL
                                | OREQUAL
        rrNr"rrr"r"r#�p_assignment_operator�s
zCParser.p_assignment_operatorcCs|d|d<dS)z. constant_expression : conditional_expression rrNr"rrr"r"r#�p_constant_expression�szCParser.p_constant_expressioncCsDt|�dkr|d|d<n&t�|d|d|d|dj�|d<dS)z� conditional_expression  : binary_expression
                                    | binary_expression CONDOP expression COLON conditional_expression
        r\rrr~r�N)r-rZ	TernaryOpr7rrr"r"r#�p_conditional_expression�sz CParser.p_conditional_expressioncCsDt|�dkr|d|d<n&t�|d|d|d|dj�|d<dS)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\rrr~N)r-rZBinaryOpr7rrr"r"r#�p_binary_expression�szCParser.p_binary_expressioncCs|d|d<dS)z$ cast_expression : unary_expression rrNr"rrr"r"r#�p_cast_expression_1�szCParser.p_cast_expression_1c	Cs*t�|d|d|�|�d���|d<dS)z; cast_expression : LPAREN type_name RPAREN cast_expression r\r�rrN)rZCastr<r|rrr"r"r#�p_cast_expression_2�szCParser.p_cast_expression_2cCs|d|d<dS)z* unary_expression    : postfix_expression rrNr"rrr"r"r#�p_unary_expression_1�szCParser.p_unary_expression_1cCs$t�|d|d|dj�|d<dS)z� unary_expression    : PLUSPLUS unary_expression
                                | MINUSMINUS unary_expression
                                | unary_operator cast_expression
        rr\rN�r�UnaryOpr7rrr"r"r#�p_unary_expression_2�szCParser.p_unary_expression_2c	Cs>t�|dt|�dkr|dn|d|�|�d���|d<dS)zx unary_expression    : SIZEOF unary_expression
                                | SIZEOF LPAREN type_name RPAREN
        rr~r\rN)rrr-r<r|rrr"r"r#�p_unary_expression_3�s
�zCParser.p_unary_expression_3cCs|d|d<dS)z� unary_operator  : AND
                            | TIMES
                            | PLUS
                            | MINUS
                            | NOT
                            | LNOT
        rrNr"rrr"r"r#�p_unary_operator�szCParser.p_unary_operatorcCs|d|d<dS)z* postfix_expression  : primary_expression rrNr"rrr"r"r#�p_postfix_expression_1�szCParser.p_postfix_expression_1cCs$t�|d|d|dj�|d<dS)zG postfix_expression  : postfix_expression LBRACKET expression RBRACKET rr~rN)rZArrayRefr7rrr"r"r#�p_postfix_expression_2szCParser.p_postfix_expression_2cCs4t�|dt|�dkr|dnd|dj�|d<dS)z� postfix_expression  : postfix_expression LPAREN argument_expression_list RPAREN
                                | postfix_expression LPAREN RPAREN
        rr�r~Nr)r�FuncCallr-r7rrr"r"r#�p_postfix_expression_3szCParser.p_postfix_expression_3cCsBt�|d|�|�d���}t�|d|d||dj�|d<dS)z� postfix_expression  : postfix_expression PERIOD ID
                                | postfix_expression PERIOD TYPEID
                                | postfix_expression ARROW ID
                                | postfix_expression ARROW TYPEID
        r~rr\rN)rr�r<r|Z	StructRefr7)rrsZfieldr"r"r#�p_postfix_expression_4szCParser.p_postfix_expression_4cCs(t�d|d|d|dj�|d<dS)z{ postfix_expression  : postfix_expression PLUSPLUS
                                | postfix_expression MINUSMINUS
        rsr\rrNrrrr"r"r#�p_postfix_expression_5szCParser.p_postfix_expression_5cCst�|d|d�|d<dS)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�rN)rZCompoundLiteralrrr"r"r#�p_postfix_expression_6szCParser.p_postfix_expression_6cCs|d|d<dS)z" primary_expression  : identifier rrNr"rrr"r"r#�p_primary_expression_1 szCParser.p_primary_expression_1cCs|d|d<dS)z  primary_expression  : constant rrNr"rrr"r"r#�p_primary_expression_2$szCParser.p_primary_expression_2cCs|d|d<dS)zp primary_expression  : unified_string_literal
                                | unified_wstring_literal
        rrNr"rrr"r"r#�p_primary_expression_3(szCParser.p_primary_expression_3cCs|d|d<dS)z0 primary_expression  : LPAREN expression RPAREN r\rNr"rrr"r"r#�p_primary_expression_4.szCParser.p_primary_expression_4cCsF|�|�d��}t�t�|d|�t�|d|dg|�|�|d<dS)zQ primary_expression  : OFFSETOF LPAREN type_name COMMA identifier RPAREN
        rr~r�rN)r<r|rrr�r)rrsr7r"r"r#�p_primary_expression_52s
�zCParser.p_primary_expression_5cCsNt|�dkr*t�|dg|dj�|d<n |dj�|d�|d|d<dS)z� argument_expression_list    : assignment_expression
                                        | argument_expression_list COMMA assignment_expression
        r\rrr~N)r-rrr7r�r*rrr"r"r#�p_argument_expression_list:sz"CParser.p_argument_expression_listcCs$t�|d|�|�d���|d<dS)z identifier  : ID rrN)rr�r<r|rrr"r"r#�p_identifierDszCParser.p_identifierc	Cs&t�d|d|�|�d���|d<dS)z� constant    : INT_CONST_DEC
                        | INT_CONST_OCT
                        | INT_CONST_HEX
                        | INT_CONST_BIN
        rGrrN�r�Constantr<r|rrr"r"r#�p_constant_1Hs
�zCParser.p_constant_1c	Cs&t�d|d|�|�d���|d<dS)zM constant    : FLOAT_CONST
                        | HEX_FLOAT_CONST
        �floatrrNr"rrr"r"r#�p_constant_2Qs
�zCParser.p_constant_2c	Cs&t�d|d|�|�d���|d<dS)zH constant    : CHAR_CONST
                        | WCHAR_CONST
        �charrrNr"rrr"r"r#�p_constant_3Xs
�zCParser.p_constant_3c	Csht|�dkr0t�d|d|�|�d���|d<n4|djdd�|ddd�|d_|d|d<dS)z~ unified_string_literal  : STRING_LITERAL
                                    | unified_string_literal STRING_LITERAL
        r\�stringrrNr1)r-rr#r<r|�valuerrr"r"r#�p_unified_string_literalds�
(z CParser.p_unified_string_literalc	Cslt|�dkr0t�d|d|�|�d���|d<n8|dj��dd�|ddd�|d_|d|d<dS)z� unified_wstring_literal : WSTRING_LITERAL
                                    | unified_wstring_literal WSTRING_LITERAL
        r\r)rrNr1)r-rr#r<r|r*�rstriprrr"r"r#�p_unified_wstring_literalos�
,z!CParser.p_unified_wstring_literalcCs|d|d<dS)z  brace_open  :   LBRACE
        rrNr"rrr"r"r#�p_brace_openzszCParser.p_brace_opencCs|d|d<dS)z  brace_close :   RBRACE
        rrNr"rrr"r"r#�
p_brace_closeszCParser.p_brace_closecCsd|d<dS)zempty : Nrr"rrr"r"r#�p_empty�szCParser.p_emptycCs<|r,|�d|j|j|j|j�|�d��n|�dd�dS)Nz
before: %s)r|r?zAt end of inputr
)r4r*r<r|rZfind_tok_columnrrr"r"r#�p_error�s
��zCParser.p_errorN)TrTrFr
)r
r)F)��__name__�
__module__�__qualname__r$r'r,r0r8r9r;rrrrr@rFrRrYrirnroZ
precedencertrurwrxryrzr{r}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrr	r
rrr
rrrrrrrrrrrrrrrr r!r$r&r(r+r-r.r/r0r1r"r"r"r#r
s6�
j	

	)7-Y		;		
	
&		
			

	
		

		
	
	r
�__main__)�reZplyrr
r�c_lexerrZ	plyparserrrrZast_transformsr	r
r2�pprint�time�sysr"r"r"r#�<module>	s,

Youez - 2016 - github.com/yon3zu
LinuXploit