gf~ddlmZddlmZddlmZddlmZmZm Z m Z ddl m Z m Z e GddeZdS) )yacc)c_ast)CLexer) PLYParser ParseError parameterizedtemplate)fix_switch_casesfix_atomic_specifierscLeZdZdedddddfdZddZdZd Zd Zd Z d Z d Z dZ dZ dZdZdZdZddZddZdZdZdZdZdZdZdZdZdZdZd Zd!Zd"Z d#Z!d$Z"d%Z#d&Z$d'Z%d(Z&d)Z'd*Z(d+Z)d,Z*d-Z+d.Z,d/Z-d0Z.d1Z/d2Z0d3Z1d4Z2d5Z3d6Z4d7Z5d8Z6d9Z7d:Z8d;Z9d<Z:d=Z;d>ZdAZ?dBZ@dCZAdDZBdEZCdFZDdGZEdHZFdIZGdJZHdKZIdLZJdMZKdNZLdOZMdPZNdQZOdRZPdSZQdTZRdUZSdVZTdWZUdXZVeWdYdZd[d\ZXeWdYdZd[d]ZYeWdYdZd[d^ZZeWdYdZd_Z[eWdYdZd[d`Z\eWdYdZd[daZ]eWdYdZd[dbZ^eWdYdZd[dcZ_ddZ`deZadfZbdgZcdhZddiZedjZfdkZgdlZhdmZidnZjdoZkdpZldqZmdrZndsZodtZpduZqdvZrdwZsdxZtdyZudzZvd{Zwd|Zxd}Zyd~ZzdZ{dZ|dZ}dZ~dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdS)CParserTzpycparser.lextabzpycparser.yacctabFcb||j|j|j|j|_|j||||jj|_gd}|D]} || tj|d|||||_ tg|_ 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. 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_funcon_lbrace_funcon_rbrace_functype_lookup_func)optimizelextab outputdir)abstract_declaratorassignment_expressiondeclaration_listdeclaration_specifiers_no_type designation expressionidentifier_listinit_declarator_listid_init_declarator_listinitializer_listparameter_type_listblock_item_listtype_qualifier_liststruct_declarator_listtranslation_unit_or_empty)modulestartdebugr tabmodulerN) _lex_error_func_lex_on_lbrace_func_lex_on_rbrace_func_lex_type_lookup_funcclexbuildtokens_create_opt_rulercparserdict _scope_stack_last_yielded_token) self lex_optimizelexerr yacc_optimizeyacctab yacc_debug taboutputdirrules_with_optrules r/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/pycparser/c_parser.py__init__zCParser.__init__stE+33!7 999 !"  $ $ $i&    "# ( (D  ! !$ ' ' ' 'y-"" $$$ "VVH$(   c||j_|jtg|_d|_|j||j|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)inputr8r()r.filename reset_linenor3r4r5r2parse)r6textrDr(s r?rFz CParser.parsesb&     !VVH#' |!!i" rAcR|jtdSN)r4appendr3r6s r? _push_scopezCParser._push_scopes#   (((((rAclt|jdksJ|jdS)Nr)lenr4poprKs r? _pop_scopezCParser._pop_scopes94$%%)))) rAc|jd|ds|d|z|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 scopeNr4get _parse_errorr6namecoords r?_add_typedef_namezCParser._add_typedef_namesf $((t44 /    "&'(- / / /'+"d###rAc|jd|dr|d|z|d|jd|<dS)ze Add a new object, function, or enum member name (ie an ID) to the current scope rRFz;Non-typedef %r previously declared as typedef in this scopeNrSrVs r?_add_identifierzCParser._add_identifiersf  R $ $T5 1 1 /    "&'(- / / /',"d###rAcjt|jD]}||}||cSdS)z8 Is *name* a typedef-name in the current scope? NF)reversedr4rT)r6rWscopein_scopes r?_is_type_in_scopezCParser._is_type_in_scopesEd/00 5 5EyyH#H___#urAcZ|||||dSrI)rU_coord)r6msglinecolumns r?r*zCParser._lex_error_funcs, #t{{48899999rAc.|dSrI)rLrKs r?r+zCParser._lex_on_lbrace_funcs rAc.|dSrI)rPrKs r?r,zCParser._lex_on_rbrace_funcs rAc0||}|S)z Looks up types that were previously defined with typedef. Passed to the lexer for recognizing identifiers that are types. )r`)r6rWis_types r?r-zCParser._lex_type_lookup_funcs ((..rAc|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. )r. last_tokenrKs r?_get_yacc_lookahead_tokenz!CParser._get_yacc_lookahead_tokens y##rAc2|}|}|jr|j}|jt|tjr ||_|S|}t|jtjs&|j}t|jtj&|j|_||_|S)z Tacks a type modifier on a declarator, and returns the modified declarator. Note: the declarator and modifier may be modified )type isinstancerTypeDecl)r6declmodifier modifier_head modifier_tail decl_tails r?_type_modify_declzCParser._type_modify_decls!    /).M  / dEN + + !%M O I @@ +%N !@@ +"+M *INKrAc|}t|tjs!|j}t|tj!|j|_|jdd|_|D]V}t|tjs:t|dkr| d|j K||_|cSW|s\t|jtj s| d|j tjdg|j |_n0tjd|D|dj |_|S) z- Fixes a declaration. Modifies decl. Nrz Invalid multiple types specifiedzMissing type in declarationintrXc&g|]}|jD]}|S)names).0idrWs r? z/CParser._fix_decl_name_type..Ss'>>>"RX>>T>>>>rA) rorrprndeclnamerWqualsIdentifierTyperNrUrXFuncDecl)r6rqtypenamerntns r?_fix_decl_name_typezCParser._fix_decl_name_type+ss T5>22 9DT5>22 M Z]   Bb%"677 x==1$$%%:BHFFFF!#DIKKK   )di88 C!!5tzCCC,G*&&&DII,>>>>>qk')))DI rAc|ptggggg}|r|||n||d||S)a Declaration specifiers are represented by a dictionary with the entries: * qual: a list of type qualifiers * storage: a list of storage type qualifiers * type: a list of type specifiers * function: a list of function specifiers * 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. )qualstoragernfunction alignmentr)r3rJinsert)r6declspecnewspeckindrJspecs r?_add_declaration_specifierz"CParser._add_declaration_specifierWsd X4R"rUWXXX  * J  g & & & & J  a ) ) ) rAc d|dv}g}|ddn|ddt|ddksPt|dd jd ks,||dd jds> 1+0 !u~>> 1$,(,V R(8(>q(A %L$% ,% ,D<+++ .#mv, Ofv,, ... $jv,{+ O!*-f&)) HHY//v,, . . . +*J ek(-*++ Q) !55k4<PP ! LL**:?J|dkr tjStjS)z` Given a token (either STRUCT or UNION), selects the appropriate AST class. struct)rrr)r6tokens r?_select_struct_union_classz"CParser._select_struct_union_classs H  < ; rA) )leftLOR)rLAND)rOR)rXOR)rAND)rEQNE)rGTGELTLE)rRSHIFTLSHIFT)rPLUSMINUS)rTIMESDIVIDEMODc|dtjg|d<dStj|d|d<dS)zh translation_unit_or_empty : translation_unit | empty rNr)rFileASTr6ps r?p_translation_unit_or_emptyz#CParser.p_translation_unit_or_emptys? Q4<=$$AaDDD=1&&AaDDDrAc|d|d<dS)z4 translation_unit : external_declaration rrNr{rs r?p_translation_unit_1zCParser.p_translation_unit_1t!rAc^|d|d|d|d<dS)zE translation_unit : translation_unit external_declaration rrrN)extendrs r?p_translation_unit_2zCParser.p_translation_unit_2 s/ ! AaDt!rAc|dg|d<dS)z7 external_declaration : function_definition rrNr{rs r?p_external_declaration_1z CParser.p_external_declaration_1!v!rAc|d|d<dS)z/ external_declaration : declaration rrNr{rs r?p_external_declaration_2z CParser.p_external_declaration_2t!rAc|dg|d<dS)zi external_declaration : pp_directive | pppragma_directive rrNr{rs r?p_external_declaration_3z CParser.p_external_declaration_3s!v!rAcg|d<dS)z( external_declaration : SEMI rNr{rs r?p_external_declaration_4z CParser.p_external_declaration_4%s!rAc|d|d<dS)z1 external_declaration : static_assert rrNr{rs r?p_external_declaration_5z CParser.p_external_declaration_5*rrAc t|dkr6tj|dd||dg|d<dStj|d|d||dg|d<dS)z static_assert : _STATIC_ASSERT LPAREN constant_expression COMMA unified_string_literal RPAREN | _STATIC_ASSERT LPAREN constant_expression RPAREN Nrr)rNr StaticAssert _token_coordrs r?p_static_assert_declarationz#CParser.p_static_assert_declaration/s} q66Q;;&qtT43D3DQ3J3JKKLAaDDD&qtQqT43D3DQ3J3JKKLAaDDDrAcZ|d||ddS)z pp_directive : PPHASH zDirectives not supported yetrN)rUrrs r?p_pp_directivezCParser.p_pp_directive8s< 8++Aq11 3 3 3 3 3rAct|dkr4tj|d||d|d<dStjd||d|d<dS)zg pppragma_directive : PPPRAGMA | PPPRAGMA PPPRAGMASTR rrrrrN)rNrPragmarrs r?p_pppragma_directivezCParser.p_pppragma_directive>si q66Q;;<!d&7&71&=&=>>AaDDD<D$5$5a$;$;<->q!-D-DFFFG ..1!1 /!rAcr|d}|||d|d|d|d<dS)zl function_definition : declaration_specifiers id_declarator declaration_list_opt compound_statement rrrrrN)rrs r?p_function_definition_2zCParser.p_function_definition_2[sGt..1!1 /!rAc|d|d<dS)a_ statement : labeled_statement | expression_statement | compound_statement | selection_statement | iteration_statement | jump_statement | pppragma_directive | static_assert rrNr{rs r? p_statementzCParser.p_statementjst!rAct|dtjrPt|dkr=tj|d|dg||d|d<dS|d|d<dS)zx pragmacomp_or_statement : pppragma_directive statement | statement rrr block_itemsrXrN)rorrrNCompoundrrs r?p_pragmacomp_or_statementz!CParser.p_pragmacomp_or_statements} adEL ) ) c!ffkk>qT1Q4L''1--///AaDDDQ4AaDDDrAc |d}|d|d}tjtjtjf}t |dkr^t |d|rHtjd|d|d|d|d |ddd|dj g}nG||tdd gd }n|||dd }||d<dS)z decl_body : declaration_specifiers init_declarator_list_opt | declaration_specifiers_no_type id_init_declarator_list_opt rrNrnrrrrrrrTr) rrrrrNrorrXrr3)r6rrtys_u_or_ers r? p_decl_bodyzCParser.p_decl_bodyst Q4< fB ek5:>H2ww!|| 2a5( ; ;|v,{+ O!*-A Q%+ ' ' ' ("00T5556&*1,, ,,d"&-((E !rAc|d|d<dS)z& declaration : decl_body SEMI rrNr{rs r? p_declarationzCParser.p_declarationrrAcdt|dkr|dn|d|dz|d<dS)zj declaration_list : declaration | declaration_list declaration rrrNrNrs r?p_declaration_listzCParser.p_declaration_lists31vv{{qtt!qt !rAcR||d|dd|d<dS)z] declaration_specifiers_no_type : type_qualifier declaration_specifiers_no_type_opt rrrrNrrs r?"p_declaration_specifiers_no_type_1z*CParser.p_declaration_specifiers_no_type_1+..qtQqT6BB!rAcR||d|dd|d<dS)zf declaration_specifiers_no_type : storage_class_specifier declaration_specifiers_no_type_opt rrrrNrrs r?"p_declaration_specifiers_no_type_2z*CParser.p_declaration_specifiers_no_type_2 s+..qtQqT9EE!rAcR||d|dd|d<dS)za declaration_specifiers_no_type : function_specifier declaration_specifiers_no_type_opt rrrrNrrs r?"p_declaration_specifiers_no_type_3z*CParser.p_declaration_specifiers_no_type_3s+..qtQqT:FF!rAcR||d|dd|d<dS)z_ declaration_specifiers_no_type : atomic_specifier declaration_specifiers_no_type_opt rrrnrNrrs r?"p_declaration_specifiers_no_type_4z*CParser.p_declaration_specifiers_no_type_4rrAcR||d|dd|d<dS)zb declaration_specifiers_no_type : alignment_specifier declaration_specifiers_no_type_opt rrrrNrrs r?"p_declaration_specifiers_no_type_5z*CParser.p_declaration_specifiers_no_type_5+..qtQqT;GG!rAcV||d|ddd|d<dS)zI declaration_specifiers : declaration_specifiers type_qualifier rrrTrJrNrrs r?p_declaration_specifiers_1z"CParser.p_declaration_specifiers_1!0..qtQqT6$.OO!rAcV||d|ddd|d<dS)zR declaration_specifiers : declaration_specifiers storage_class_specifier rrrTrrNrrs r?p_declaration_specifiers_2z"CParser.p_declaration_specifiers_2&s0..qtQqT9T.RR!rAcV||d|ddd|d<dS)zM declaration_specifiers : declaration_specifiers function_specifier rrrTrrNrrs r?p_declaration_specifiers_3z"CParser.p_declaration_specifiers_3+s0..qtQqT:d.SS!rAcV||d|ddd|d<dS)zS declaration_specifiers : declaration_specifiers type_specifier_no_typeid rrrnTrrNrrs r?p_declaration_specifiers_4z"CParser.p_declaration_specifiers_40rrAcF|d|dd|d<dS)z2 declaration_specifiers : type_specifier Nrrnrrrs r?p_declaration_specifiers_5z"CParser.p_declaration_specifiers_55'..tQqT6BB!rAcV||d|ddd|d<dS)zQ declaration_specifiers : declaration_specifiers_no_type type_specifier rrrnTrrNrrs r?p_declaration_specifiers_6z"CParser.p_declaration_specifiers_6:rrAcV||d|ddd|d<dS)zN declaration_specifiers : declaration_specifiers alignment_specifier rrrTrrNrrs r?p_declaration_specifiers_7z"CParser.p_declaration_specifiers_7?s0..qtQqT;t.TT!rAc|d|d<dS)a storage_class_specifier : AUTO | REGISTER | STATIC | EXTERN | TYPEDEF | _THREAD_LOCAL rrNr{rs r?p_storage_class_specifierz!CParser.p_storage_class_specifierDt!rAc|d|d<dS)zR function_specifier : INLINE | _NORETURN rrNr{rs r?p_function_specifierzCParser.p_function_specifierNrrAcntj|dg||d|d<dS)a+ type_specifier_no_typeid : VOID | _BOOL | CHAR | SHORT | INT | LONG | FLOAT | DOUBLE | _COMPLEX | SIGNED | UNSIGNED | __INT128 rryrNrrrrs r?p_type_specifier_no_typeidz"CParser.p_type_specifier_no_typeidTs7#QqTF$2C2CAq2I2IJJJ!rAc|d|d<dS)z type_specifier : typedef_name | enum_specifier | struct_or_union_specifier | type_specifier_no_typeid | atomic_specifier rrNr{rs r?p_type_specifierzCParser.p_type_specifierdst!rAcT|d}|jd||d<dS)z= atomic_specifier : _ATOMIC LPAREN type_name RPAREN r_AtomicrN)rrJ)r6rtyps r?p_atomic_specifierzCParser.p_atomic_specifierns0d ###!rAc|d|d<dS)z type_qualifier : CONST | RESTRICT | VOLATILE | _ATOMIC rrNr{rs r?p_type_qualifierzCParser.p_type_qualifierus t!rAcht|dkr|d|dgzn|dg|d<dS)z init_declarator_list : init_declarator | init_declarator_list COMMA init_declarator rrrrNrrs r?p_init_declarator_listzCParser.p_init_declarator_list}7!$A! qtqtf}}!A$!rAcpt|dt|dkr|dnd|d<dS)zb init_declarator : declarator | declarator EQUALS initializer rrrNrrr3rNrs r?p_init_declaratorzCParser.p_init_declarator81SVVaZZQqTTTCCC!rAcht|dkr|d|dgzn|dg|d<dS)z id_init_declarator_list : id_init_declarator | id_init_declarator_list COMMA init_declarator rrrrNrrs r?p_id_init_declarator_listz!CParser.p_id_init_declarator_listr4rAcpt|dt|dkr|dnd|d<dS)zn id_init_declarator : id_declarator | id_declarator EQUALS initializer rrrNrrr6rs r?p_id_init_declaratorzCParser.p_id_init_declaratorr8rAcV||d|ddd|d<dS)zY specifier_qualifier_list : specifier_qualifier_list type_specifier_no_typeid rrrnTrrNrrs r?p_specifier_qualifier_list_1z$CParser.p_specifier_qualifier_list_1rrAcV||d|ddd|d<dS)zO specifier_qualifier_list : specifier_qualifier_list type_qualifier rrrTrrNrrs r?p_specifier_qualifier_list_2z$CParser.p_specifier_qualifier_list_2rrAcF|d|dd|d<dS)z4 specifier_qualifier_list : type_specifier Nrrnrrrs r?p_specifier_qualifier_list_3z$CParser.p_specifier_qualifier_list_3rrAcNt|dgg|dgg|d<dS)zH specifier_qualifier_list : type_qualifier_list type_specifier rrrrNr3rs r?p_specifier_qualifier_list_4z$CParser.p_specifier_qualifier_list_4s.1RqtfrRRR!rAcBtg|dgggg|d<dS)z9 specifier_qualifier_list : alignment_specifier rrrNrDrs r?p_specifier_qualifier_list_5z$CParser.p_specifier_qualifier_list_5s*!vrRPPP!rAcR||d|dd|d<dS)zR specifier_qualifier_list : specifier_qualifier_list alignment_specifier rrrrNrrs r?p_specifier_qualifier_list_6z$CParser.p_specifier_qualifier_list_6rrAc||d}||dd||d|d<dS)z{ struct_or_union_specifier : struct_or_union ID | struct_or_union TYPEID rrNrWrrXr)rrr6rklasss r?p_struct_or_union_specifier_1z%CParser.p_struct_or_union_specifier_1sV//!55u1##Aq))+++!rAc||d}t|dkr'|dg||d|d<dS|d|d||d|d<dS)z struct_or_union_specifier : struct_or_union brace_open struct_declaration_list brace_close | struct_or_union brace_open brace_close rrNrrKrrrrNrrLs r?p_struct_or_union_specifier_2z%CParser.p_struct_or_union_specifier_2s//!55 q66Q;;5''1--///AaDDD 5d''1--///AaDDDrAc||d}t|dkr-||dg||d|d<dS||d|d||d|d<dS)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 rrrrKrrNrPrLs r?p_struct_or_union_specifier_3z%CParser.p_struct_or_union_specifier_3s //!55 q66Q;;5qT''1--///AaDDD 5qTd''1--///AaDDDrAc|d|d<dS)zF struct_or_union : STRUCT | UNION rrNr{rs r?p_struct_or_unionzCParser.p_struct_or_unionrrAcvt|dkr|dpg|d<dS|d|dpgz|d<dS)z struct_declaration_list : struct_declaration | struct_declaration_list struct_declaration rrrNrrs r?p_struct_declaration_listz!CParser.p_struct_declaration_listsF q66Q;;Q4:2AaDDDQ41Q4:2&AaDDDrAc|d}d|dvsJ|d|||d}nt|ddkrf|dd}t|tjr|}ntj|}||t | g}n'||t dd g}||d<dS) zW struct_declaration : specifier_qualifier_list struct_declarator_list_opt SEMI rrrrNrrrnrrqr)rrNrorNoderr3)r6rrrnode decl_types r?p_struct_declaration_1zCParser.p_struct_declaration_1stY//// Q4 ,,d-EEf  ! # # <?D$ ++ 7 !066 ,,+++,-..EE,,D1112-44E!rAcd|d<dS)z# struct_declaration : SEMI Nrr{rs r?p_struct_declaration_2zCParser.p_struct_declaration_2"s!rAc|dg|d<dS)z1 struct_declaration : pppragma_directive rrNr{rs r?p_struct_declaration_3zCParser.p_struct_declaration_3'rrAcht|dkr|d|dgzn|dg|d<dS)z struct_declarator_list : struct_declarator | struct_declarator_list COMMA struct_declarator rrrrNrrs r?p_struct_declarator_listz CParser.p_struct_declarator_list,r4rAc"|ddd|d<dS)z( struct_declarator : declarator rNrqrrr{rs r?p_struct_declarator_1zCParser.p_struct_declarator_15s!..!rAct|dkr|d|dd|d<dStjdddd|dd|d<dS)z struct_declarator : declarator COLON constant_expression | COLON constant_expression rrrfrNr)rNrrprs r?p_struct_declarator_2zCParser.p_struct_declarator_2:sZ q66A::aDQqT22AaDDD!N4tTBBqQRtTTAaDDDrAcltj|dd||d|d<dS)zM enum_specifier : ENUM ID | ENUM TYPEID rNrrrrrrs r?p_enum_specifier_1zCParser.p_enum_specifier_1Cs3z!A$d&7&71&=&=>>!rAcltjd|d||d|d<dS)zG enum_specifier : ENUM brace_open enumerator_list brace_close Nrrrrkrs r?p_enum_specifier_2zCParser.p_enum_specifier_2Is3z$!d&7&71&=&=>>!rAcxtj|d|d||d|d<dS)z enum_specifier : ENUM ID brace_open enumerator_list brace_close | ENUM TYPEID brace_open enumerator_list brace_close rrrrNrkrs r?p_enum_specifier_3zCParser.p_enum_specifier_3Ns7z!A$!d&7&71&=&=>>!rAc&t|dkr,tj|dg|dj|d<dSt|dkr |d|d<dS|dj|d|d|d<dS)z enumerator_list : enumerator | enumerator_list COMMA | enumerator_list COMMA enumerator rrrrN)rNrEnumeratorListrX enumeratorsrJrs r?p_enumerator_listzCParser.p_enumerator_listTs q66Q;;'1! ;;AaDDD VVq[[Q4AaDDD aD  # #AaD ) ) )Q4AaDDDrAcjtj|d||d|d<dS)z alignment_specifier : _ALIGNAS LPAREN type_name RPAREN | _ALIGNAS LPAREN constant_expression RPAREN rrrN)rAlignasrrs r?p_alignment_specifierzCParser.p_alignment_specifieras1}QqT4#4#4Q#:#:;;!rAcDt|dkr1tj|dd||d}n6tj|d|d||d}||j|j||d<dS)zR enumerator : ID | ID EQUALS constant_expression rrNrr)rNr Enumeratorrr[rWrX)r6r enumerators r? p_enumeratorzCParser.p_enumeratorgs q66Q;;)!d))!Q//11JJ)!ad))!Q//11J Z_j.>???!rAc|d|d<dS)zQ declarator : id_declarator | typeid_declarator rrNr{rs r? p_declaratorzCParser.p_declaratorwrrA)r~ID)typeidTYPEID)typeid_noparenrc|d|d<dS)z1 xxx_declarator : direct_xxx_declarator rrNr{rs r?p_xxx_declarator_1zCParser.p_xxx_declarator_1}rrAcP||d|d|d<dS)z9 xxx_declarator : pointer direct_xxx_declarator rrrNrvrs r?p_xxx_declarator_2zCParser.p_xxx_declarator_2s)%%adAaD11!rAc rtj|dddd||d|d<dS)z' direct_xxx_declarator : yyy rNrr)rrprrs r?p_direct_xxx_declarator_1z!CParser.p_direct_xxx_declarator_1sE~qT##Aq)) +++!rAc|d|d<dS)z@ direct_xxx_declarator : LPAREN xxx_declarator RPAREN rrNr{rs r?p_direct_xxx_declarator_2z!CParser.p_direct_xxx_declarator_2rrAc t|dkr|dngpg}tjdt|dkr|dn|d||dj}||d||d<dS) z} direct_xxx_declarator : direct_xxx_declarator LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET rrNrrrndim dim_qualsrXrqrrr)rNr ArrayDeclrXrv)r6rrarrs r?p_direct_xxx_declarator_3z!CParser.p_direct_xxx_declarator_3sQ!12oA !!A$*  %%1Q4#%>>!rAcd|d|dfD}d|D}tjd|d||dj}||d| |d <dS) 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 cBg|]}t|tr|n|gSr{rolist)r}items r?rz5CParser.p_direct_xxx_declarator_4..s=%%%!+4 6 6BTF%%%rArrc g|] }|D]}|| SrIr{)r}sublistrs r?rz5CParser.p_direct_xxx_declarator_4..s8!!!g'!!$rANrrrrrrrrXrv)r6r listed_qualsrrs r?p_direct_xxx_declarator_4z!CParser.p_direct_xxx_declarator_4s%%1ad %%% !!!!! o!A$*  %%1Q4#%>>!rAc tjdtj|d||d|d|dng|dj}||d||d<dS)zi direct_xxx_declarator : direct_xxx_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET Nrrrrrrrrr~rrXrvr6rrs r?p_direct_xxx_declarator_5z!CParser.p_direct_xxx_declarator_5so1t00A6677d.addBA$*  %%1Q4#%>>!rActtj|dd|dj}|jdkrR|jK|jjD]>}t|tjrn!| |j |j?| |d||d<dS)z direct_xxx_declarator : direct_xxx_declarator LPAREN parameter_type_list RPAREN | direct_xxx_declarator LPAREN identifier_list_opt RPAREN rNrargsrnrXLBRACErr) rrrXrlrnrparamsro EllipsisParamr[rWrv)r6rfuncparams r?p_direct_xxx_declarator_6z!CParser.p_direct_xxx_declarator_6s ~1A$*  ) ) + + 0H < <y$!Y-BBE!%)<==Duu((U[AAAA%%1Q4$%??!rAc||d}tj|dpgd|}t|dkr1|d}|j|j}|j||_|d|d<dS||d<dS)zm pointer : TIMES type_qualifier_list_opt | TIMES type_qualifier_list_opt pointer rrN)rrnrXrr)rrPtrDeclrNrn)r6rrX nested_type tail_types r? p_pointerzCParser.p_pointers!!!Q'' m!A$*"4uMMM q66A::!I.,%N .,(INQ4AaDDDAaDDDrAcht|dkr |dgn|d|dgz|d<dS)zs type_qualifier_list : type_qualifier | type_qualifier_list type_qualifier rrrNrrs r?p_type_qualifier_listzCParser.p_type_qualifier_list7Q1!vv!A$!A$-!rAct|dkrF|djtj||d|d|d<dS)zn parameter_type_list : parameter_list | parameter_list COMMA ELLIPSIS rrrrN)rNrrJrrrrs r?p_parameter_type_listzCParser.p_parameter_type_list sY q66A:: aDK  u243D3DQ3J3JKK L L Lt!rAct|dkr,tj|dg|dj|d<dS|dj|d|d|d<dS)zz parameter_list : parameter_declaration | parameter_list COMMA parameter_declaration rrrrNrNr ParamListrXrrJrs r?p_parameter_listzCParser.p_parameter_listg q66Q;;?AaD61Q4:66AaDDD aDK  qt $ $ $Q4AaDDDrAc|d}|ds/tjdg||dg|d<||t |dgd|d<d S) z parameter_declaration : declaration_specifiers id_declarator | declaration_specifiers typeid_noparen_declarator rrnrxryrrZrYrN)rrrrr3rs r?p_parameter_declaration_1z!CParser.p_parameter_declaration_1)stF| 0!0%''1--///0DL''QqT???#(%%%&(!rAc |d}|ds/tjdg||dg|d<t|ddkrt|ddjdkr`||ddjdr4||t|dd g d}nntjd |d d|dptj dddd||d }|d}| ||}||d<dS)zR parameter_declaration : declaration_specifiers abstract_declarator_opt rrnrxryrRrrNrrYrrrWrrrnrX) rrrrNr|r`rr3Typenamerpr)r6rrrqrs r?p_parameter_declaration_2z!CParser.p_parameter_declaration_25sntF| 0!0%''1--///0DL tF|  q Sfb)9)?%@%@A%E%E&&tF|B'7'=a'@AA&F++QqT5556,8889;DD>6lqTCU^D$dCC''1-- ///D F|H++D(;;D!rAct|dkr,tj|dg|dj|d<dS|dj|d|d|d<dS)ze identifier_list : identifier | identifier_list COMMA identifier rrrrNrrs r?p_identifier_listzCParser.p_identifier_listUrrAc|d|d<dS)z- initializer : assignment_expression rrNr{rs r?p_initializer_1zCParser.p_initializer_1_rrAc|d.tjg||d|d<dS|d|d<dS)z initializer : brace_open initializer_list_opt brace_close | brace_open initializer_list COMMA brace_close rNrr)rInitListrrs r?p_initializer_2zCParser.p_initializer_2dsG Q4<>"d&7&71&=&=>>AaDDDQ4AaDDDrAct|dkrW|d|dn tj|d|d}tj|g|dj|d<dS|d|dn tj|d|d}|dj||d|d<dS)z initializer_list : designation_opt initializer | initializer_list COMMA designation_opt initializer rrNrrr)rNrNamedInitializerrrXexprsrJ)r6rrs r?p_initializer_listzCParser.p_initializer_listms q66Q;;Q4<1Q44U-CAaD!A$-O-OD>4&!A$*55AaDDDQ4<1Q44U-CAaD!A$-O-OD aDJ  d # # #Q4AaDDDrAc|d|d<dS)z. designation : designator_list EQUALS rrNr{rs r? p_designationzCParser.p_designationyrrAcht|dkr |dgn|d|dgz|d<dS)z_ designator_list : designator | designator_list designator rrrNrrs r?p_designator_listzCParser.p_designator_listrrAc|d|d<dS)zi designator : LBRACKET constant_expression RBRACKET | PERIOD identifier rrNr{rs r? p_designatorzCParser.p_designatorrrAc  tjd|ddddd|dptjdddd||d}|||dd|d<dS) zH type_name : specifier_qualifier_list abstract_declarator_opt rrrNrrrnr)rrrprr)r6rrs r? p_type_namezCParser.p_type_names>A$v,qqq/1?dD$??##Aq)) +++''!A$v,??!rActtjdddd}|||d|d<dS)z+ abstract_declarator : pointer Nrrr)rrprv)r6r dummytypes r?p_abstract_declarator_1zCParser.p_abstract_declarator_1sEN4tT:: %%qT&!rAcP||d|d|d<dS)zF abstract_declarator : pointer direct_abstract_declarator rrrNrrs r?p_abstract_declarator_2zCParser.p_abstract_declarator_2s)%%adAaD11!rAc|d|d<dS)z> abstract_declarator : direct_abstract_declarator rrNr{rs r?p_abstract_declarator_3zCParser.p_abstract_declarator_3rrAc|d|d<dS)zA direct_abstract_declarator : LPAREN abstract_declarator RPAREN rrNr{rs r?p_direct_abstract_declarator_1z&CParser.p_direct_abstract_declarator_1t!rActjd|dg|dj}||d||d<dS)zn direct_abstract_declarator : direct_abstract_declarator LBRACKET assignment_expression_opt RBRACKET Nrrrrrrrs r?p_direct_abstract_declarator_2z&CParser.p_direct_abstract_declarator_2sVo!A$*  %%1Q4#%>>!rAc t|dkr|dngpg}tjtjddddt|dkr|dn|d|||d|d<dS)zk direct_abstract_declarator : LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET rrNrrrr)rNrrrpr)r6rrs r?p_direct_abstract_declarator_3z&CParser.p_direct_abstract_declarator_3sQ!12dD$77A !!##Aq)) +++!rAc tjdtj|d||dg|dj}||d||d<dS)zZ direct_abstract_declarator : direct_abstract_declarator LBRACKET TIMES RBRACKET Nrrrrrrrs r?p_direct_abstract_declarator_4z&CParser.p_direct_abstract_declarator_4sro1t00A6677A$*  %%1Q4#%>>!rAc tjtjddddtj|d||dg||d|d<dS)z? direct_abstract_declarator : LBRACKET TIMES RBRACKET Nrrrr)rrrpr~rrs r?p_direct_abstract_declarator_5z&CParser.p_direct_abstract_declarator_5sndD$771t00A6677##Aq)) +++!rActj|dd|dj}||d||d<dS)zh direct_abstract_declarator : direct_abstract_declarator LPAREN parameter_type_list_opt RPAREN rNrrrr)rrrXrv)r6rrs r?p_direct_abstract_declarator_6z&CParser.p_direct_abstract_declarator_6sS~1A$* %%1Q4$%??!rAc tj|dtjdddd||d|d<dS)zM direct_abstract_declarator : LPAREN parameter_type_list_opt RPAREN rNrrr)rrrprrs r?p_direct_abstract_declarator_7z&CParser.p_direct_abstract_declarator_7sO~1dD$77##Aq))+++!rAcdt|dtr|dn|dg|d<dS)zG block_item : declaration | statement rrNrrs r? p_block_itemzCParser.p_block_items2"!A$--9qttAaD6!rAc~t|dks |ddgkr|dn|d|dz|d<dS)z_ block_item_list : block_item | block_item_list block_item rNrrrrs r?p_block_item_listzCParser.p_block_item_listsA A! qtv~~qttAaD1Q4K!rAcltj|d||d|d<dS)zA compound_statement : brace_open block_item_list_opt brace_close rrrrN)rrrrs r?p_compound_statement_1zCParser.p_compound_statement_1s:~!##Aq))+++!rAcxtj|d|d||d|d<dS)z6 labeled_statement : ID COLON pragmacomp_or_statement rrrN)rLabelrrs r?p_labeled_statement_1zCParser.p_labeled_statement_15{1Q41t'8'8A'>'>??!rAcztj|d|dg||d|d<dS)zL labeled_statement : CASE constant_expression COLON pragmacomp_or_statement rrrrN)rCaserrs r?p_labeled_statement_2zCParser.p_labeled_statement_2 s7z!A$1(9(9!Q(?(?@@!rAcltj|dg||d|d<dS)z; labeled_statement : DEFAULT COLON pragmacomp_or_statement rrrN)rDefaultrrs r?p_labeled_statement_3zCParser.p_labeled_statement_3s1}adVT%6%6q!%<%<==!rAc ztj|d|dd||d|d<dS)zK selection_statement : IF LPAREN expression RPAREN pragmacomp_or_statement rrNrrrIfrrs r?p_selection_statement_1zCParser.p_selection_statement_1s7x!adD$*;*;Aq*A*ABB!rAc tj|d|d|d||d|d<dS)zZ selection_statement : IF LPAREN expression RPAREN statement ELSE pragmacomp_or_statement rrrrNrrs r?p_selection_statement_2zCParser.p_selection_statement_2s;x!adAaD$*;*;Aq*A*ABB!rAc ttj|d|d||d|d<dS)zO selection_statement : SWITCH LPAREN expression RPAREN pragmacomp_or_statement rrrrN)r rSwitchrrs r?p_selection_statement_3zCParser.p_selection_statement_3sD QqT1Q4):):1a)@)@AACC!rAcxtj|d|d||d|d<dS)zN iteration_statement : WHILE LPAREN expression RPAREN pragmacomp_or_statement rrrrN)rWhilerrs r?p_iteration_statement_1zCParser.p_iteration_statement_1 rrAcxtj|d|d||d|d<dS)zV iteration_statement : DO pragmacomp_or_statement WHILE LPAREN expression RPAREN SEMI rrrrN)rDoWhilerrs r?p_iteration_statement_2zCParser.p_iteration_statement_2$s5}QqT1Q4):):1a)@)@AA!rAc tj|d|d|d|d||d|d<dS)zx iteration_statement : FOR LPAREN expression_opt SEMI expression_opt SEMI expression_opt RPAREN pragmacomp_or_statement rrr rrN)rForrrs r?p_iteration_statement_3zCParser.p_iteration_statement_3(sAy1qtQqT1Q41B1B1a1H1HII!rAc tjtj|d||d|d|d|d||d|d<dS)zp iteration_statement : FOR LPAREN declaration expression_opt SEMI expression_opt RPAREN pragmacomp_or_statement rrrrN)rr DeclListrrs r?p_iteration_statement_4zCParser.p_iteration_statement_4,sdy!d.?.?1.E.EFF1qtQqT4+<+!A$!adAaDJ??AaDDDrAc|d|d<dS)z$ cast_expression : unary_expression rrNr{rs r?p_cast_expression_1zCParser.p_cast_expression_1rrAcxtj|d|d||d|d<dS)z; cast_expression : LPAREN type_name RPAREN cast_expression rrrrN)rCastrrs r?p_cast_expression_2zCParser.p_cast_expression_2s5z!A$!d&7&71&=&=>>!rAc|d|d<dS)z* unary_expression : postfix_expression rrNr{rs r?p_unary_expression_1zCParser.p_unary_expression_1rrAcftj|d|d|dj|d<dS)z unary_expression : PLUSPLUS unary_expression | MINUSMINUS unary_expression | unary_operator cast_expression rrrNrUnaryOprXrs r?p_unary_expression_2zCParser.p_unary_expression_2s- }QqT1Q4144!rActj|dt|dkr|dn|d||d|d<dS)z unary_expression : SIZEOF unary_expression | SIZEOF LPAREN type_name RPAREN | _ALIGNOF LPAREN type_name RPAREN rrrrN)rr=rNrrs r?p_unary_expression_3zCParser.p_unary_expression_3sT } aDFFaKKAaDDQqT   a # #%%!rAc|d|d<dS)z unary_operator : AND | TIMES | PLUS | MINUS | NOT | LNOT rrNr{rs r?p_unary_operatorzCParser.p_unary_operatorr$rAc|d|d<dS)z* postfix_expression : primary_expression rrNr{rs r?p_postfix_expression_1zCParser.p_postfix_expression_1rrAcftj|d|d|dj|d<dS)zG postfix_expression : postfix_expression LBRACKET expression RBRACKET rrrN)rArrayRefrXrs r?p_postfix_expression_2zCParser.p_postfix_expression_2s+~adAaD!A$*55!rActj|dt|dkr|dnd|dj|d<dS)z postfix_expression : postfix_expression LPAREN argument_expression_list RPAREN | postfix_expression LPAREN RPAREN rrrNr)rFuncCallrNrXrs r?p_postfix_expression_3zCParser.p_postfix_expression_3s?~adCFFaKKAaDDT1Q4:NN!rActj|d||d}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 rrrrN)rr~r StructRefrX)r6rfields r?p_postfix_expression_4zCParser.p_postfix_expression_4sT 1t00A6677qtQqT5!A$*==!rAcltjd|dz|d|dj|d<dS)z{ postfix_expression : postfix_expression PLUSPLUS | postfix_expression MINUSMINUS rrrrNr<rs r?p_postfix_expression_5zCParser.p_postfix_expression_5s1}S1Q4Z1qtz::!rAcNtj|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 rrrN)rCompoundLiteralrs r?p_postfix_expression_6zCParser.p_postfix_expression_6s&$QqT1Q400!rAc|d|d<dS)z" primary_expression : identifier rrNr{rs r?p_primary_expression_1zCParser.p_primary_expression_1rrAc|d|d<dS)z primary_expression : constant rrNr{rs r?p_primary_expression_2zCParser.p_primary_expression_2rrAc|d|d<dS)zp primary_expression : unified_string_literal | unified_wstring_literal rrNr{rs r?p_primary_expression_3zCParser.p_primary_expression_3rrAc|d|d<dS)z0 primary_expression : LPAREN expression RPAREN rrNr{rs r?p_primary_expression_4zCParser.p_primary_expression_4rrAc||d}tjtj|d|tj|d|dg|||d<dS)za primary_expression : OFFSETOF LPAREN type_name COMMA offsetof_member_designator RPAREN rrrrN)rrrIr~r!)r6rrXs r?p_primary_expression_5zCParser.p_primary_expression_5sb!!!Q''~ehqtU33#nadAaD\5AA#%%!rAct|dkr |d|d<dSt|dkr9tj|d|d|d|dj|d<dSt|dkr2tj|d|d|dj|d<dSt dt|z) z offsetof_member_designator : identifier | offsetof_member_designator PERIOD identifier | offsetof_member_designator LBRACKET expression RBRACKET rrrrrrz$Unexpected parsing state. len(p): %uN)rNrrLrXrFNotImplementedErrorrs r?p_offsetof_member_designatorz$CParser.p_offsetof_member_designators q66Q;;Q4AaDDD VVq[[?1Q41qtQqTZ@@AaDDD VVq[[>!A$!adj99AaDDD%&LsSTvv&UVV VrAct|dkr,tj|dg|dj|d<dS|dj|d|d|d<dS)z argument_expression_list : assignment_expression | argument_expression_list COMMA assignment_expression rrrrN)rNrr!rXrrJrs r?p_argument_expression_listz"CParser.p_argument_expression_listsg q66Q;;>1Q4&!A$*55AaDDD aDJ  ad # # #Q4AaDDDrAcjtj|d||d|d<dS)z identifier : ID rrN)rr~rrs r? p_identifierzCParser.p_identifiers/x!d//15566!rAc4d}d}|dddD]}|dvr|dz } |dvr|dz }d}|dkrtd|d krtd d |zd |zz}tj|d z|d||d|d<dS)z constant : INT_CONST_DEC | INT_CONST_OCT | INT_CONST_HEX | INT_CONST_BIN | INT_CONST_CHAR rrNlL)uUrz.Constant cannot have more than one u/U suffix.rz.Constant cannot have more than two l/L suffix.z unsigned zlong rx) ValueErrorrConstantr)r6ruCountlCountxrprefixs r? p_constant_1zCParser.p_constant_1#s1bcc  AJ! j!   A::NOO O aZZNOO Ov%&(88~ UNAaD$"3"3Aq"9"9;;!rAcd|dvrd}n(|dddvrd}n|dddvrd}nd}tj||d||d|d <d S) zM constant : FLOAT_CONST | HEX_FLOAT_CONST rprfloatrR)fFrgz long doubledoublerN)lowerrrmr)r6rrs r? p_constant_2zCParser.p_constant_2:s !A$**,,  AAtBx:%%1bZ''!~ qtT&&q!,,..!rAcltjd|d||d|d<dS)z constant : CHAR_CONST | WCHAR_CONST | U8CHAR_CONST | U16CHAR_CONST | U32CHAR_CONST charrrN)rrmrrs r? p_constant_3zCParser.p_constant_3Ks8~ AaD$++Aq1133!rAct|dkr5tjd|d||d|d<dS|djdd|dddz|d_|d|d<dS)z~ unified_string_literal : STRING_LITERAL | unified_string_literal STRING_LITERAL rstringrrNrR)rNrrmrvaluers r?p_unified_string_literalz CParser.p_unified_string_literalZs q66Q;;>!A$ 1 1!Q 7 799AaDDD1CRC1Q483AaDJQ4AaDDDrAc2t|dkr5tjd|d||d|d<dS|djdd|dddz|d_|d|d<dS)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 rr~rrNrR)rNrrmrrrstriprs r?p_unified_wstring_literalz!CParser.p_unified_wstring_literales q66Q;;>!A$ 1 1!Q 7 799AaDDD1**,,SbS1AaDHr@rBrErGrIrNrQrSrUrWr^r`rbrdrgrirlrnrprtrwr{r}rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr rrrrrrr"r$r&r)r+r-r0r3r5r8r:r>r@rBrDrGrJrNrPrSrUrWrYr[r]r`rbrdrrryr|rrrrrrr{rAr?r r s %'m(m(m(m(^0)))   +++,,,:::$$$R!!!d***X2WWWWr" J('''      MMM333 ===$      n   (,,,z444CCC FFF GGGCCC HHH PPP SSS TTT PPP CCC PPP UUU  KKK 888DDD 888 DDDPPP PPP CCC SSS QQQ HHH + + +///$///&'''$$$L  888/// UUU??? ??? ???   <<<   ]>>CCCCCCCCC @@@BBBJJJDDD 999444777TTT    KKKBBB   AAA@@@4???555%%%666OOO >>>;;; 111  %%% W W W777;;;...."333   "%%% %%%  E E E E ErAr N)plyrrrc_lexerr plyparserrrrr ast_transformsr r r r{rAr?rsEEEEEEEEEEEECCCCCCCC ~E~E~E~E~Ei~E~E ~E~E~ErA