Your IP : 216.73.216.196


Current Path : /opt/alt/python35/lib/python3.5/site-packages/pycparser/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/pycparser/__pycache__/c_parser.cpython-35.opt-1.pyc



I�]��@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
@s!eZdZdddddddd�Zddd	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd �Zd!d"�Zd#d$�Zdd%d&�Zd'd(�Zd)d*�ZdMZd>d?�Zd@dA�ZdBdC�ZdDdE�ZdFdG�ZdHdI�ZdJdK�ZdLdM�ZdNdO�ZdPdQ�ZdRdS�Z dTdU�Z!dVdW�Z"dXdY�Z#dZd[�Z$d\d]�Z%d^d_�Z&d`da�Z'dbdc�Z(ddde�Z)dfdg�Z*dhdi�Z+djdk�Z,dldm�Z-dndo�Z.dpdq�Z/drds�Z0dtdu�Z1dvdw�Z2dxdy�Z3dzd{�Z4d|d}�Z5d~d�Z6d�d��Z7d�d��Z8d�d��Z9d�d��Z:d�d��Z;d�d��Z<d�d��Z=d�d��Z>d�d��Z?d�d��Z@d�d��ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVd�d��ZWd�d��ZXd�d��ZYd�d��ZZd�d��Z[d�d��Z\d�d��Z]d�d��Z^d�d��Z_d�d��Z`d�d��Zad�d��Zbd�d��Zcd�d��Zdd�d��Zed�d��Zfd�d��Zgd�d��Zhd�d��Zid�d��Zjd�d��Zkd�d��Zld�d��Zmd�d��Znd�d��Zod�d��Zpd�d��Zqd�d��Zrd�d��Zsd�d��Ztd�d��Zud�d��Zvdd�Zwdd�Zxdd�Zydd�Zzdd	�Z{d
d�Z|dd
�Z}dd�Z~dd�Zdd�Z�dd�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�d0d1�Z�d2d3�Z�d4d5�Z�d6d7�Z�d8d9�Z�d:d;�Z�d<d=�Z�d>d?�Z�d@dA�Z�dBS(N�CParserTzpycparser.lextabzpycparser.yacctabF�c	Cs�td|jd|jd|jd|j�|_|jjd|d|d|�|jj|_dd	d
ddd
ddddddddg}x|D]}|j|�q�Wt	j	d|ddd|d|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�lextabZ	outputdirZabstract_declaratorZassignment_expressionZdeclaration_listZdeclaration_specifiersZdesignationZ
expressionZidentifier_listZinit_declarator_listZinitializer_listZparameter_type_listZspecifier_qualifier_listZblock_item_listZtype_qualifier_listZstruct_declarator_list�module�startZtranslation_unit_or_empty�debugZ	tabmoduleN)r�_lex_error_func�_lex_on_lbrace_func�_lex_on_rbrace_func�_lex_type_lookup_func�clexZbuild�tokensZ_create_opt_ruler�cparser�dict�_scope_stack�_last_yielded_token)	�selfZlex_optimizer
Z
yacc_optimizeZyacctabZ
yacc_debugZtaboutputdirZrules_with_optZrule�r�C/opt/alt/python35/lib/python3.5/site-packages/pycparser/c_parser.py�__init__sF5				
	
zCParser.__init__rcCsS||j_|jj�t�g|_d|_|jjd|d|jd|�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
debuglevelrrrr!~s

		z
CParser.parsecCs|jjt��dS)N)r�appendr)rrrr�_push_scope�szCParser._push_scopecCs|jj�dS)N)r�pop)rrrr�
_pop_scope�szCParser._pop_scopecCsB|jdj|d�s-|jd||�d|jd|<dS)zC Add a new typedef name (ie a TYPEID) to the current scope
        rTz;Typedef %r previously declared as non-typedef in this scopeN���r')r�get�_parse_error)r�name�coordrrr�_add_typedef_name�s
zCParser._add_typedef_namecCsB|jdj|d�r-|jd||�d|jd|<dS)ze Add a new object, function, or enum member name (ie an ID) to the
            current scope
        rFz;Non-typedef %r previously declared as typedef in this scopeNr'r')rr(r))rr*r+rrr�_add_identifier�s
zCParser._add_identifiercCs=x6t|j�D]%}|j|�}|dk	r|SqWdS)z8 Is *name* a typedef-name in the current scope?
        NF)�reversedrr()rr*ZscopeZin_scoperrr�_is_type_in_scope�s
zCParser._is_type_in_scopecCs |j||j||��dS)N)r)�_coord)r�msg�line�columnrrrr�szCParser._lex_error_funccCs|j�dS)N)r$)rrrrr�szCParser._lex_on_lbrace_funccCs|j�dS)N)r&)rrrrr�szCParser._lex_on_rbrace_funccCs|j|�}|S)z� Looks up types that were previously defined with
            typedef.
            Passed to the lexer for recognizing identifiers that
            are types.
        )r/)rr*Zis_typerrrr�szCParser._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_token)rrrr�_get_yacc_lookahead_token�sz!CParser._get_yacc_lookahead_tokencCs�|}|}x|jr$|j}qWt|tj�rD||_|S|}x"t|jtj�sn|j}qMW|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_tailrrr�_type_modify_decl�s
	
	zCParser._type_modify_declcCs|}xt|tj�s'|j}q	W|j|_|j|_xU|D]M}t|tj�sGt|�dkr�|j	d|j
�qG||_|SqGW|s�t|jtj�s�|j	d|j
�tjdgd|j
�|_n,tjdd�|D�d|dj
�|_|S)	z- Fixes a declaration. Modifies decl.
        rz Invalid multiple types specifiedzMissing type in declaration�intr+cSs&g|]}|jD]}|�qqSr)�names)�.0�idr*rrr�
<listcomp>Us	z/CParser._fix_decl_name_type.<locals>.<listcomp>r)r6rr7r5�declnamer*�quals�IdentifierType�lenr)r+�FuncDecl)rr8�typenamer5Ztnrrr�_fix_decl_name_type,s.

	
	zCParser._fix_decl_name_typec	Cs?|p$tdgdgdgdg�}||jd|�|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�storager5�functionr)r�insert)rZdeclspecZnewspecZkind�specrrr�_add_declaration_specifierYs
'z"CParser._add_declaration_specifiercCsd|dk}g}|djd�dk	r2n�|dddkr0t|d�dks�t|ddj�d	ks�|j|ddjd�r�d
}x+|dD]}t|d�r�|j}Pq�W|jd|�tjd
|ddjdddddd|ddj�|dd<|dd=n�t	|ddtj
tjtjf�s�|dd}xt	|tj�s�|j
}qjW|jdkr�|ddjd|_|dd=xD|D]<}	|rtjddd|dd|dd|	dd|	dj�}
netjddd|dd|dd|dd|	dd|	jd�d|	jd�d|	dj�}
t	|
j
tj
tjtjf�r�|
}n|j|
|d�}|r�|r�|j|j|j�n|j|j|j�|j|�q�W|S)z� Builds a list of declarations all sharing the given specifiers.
            If typedef_namespace is true, each declared name is added
            to the "typedef namespace", which also includes objects,
            functions, and enum constants.
        ZtypedefrHr�bitsizeNr8r5�r�?r+zInvalid declarationr@rAr*rG�funcspecrI�initr'r'r'r'r'r'r')r(rCr<r/�hasattrr+r)rr7r6�Struct�UnionrBr5r@ZTypedef�DeclrFr,r*r-r#)rrK�decls�typedef_namespaceZ
is_typedefZdeclarationsr+�tZdecls_0_tailr8�declarationZ
fixed_declrrr�_build_declarationsjsl3		

	


	



		zCParser._build_declarationsc	CsY|jd|dtd|dd�gdd�d}tjd|d	|d
|d|j�S)z' Builds a function definition.
        rKrVr8rQNrWTr�param_decls�bodyr+)rZrrZFuncDefr+)rrKr8r[r\rYrrr�_build_function_definition�s	
	z"CParser._build_function_definitioncCs|dkrtjStjSdS)z` Given a token (either STRUCT or UNION), selects the
            appropriate AST class.
        ZstructN)rrSrT)r�tokenrrr�_select_struct_union_class�sz"CParser._select_struct_union_class�left�LOR�LAND�OR�XOR�AND�EQ�NE�GT�GE�LT�LE�RSHIFT�LSHIFT�PLUS�MINUS�TIMES�DIVIDE�MODcCsA|ddkr&tjg�|d<ntj|d�|d<dS)zh translation_unit_or_empty   : translation_unit
                                        | empty
        rNr)rZFileAST)r�prrr�p_translation_unit_or_empty�sz#CParser.p_translation_unit_or_emptycCs|d|d<dS)z4 translation_unit    : external_declaration
        rrNr)rrsrrr�p_translation_unit_1�szCParser.p_translation_unit_1cCs7|ddk	r%|dj|d�|d|d<dS)zE translation_unit    : translation_unit external_declaration
        rNNrr)�extend)rrsrrr�p_translation_unit_2szCParser.p_translation_unit_2cCs|dg|d<dS)z7 external_declaration    : function_definition
        rrNr)rrsrrr�p_external_declaration_1sz CParser.p_external_declaration_1cCs|d|d<dS)z/ external_declaration    : declaration
        rrNr)rrsrrr�p_external_declaration_2sz CParser.p_external_declaration_2cCs|d|d<dS)z0 external_declaration    : pp_directive
        rrNr)rrsrrr�p_external_declaration_3sz CParser.p_external_declaration_3cCsd|d<dS)z( external_declaration    : SEMI
        Nrr)rrsrrr�p_external_declaration_4sz CParser.p_external_declaration_4cCs&|jd|j|jd���dS)z  pp_directive  : PPHASH
        zDirectives not supported yetrN)r)r0�lineno)rrsrrr�p_pp_directive$s	zCParser.p_pp_directivecCs�tdgdgdtjdgd|j|jd���gdg�}|jd|d	|dd
|dd|d
�|d<dS)zR function_definition : declarator declaration_list_opt compound_statement
        rGrHr5r;r+rrIrKr8r[rNr\�rN)rrrBr0r|r])rrsrKrrr�p_function_definition_1-s		

zCParser.p_function_definition_1c
CsB|d}|jd|d|dd|dd|d�|d	<d
S)zi function_definition : declaration_specifiers declarator declaration_list_opt compound_statement
        rrKr8rNr[r~r\�rN)r])rrsrKrrr�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)rrsrrr�p_statementIszCParser.p_statementcCs|d}|ddkr�|d}tjtjtjf}t|�dkr�t|d|�r�tjddd|dd	|d	d
|dd|dddd
dd|dj�g}q|jd|dt	dddd�gdd�}n"|jd|d|ddd�}||d<dS)zE decl_body : declaration_specifiers init_declarator_list_opt
        rrNNr5rr*rArGrHrPrIrQrMr+rKrVr8rWT)
rrSrT�EnumrCr6rUr+rZr)rrsrKZtyZs_u_or_erVrrr�p_decl_body\s.

%	



		
	zCParser.p_decl_bodycCs|d|d<dS)z& declaration : decl_body SEMI
        rrNr)rrsrrr�
p_declaration�szCParser.p_declarationcCs6t|�dkr|dn|d|d|d<dS)zj declaration_list    : declaration
                                | declaration_list declaration
        rNrrN)rC)rrsrrr�p_declaration_list�szCParser.p_declaration_listcCs%|j|d|dd�|d<dS)zM declaration_specifiers  : type_qualifier declaration_specifiers_opt
        rNrrGrN)rL)rrsrrr�p_declaration_specifiers_1�sz"CParser.p_declaration_specifiers_1cCs%|j|d|dd�|d<dS)zM declaration_specifiers  : type_specifier declaration_specifiers_opt
        rNrr5rN)rL)rrsrrr�p_declaration_specifiers_2�sz"CParser.p_declaration_specifiers_2cCs%|j|d|dd�|d<dS)zV declaration_specifiers  : storage_class_specifier declaration_specifiers_opt
        rNrrHrN)rL)rrsrrr�p_declaration_specifiers_3�sz"CParser.p_declaration_specifiers_3cCs%|j|d|dd�|d<dS)zQ declaration_specifiers  : function_specifier declaration_specifiers_opt
        rNrrIrN)rL)rrsrrr�p_declaration_specifiers_4�sz"CParser.p_declaration_specifiers_4cCs|d|d<dS)z� storage_class_specifier : AUTO
                                    | REGISTER
                                    | STATIC
                                    | EXTERN
                                    | TYPEDEF
        rrNr)rrsrrr�p_storage_class_specifier�sz!CParser.p_storage_class_specifiercCs|d|d<dS)z& function_specifier  : INLINE
        rrNr)rrsrrr�p_function_specifier�szCParser.p_function_specifiercCs6tj|dgd|j|jd���|d<dS)a� type_specifier  : VOID
                            | _BOOL
                            | CHAR
                            | SHORT
                            | INT
                            | LONG
                            | FLOAT
                            | DOUBLE
                            | _COMPLEX
                            | SIGNED
                            | UNSIGNED
        rr+rN)rrBr0r|)rrsrrr�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)rrsrrr�p_type_specifier_2�szCParser.p_type_specifier_2cCs|d|d<dS)zo type_qualifier  : CONST
                            | RESTRICT
                            | VOLATILE
        rrNr)rrsrrr�p_type_qualifier�szCParser.p_type_qualifiercCs<t|�dkr'|d|dgn
|dg|d<dS)z� init_declarator_list    : init_declarator
                                    | init_declarator_list COMMA init_declarator
        r�rr~rN)rC)rrsrrr�p_init_declarator_list_1�sz CParser.p_init_declarator_list_1cCs$tddd|d�g|d<dS)z6 init_declarator_list    : EQUALS initializer
        r8NrQrNr)r)rrsrrr�p_init_declarator_list_2�sz CParser.p_init_declarator_list_2cCs$td|ddd�g|d<dS)z7 init_declarator_list    : abstract_declarator
        r8rrQNr)r)rrsrrr�p_init_declarator_list_3�sz CParser.p_init_declarator_list_3cCs=td|ddt|�dkr,|dnd�|d<dS)zb init_declarator : declarator
                            | declarator EQUALS initializer
        r8rrQrNr~Nr)rrC)rrsrrr�p_init_declaratorszCParser.p_init_declaratorcCs%|j|d|dd�|d<dS)zS specifier_qualifier_list    : type_qualifier specifier_qualifier_list_opt
        rNrrGrN)rL)rrsrrr�p_specifier_qualifier_list_1sz$CParser.p_specifier_qualifier_list_1cCs%|j|d|dd�|d<dS)zS specifier_qualifier_list    : type_specifier specifier_qualifier_list_opt
        rNrr5rN)rL)rrsrrr�p_specifier_qualifier_list_2sz$CParser.p_specifier_qualifier_list_2c	CsL|j|d�}|d|dddd|j|jd���|d<dS)z{ struct_or_union_specifier   : struct_or_union ID
                                        | struct_or_union TYPEID
        rr*rNrVNr+r)r_r0r|)rrs�klassrrr�p_struct_or_union_specifier_1s

z%CParser.p_struct_or_union_specifier_1c	CsL|j|d�}|ddd|dd|j|jd���|d<dS)	zd struct_or_union_specifier : struct_or_union brace_open struct_declaration_list brace_close
        rr*NrVr~r+rNr)r_r0r|)rrsr�rrr�p_struct_or_union_specifier_2s

z%CParser.p_struct_or_union_specifier_2c	CsP|j|d�}|d|dd|dd|j|jd���|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*rNrVr�r+rN)r_r0r|)rrsr�rrr�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)rrsrrr�p_struct_or_union0szCParser.p_struct_or_unioncCs6t|�dkr|dn|d|d|d<dS)z� struct_declaration_list     : struct_declaration
                                        | struct_declaration_list struct_declaration
        rNrrN)rC)rrsrrr�p_struct_declaration_list8sz!CParser.p_struct_declaration_listc	Cs�|d}|ddk	r9|jd|d|d�}n�t|d�dkr�|dd}t|tj�rx|}ntj|�}|jd|dtd|�g�}n*|jd|dtddd	d�g�}||d<dS)
zW struct_declaration : specifier_qualifier_list struct_declarator_list_opt SEMI
        rrNNrKrVr5rr8rQ)rZrCr6rZNoderBr)rrsrKrVZnodeZ	decl_typerrr�p_struct_declaration_1>s"
				zCParser.p_struct_declaration_1c	Cs:|jd|ddtd|ddd�g�|d<dS)	zP struct_declaration : specifier_qualifier_list abstract_declarator SEMI
        rKrrVr8rNrQNr)rZr)rrsrrr�p_struct_declaration_2ds
	
zCParser.p_struct_declaration_2cCs<t|�dkr'|d|dgn
|dg|d<dS)z� struct_declarator_list  : struct_declarator
                                    | struct_declarator_list COMMA struct_declarator
        r�rr~rN)rC)rrsrrr�p_struct_declarator_listrsz CParser.p_struct_declarator_listcCsd|dddi|d<dS)z( struct_declarator : declarator
        r8rrMNrr)rrsrrr�p_struct_declarator_1{szCParser.p_struct_declarator_1cCs`t|�dkr3d|dd|di|d<n)dtjddd�d|di|d<dS)z� struct_declarator   : declarator COLON constant_expression
                                | COLON constant_expression
        r~r8rrMrNrN)rCrr7)rrsrrr�p_struct_declarator_2�s!zCParser.p_struct_declarator_2cCs3tj|dd|j|jd���|d<dS)zM enum_specifier  : ENUM ID
                            | ENUM TYPEID
        rNNrr)rr�r0r|)rrsrrr�p_enum_specifier_1�szCParser.p_enum_specifier_1cCs3tjd|d|j|jd���|d<dS)zG enum_specifier  : ENUM brace_open enumerator_list brace_close
        Nr~rr)rr�r0r|)rrsrrr�p_enum_specifier_2�szCParser.p_enum_specifier_2cCs7tj|d|d|j|jd���|d<dS)z� enum_specifier  : ENUM ID brace_open enumerator_list brace_close
                            | ENUM TYPEID brace_open enumerator_list brace_close
        rNr�rrN)rr�r0r|)rrsrrr�p_enum_specifier_3�szCParser.p_enum_specifier_3cCs�t|�dkr9tj|dg|dj�|d<nIt|�dkr\|d|d<n&|djj|d�|d|d<dS)z� enumerator_list : enumerator
                            | enumerator_list COMMA
                            | enumerator_list COMMA enumerator
        rNrrr~N)rCrZEnumeratorListr+Zenumeratorsr#)rrsrrr�p_enumerator_list�s'zCParser.p_enumerator_listcCs�t|�dkr@tj|dd|j|jd���}n/tj|d|d|j|jd���}|j|j|j�||d<dS)zR enumerator  : ID
                        | ID EQUALS constant_expression
        rNrNr~r)rCrZ
Enumeratorr0r|r-r*r+)rrsZ
enumeratorrrr�p_enumerator�s
zCParser.p_enumeratorcCs|d|d<dS)z) declarator  : direct_declarator
        rrNr)rrsrrr�p_declarator_1�szCParser.p_declarator_1cCs"|j|d|d�|d<dS)z1 declarator  : pointer direct_declarator
        rNrrN)r:)rrsrrr�p_declarator_2�szCParser.p_declarator_2cCsXtjd|dddddd|j|jd���}|j||d�|d<dS)	z& declarator  : pointer TYPEID
        r@rNr5NrAr+rr)rr7r0r|r:)rrsr8rrr�p_declarator_3�s	
zCParser.p_declarator_3cCsBtjd|dddddd|j|jd���|d<dS)z" direct_declarator   : ID
        r@rr5NrAr+r)rr7r0r|)rrsrrr�p_direct_declarator_1�s
	
zCParser.p_direct_declarator_1cCs|d|d<dS)z8 direct_declarator   : LPAREN declarator RPAREN
        rNrNr)rrsrrr�p_direct_declarator_2�szCParser.p_direct_declarator_2c
Cs�t|�dkr|dngp%g}tjdddt|�dkrS|dn|dd|d|d	j�}|jd
|d	d|�|d<dS)
zu direct_declarator   : direct_declarator LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET
        �r~r5N�dimr��	dim_qualsr+rr8r9r)rCr�	ArrayDeclr+r:)rrsrA�arrrrr�p_direct_declarator_3�s(	&zCParser.p_direct_declarator_3c
Cs�dd�|d|dgD�}dd�|D�}tjddd|d	d
|d|dj�}|jd
|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)r6�list)r=�itemrrrr?�s	z1CParser.p_direct_declarator_4.<locals>.<listcomp>r~r�cSs/g|]%}|D]}|dk	r|�qqS)Nr)r=ZsublistrGrrrr?�s	
r5Nr�r�r�r+rr8r9r)rr�r+r:)rrsZlisted_qualsr�r�rrr�p_direct_declarator_4�s		
zCParser.p_direct_declarator_4c
Cs�tjdddtj|d|j|jd���d|ddkrQ|dngd|dj�}|jd	|dd
|�|d<dS)za direct_declarator   : direct_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET
        r5Nr�r�r�r~r+rr8r9r)rr��IDr0r|r+r:)rrsr�rrr�p_direct_declarator_5s	( zCParser.p_direct_declarator_5cCs�tjd|dddd|dj�}|j�jdkr�|jdk	r�x=|jjD]/}t|tj�rsP|j	|j
|j�qZW|jd|dd	|�|d
<dS)z� direct_declarator   : direct_declarator LPAREN parameter_type_list RPAREN
                                | direct_declarator LPAREN identifier_list_opt RPAREN
        �argsr~r5Nr+r�LBRACEr8r9r)rrDr+r4r5r��paramsr6�
EllipsisParamr-r*r:)rrs�funcZparamrrr�p_direct_declarator_6s	

zCParser.p_direct_declarator_6cCs�|j|jd��}tjd|dp.gddd|�}t|�dkr�|d}x|jdk	rz|j}q_W||_|d|d<n
||d<dS)	zm pointer : TIMES type_qualifier_list_opt
                    | TIMES type_qualifier_list_opt pointer
        rrArNr5Nr+r~r)r0r|rZPtrDeclrCr5)rrsr+Znested_typeZ	tail_typerrr�	p_pointer(s(

	zCParser.p_pointercCs<t|�dkr|dgn|d|dg|d<dS)zs type_qualifier_list : type_qualifier
                                | type_qualifier_list type_qualifier
        rNrrN)rC)rrsrrr�p_type_qualifier_listFszCParser.p_type_qualifier_listcCsSt|�dkrA|djjtj|j|jd����|d|d<dS)zn parameter_type_list : parameter_list
                                | parameter_list COMMA ELLIPSIS
        rNrr~rN)rCr�r#rr�r0r|)rrsrrr�p_parameter_type_listLs/zCParser.p_parameter_type_listcCsct|�dkr9tj|dg|dj�|d<n&|djj|d�|d|d<dS)zz parameter_list  : parameter_declaration
                            | parameter_list COMMA parameter_declaration
        rNrrr~N)rCr�	ParamListr+r�r#)rrsrrr�p_parameter_listUs'zCParser.p_parameter_listcCsy|d}|dsEtjdgd|j|jd���g|d<|jd|dtd|d�g�d	|d	<d
S)zE parameter_declaration   : declaration_specifiers declarator
        rr5r;r+rKrVr8rNrN)rrBr0r|rZr)rrsrKrrr�p_parameter_declaration_1_s

"	z!CParser.p_parameter_declaration_1cCsH|d}|dsEtjdgd|j|jd���g|d<t|d�dkr�t|ddj�dkr�|j|ddjd�r�|jd|dtd|d	d
d�g�d}notj	dd
d|dd|d	ptj
ddd�d|j|jd	���}|d}|j||�}||d<dS)zR parameter_declaration   : declaration_specifiers abstract_declarator_opt
        rr5r;r+rrKrVr8rNrQNr*rrArGr'r')rrBr0r|rCr<r/rZr�Typenamer7rF)rrsrKr8rErrr�p_parameter_declaration_2js"

"3	&	

z!CParser.p_parameter_declaration_2cCsct|�dkr9tj|dg|dj�|d<n&|djj|d�|d|d<dS)ze identifier_list : identifier
                            | identifier_list COMMA identifier
        rNrrr~N)rCrr�r+r�r#)rrsrrr�p_identifier_list�s'zCParser.p_identifier_listcCs|d|d<dS)z- initializer : assignment_expression
        rrNr)rrsrrr�p_initializer_1�szCParser.p_initializer_1cCsM|ddkr;tjg|j|jd���|d<n|d|d<dS)z� initializer : brace_open initializer_list_opt brace_close
                        | brace_open initializer_list COMMA brace_close
        rNNrr)r�InitListr0r|)rrsrrr�p_initializer_2�s+zCParser.p_initializer_2cCs�t|�dkri|ddkr,|dntj|d|d�}tj|g|dj�|d<nV|ddkr�|dntj|d|d�}|djj|�|d|d<dS)z� initializer_list    : designation_opt initializer
                                | initializer_list COMMA designation_opt initializer
        r~rNrNrr�)rCrZNamedInitializerr�r+�exprsr#)rrsrQrrr�p_initializer_list�s4#4zCParser.p_initializer_listcCs|d|d<dS)z. designation : designator_list EQUALS
        rrNr)rrsrrr�
p_designation�szCParser.p_designationcCs<t|�dkr|dgn|d|dg|d<dS)z_ designator_list : designator
                            | designator_list designator
        rNrrN)rC)rrsrrr�p_designator_list�szCParser.p_designator_listcCs|d|d<dS)zi designator  : LBRACKET constant_expression RBRACKET
                        | PERIOD identifier
        rNrNr)rrsrrr�p_designator�szCParser.p_designatorcCsytjddd|ddd|dp9tjddd�d	|j|jd���}|j||dd�|d
<dS)zH type_name   : specifier_qualifier_list abstract_declarator_opt
        r*rrArrGr5rNNr+r)rr�r7r0r|rF)rrsrErrr�p_type_name�s		zCParser.p_type_namecCs9tjddd�}|jd|d|d�|d<dS)z+ abstract_declarator     : pointer
        Nr8r9rr)rr7r:)rrsZ	dummytyperrr�p_abstract_declarator_1�s	zCParser.p_abstract_declarator_1cCs"|j|d|d�|d<dS)zF abstract_declarator     : pointer direct_abstract_declarator
        rNrrN)r:)rrsrrr�p_abstract_declarator_2�szCParser.p_abstract_declarator_2cCs|d|d<dS)z> abstract_declarator     : direct_abstract_declarator
        rrNr)rrsrrr�p_abstract_declarator_3�szCParser.p_abstract_declarator_3cCs|d|d<dS)zA direct_abstract_declarator  : LPAREN abstract_declarator RPAREN rNrNr)rrsrrr�p_direct_abstract_declarator_1�sz&CParser.p_direct_abstract_declarator_1c
CsStjddd|ddgd|dj�}|jd|dd	|�|d
<dS)zn direct_abstract_declarator  : direct_abstract_declarator LBRACKET assignment_expression_opt RBRACKET
        r5Nr�r~r�r+rr8r9r)rr�r+r:)rrsr�rrr�p_direct_abstract_declarator_2�s	
z&CParser.p_direct_abstract_declarator_2cCsQtjdtjddd�d|ddgd|j|jd���|d<dS)	zS direct_abstract_declarator  : LBRACKET assignment_expression_opt RBRACKET
        r5Nr�rNr�r+rr)rr�r7r0r|)rrsrrr�p_direct_abstract_declarator_3�s
	
z&CParser.p_direct_abstract_declarator_3c
Csqtjdddtj|d|j|jd���dgd|dj�}|jd|dd	|�|d
<dS)zZ direct_abstract_declarator  : direct_abstract_declarator LBRACKET TIMES RBRACKET
        r5Nr�r~r�r+rr8r9r)rr�r�r0r|r+r:)rrsr�rrr�p_direct_abstract_declarator_4s	(z&CParser.p_direct_abstract_declarator_4cCsotjdtjddd�dtj|d|j|jd���dgd|j|jd���|d<dS)	z? direct_abstract_declarator  : LBRACKET TIMES RBRACKET
        r5Nr�r~r�r+rr)rr�r7r�r0r|)rrsrrr�p_direct_abstract_declarator_5s
	(z&CParser.p_direct_abstract_declarator_5cCsMtjd|dddd|dj�}|jd|dd|�|d	<dS)
zh direct_abstract_declarator  : direct_abstract_declarator LPAREN parameter_type_list_opt RPAREN
        r�r~r5Nr+rr8r9r)rrDr+r:)rrsr�rrr�p_direct_abstract_declarator_6s
	
z&CParser.p_direct_abstract_declarator_6c	CsKtjd|ddtjddd�d|j|jd���|d<dS)zM direct_abstract_declarator  : LPAREN parameter_type_list_opt RPAREN
        r�rNr5Nr+rr)rrDr7r0r|)rrsrrr�p_direct_abstract_declarator_7s	
z&CParser.p_direct_abstract_declarator_7cCs2t|dt�r|dn
|dg|d<dS)zG block_item  : declaration
                        | statement
        rrN)r6r�)rrsrrr�p_block_item*szCParser.p_block_itemcCsIt|�dks%|ddgkr/|dn|d|d|d<dS)z_ block_item_list : block_item
                            | block_item_list block_item
        rNNrr)rC)rrsrrr�p_block_item_list2szCParser.p_block_item_listcCs6tjd|dd|j|jd���|d<dS)zA compound_statement : brace_open block_item_list_opt brace_close Zblock_itemsrNr+rrN)rZCompoundr0r|)rrsrrr�p_compound_statement_19s	
zCParser.p_compound_statement_1cCs7tj|d|d|j|jd���|d<dS)z( labeled_statement : ID COLON statement rr~rN)rZLabelr0r|)rrsrrr�p_labeled_statement_1?szCParser.p_labeled_statement_1cCs:tj|d|dg|j|jd���|d<dS)z> labeled_statement : CASE constant_expression COLON statement rNr�rrN)rZCaser0r|)rrsrrr�p_labeled_statement_2CszCParser.p_labeled_statement_2cCs3tj|dg|j|jd���|d<dS)z- labeled_statement : DEFAULT COLON statement r~rrN)rZDefaultr0r|)rrsrrr�p_labeled_statement_3GszCParser.p_labeled_statement_3cCs:tj|d|dd|j|jd���|d<dS)z= selection_statement : IF LPAREN expression RPAREN statement r~r�Nrr)r�Ifr0r|)rrsrrr�p_selection_statement_1KszCParser.p_selection_statement_1cCs>tj|d|d|d|j|jd���|d<dS)zL selection_statement : IF LPAREN expression RPAREN statement ELSE statement r~r��rrN)rr�r0r|)rrsrrr�p_selection_statement_2OszCParser.p_selection_statement_2cCs=ttj|d|d|j|jd����|d<dS)zA selection_statement : SWITCH LPAREN expression RPAREN statement r~r�rrN)r	rZSwitchr0r|)rrsrrr�p_selection_statement_3SszCParser.p_selection_statement_3cCs7tj|d|d|j|jd���|d<dS)z@ iteration_statement : WHILE LPAREN expression RPAREN statement r~r�rrN)rZWhiler0r|)rrsrrr�p_iteration_statement_1XszCParser.p_iteration_statement_1cCs7tj|d|d|j|jd���|d<dS)zH iteration_statement : DO statement WHILE LPAREN expression RPAREN SEMI r�rNrrN)rZDoWhiler0r|)rrsrrr�p_iteration_statement_2\szCParser.p_iteration_statement_2cCsEtj|d|d|d|d|j|jd���|d<dS)zj iteration_statement : FOR LPAREN expression_opt SEMI expression_opt SEMI expression_opt RPAREN statement r~r�r��	rrN)r�Forr0r|)rrsrrr�p_iteration_statement_3`szCParser.p_iteration_statement_3cCsctjtj|d|j|jd���|d|d|d|j|jd���|d<dS)zb iteration_statement : FOR LPAREN declaration expression_opt SEMI expression_opt RPAREN statement r~rr���rN)rr�ZDeclListr0r|)rrsrrr�p_iteration_statement_4ds+zCParser.p_iteration_statement_4cCs0tj|d|j|jd���|d<dS)z  jump_statement  : GOTO ID SEMI rNrrN)rZGotor0r|)rrsrrr�p_jump_statement_1iszCParser.p_jump_statement_1cCs)tj|j|jd���|d<dS)z jump_statement  : BREAK SEMI rrN)rZBreakr0r|)rrsrrr�p_jump_statement_2mszCParser.p_jump_statement_2cCs)tj|j|jd���|d<dS)z! jump_statement  : CONTINUE SEMI rrN)rZContinuer0r|)rrsrrr�p_jump_statement_3qszCParser.p_jump_statement_3cCsHtjt|�dkr"|dnd|j|jd���|d<dS)z\ jump_statement  : RETURN expression SEMI
                            | RETURN SEMI
        r�rNNrr)rZReturnrCr0r|)rrsrrr�p_jump_statement_4uszCParser.p_jump_statement_4cCsJ|ddkr8tj|j|jd���|d<n|d|d<dS)z, expression_statement : expression_opt SEMI rNr)rZEmptyStatementr0r|)rrsrrr�p_expression_statement{s(zCParser.p_expression_statementcCs�t|�dkr#|d|d<n`t|dtj�s]tj|dg|dj�|d<|djj|d�|d|d<dS)zn expression  : assignment_expression
                        | expression COMMA assignment_expression
        rNrrr~N)rCr6r�ExprListr+r�r#)rrsrrr�p_expression�s$zCParser.p_expressioncCs6tj|dgd|j|jd���|d<dS)z typedef_name : TYPEID rr+rN)rrBr0r|)rrsrrr�p_typedef_name�szCParser.p_typedef_namecCsVt|�dkr#|d|d<n/tj|d|d|d|dj�|d<dS)z� assignment_expression   : conditional_expression
                                    | unary_expression assignment_operator assignment_expression
        rNrrr~N)rCrZ
Assignmentr+)rrsrrr�p_assignment_expression�szCParser.p_assignment_expressioncCs|d|d<dS)a� assignment_operator : EQUALS
                                | XOREQUAL
                                | TIMESEQUAL
                                | DIVEQUAL
                                | MODEQUAL
                                | PLUSEQUAL
                                | MINUSEQUAL
                                | LSHIFTEQUAL
                                | RSHIFTEQUAL
                                | ANDEQUAL
                                | OREQUAL
        rrNr)rrsrrr�p_assignment_operator�s
zCParser.p_assignment_operatorcCs|d|d<dS)z. constant_expression : conditional_expression rrNr)rrsrrr�p_constant_expression�szCParser.p_constant_expressioncCsVt|�dkr#|d|d<n/tj|d|d|d|dj�|d<dS)z� conditional_expression  : binary_expression
                                    | binary_expression CONDOP expression COLON conditional_expression
        rNrrr~r�N)rCrZ	TernaryOpr+)rrsrrr�p_conditional_expression�sz CParser.p_conditional_expressioncCsVt|�dkr#|d|d<n/tj|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
        rNrrr~N)rCrZBinaryOpr+)rrsrrr�p_binary_expression�szCParser.p_binary_expressioncCs|d|d<dS)z$ cast_expression : unary_expression rrNr)rrsrrr�p_cast_expression_1�szCParser.p_cast_expression_1cCs7tj|d|d|j|jd���|d<dS)z; cast_expression : LPAREN type_name RPAREN cast_expression rNr�rrN)rZCastr0r|)rrsrrr�p_cast_expression_2�szCParser.p_cast_expression_2cCs|d|d<dS)z* unary_expression    : postfix_expression rrNr)rrsrrr�p_unary_expression_1�szCParser.p_unary_expression_1cCs,tj|d|d|dj�|d<dS)z� unary_expression    : PLUSPLUS unary_expression
                                | MINUSMINUS unary_expression
                                | unary_operator cast_expression
        rrNrN)r�UnaryOpr+)rrsrrr�p_unary_expression_2�szCParser.p_unary_expression_2cCsStj|dt|�dkr)|dn|d|j|jd���|d<dS)zx unary_expression    : SIZEOF unary_expression
                                | SIZEOF LPAREN type_name RPAREN
        rr~rNrN)rr�rCr0r|)rrsrrr�p_unary_expression_3�s#zCParser.p_unary_expression_3cCs|d|d<dS)z� unary_operator  : AND
                            | TIMES
                            | PLUS
                            | MINUS
                            | NOT
                            | LNOT
        rrNr)rrsrrr�p_unary_operator�szCParser.p_unary_operatorcCs|d|d<dS)z* postfix_expression  : primary_expression rrNr)rrsrrr�p_postfix_expression_1�szCParser.p_postfix_expression_1cCs,tj|d|d|dj�|d<dS)zG postfix_expression  : postfix_expression LBRACKET expression RBRACKET rr~rN)rZArrayRefr+)rrsrrr�p_postfix_expression_2szCParser.p_postfix_expression_2cCsDtj|dt|�dkr)|dnd|dj�|d<dS)z� postfix_expression  : postfix_expression LPAREN argument_expression_list RPAREN
                                | postfix_expression LPAREN RPAREN
        rr�r~Nr)r�FuncCallrCr+)rrsrrr�p_postfix_expression_3szCParser.p_postfix_expression_3cCsWtj|d|j|jd���}tj|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~rrNrN)rr�r0r|Z	StructRefr+)rrsZfieldrrr�p_postfix_expression_4s(zCParser.p_postfix_expression_4cCs0tjd|d|d|dj�|d<dS)z{ postfix_expression  : postfix_expression PLUSPLUS
                                | postfix_expression MINUSMINUS
        rsrNrrN)rr�r+)rrsrrr�p_postfix_expression_5szCParser.p_postfix_expression_5cCs"tj|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
        rNr�rN)rZCompoundLiteral)rrsrrr�p_postfix_expression_6szCParser.p_postfix_expression_6cCs|d|d<dS)z" primary_expression  : identifier rrNr)rrsrrr�p_primary_expression_1 szCParser.p_primary_expression_1cCs|d|d<dS)z  primary_expression  : constant rrNr)rrsrrr�p_primary_expression_2$szCParser.p_primary_expression_2cCs|d|d<dS)zp primary_expression  : unified_string_literal
                                | unified_wstring_literal
        rrNr)rrsrrr�p_primary_expression_3(szCParser.p_primary_expression_3cCs|d|d<dS)z0 primary_expression  : LPAREN expression RPAREN rNrNr)rrsrrr�p_primary_expression_4.szCParser.p_primary_expression_4cCs_|j|jd��}tjtj|d|�tj|d|dg|�|�|d<dS)zQ primary_expression  : OFFSETOF LPAREN type_name COMMA identifier RPAREN
        rr~r�rN)r0r|rrr�r�)rrsr+rrr�p_primary_expression_52szCParser.p_primary_expression_5cCsct|�dkr9tj|dg|dj�|d<n&|djj|d�|d|d<dS)z� argument_expression_list    : assignment_expression
                                        | argument_expression_list COMMA assignment_expression
        rNrrr~N)rCrr�r+r�r#)rrsrrr�p_argument_expression_list:s'z"CParser.p_argument_expression_listcCs0tj|d|j|jd���|d<dS)z identifier  : ID rrN)rr�r0r|)rrsrrr�p_identifierDszCParser.p_identifiercCs3tjd|d|j|jd���|d<dS)z� constant    : INT_CONST_DEC
                        | INT_CONST_OCT
                        | INT_CONST_HEX
                        | INT_CONST_BIN
        r;rrN)r�Constantr0r|)rrsrrr�p_constant_1HszCParser.p_constant_1cCs3tjd|d|j|jd���|d<dS)zM constant    : FLOAT_CONST
                        | HEX_FLOAT_CONST
        �floatrrN)rr
r0r|)rrsrrr�p_constant_2QszCParser.p_constant_2cCs3tjd|d|j|jd���|d<dS)zH constant    : CHAR_CONST
                        | WCHAR_CONST
        �charrrN)rr
r0r|)rrsrrr�p_constant_3XszCParser.p_constant_3cCs�t|�dkrDtjd|d|j|jd���|d<n>|djdd�|ddd�|d_|d|d<dS)z~ unified_string_literal  : STRING_LITERAL
                                    | unified_string_literal STRING_LITERAL
        rN�stringrrNr')rCrr
r0r|�value)rrsrrr�p_unified_string_literalds
,0z CParser.p_unified_string_literalcCs�t|�dkrDtjd|d|j|jd���|d<nD|djj�dd�|ddd�|d_|d|d<dS)z� unified_wstring_literal : WSTRING_LITERAL
                                    | unified_wstring_literal WSTRING_LITERAL
        rNrrrNr')rCrr
r0r|r�rstrip)rrsrrr�p_unified_wstring_literalos
,6z!CParser.p_unified_wstring_literalcCs|d|d<dS)z  brace_open  :   LBRACE
        rrNr)rrsrrr�p_brace_openzszCParser.p_brace_opencCs|d|d<dS)z  brace_close :   RBRACE
        rrNr)rrsrrr�
p_brace_closeszCParser.p_brace_closecCsd|d<dS)zempty : Nrr)rrsrrr�p_empty�szCParser.p_emptycCsU|rA|jd|j|jd|jd|jj|���n|jdd�dS)Nz
before: %sr|r3zAt end of inputr)r)rr0r|rZfind_tok_column)rrsrrr�p_error�s
zCParser.p_errorN�r`ra�r`rb�r`rc�r`rd�r`re�r`rfrg�r`rhrirjrk�r`rlrm�r`rnro�r`rprqrr)
rrrrr r!r"r#r$r%)��__name__�
__module__�__qualname__rr!r$r&r,r-r/rrrrr4r:rFrLrZr]r_Z
precedencertrurwrxryrzr{r}rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�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rrrrrrrrrrrrrr
sFc	

	)7-Y
		;		
	
&		
			

	
		

		
	
	r
�__main__)�reZplyrrrZc_lexerrZ	plyparserrrrZast_transformsr	r
r&�pprintZtime�sysrrrr�<module>	s�������