U q`r@slddlZddlmZddlmZddlmZddlmZm Z m Z m Z m Z ddl mZe Gdd d eZdS) N)yacc)c_ast)CLexer) PLYParserCoord ParseError parameterizedtemplate)fix_switch_casesc@seZdZdedddddfddZdJd d Zd d Zd dZddZddZ ddZ ddZ ddZ ddZ ddZddZdd Zd!d"ZdKd#d$ZdLd%d&Zd'd(Zd)d*Zd+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Zdd?Z d@dAZ!dBdCZ"dDdEZ#dFdGZ$dHdIZ%dJdKZ&dLdMZ'dNdOZ(dPdQZ)dRdSZ*dTdUZ+dVdWZ,dXdYZ-dZd[Z.d\d]Z/d^d_Z0d`daZ1dbdcZ2dddeZ3dfdgZ4dhdiZ5djdkZ6dldmZ7dndoZ8dpdqZ9drdsZ:dtduZ;dvdwZd|d}Z?d~dZ@ddZAddZBddZCddZDddZEddZFddZGddZHddZIddZJddZKddZLddZMeNdddddZOeNdddddZPeNdddddZQeNddddZReNdddddZSeNdddddZTeNdddddZUeNdddddZVddZWddZXddZYddZZddZ[ddZ\ddZ]ddZ^ddZ_ddZ`dd„ZaddĄZbddƄZcddȄZdddʄZedd̄Zfdd΄ZgddЄZhdd҄ZiddԄZjddքZkdd؄ZlddڄZmdd܄ZnddބZoddZpddZqddZrddZsddZtddZuddZvddZwddZxddZyddZzddZ{ddZ|ddZ}ddZ~ddZddZddZddZddZddZd d Zd d Zd dZddZddZddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Zd=d>Zd?d@ZdAdBZdCdDZdEdFZdGdHZdIS(MCParserTzpycparser.lextabzpycparser.yacctabFc Cs||j|j|j|jd|_|jj|||d|jj|_ddddddd d d d d dddg}|D]} || qZtj|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. lexer: Set this parameter to define the lexer to use if you're not using the default CLexer. lextab: Points to the lex table that's used for optimized mode. Only if you're modifying the lexer and want some tests to avoid re-generating the table, make this point to a local lex table file (that's been earlier generated with lex_optimize=True) yacc_optimize: Set to False when you're modifying the parser. Otherwise, changes in the parser won't be used, if some parsetab.py file exists. When releasing with a stable parser, set to True to save the re-generation of the parser table on each run. yacctab: Points to the yacc table that's used for optimized mode. Only if you're modifying the parser, make this point to a local yacc table file yacc_debug: Generate a parser.out file that explains how yacc built the parsing table from the grammar. taboutputdir: Set this parameter to control the location of generated lextab and yacctab files. )Z error_funcZon_lbrace_funcZon_rbrace_funcZtype_lookup_func)optimizelextab outputdirZabstract_declaratorZassignment_expressionZdeclaration_listZdeclaration_specifiers_no_typeZ designationZ expressionZidentifier_listZinit_declarator_listZid_init_declarator_listZinitializer_listZparameter_type_listZblock_item_listZtype_qualifier_listZstruct_declarator_listZtranslation_unit_or_empty)modulestartdebugrZ tabmodulerN) _lex_error_func_lex_on_lbrace_func_lex_on_rbrace_func_lex_type_lookup_funcclexbuildtokensZ_create_opt_rulercparserdict _scope_stack_last_yielded_token) selfZ lex_optimizelexerrZ yacc_optimizeZyacctabZ yacc_debugZ taboutputdirZrules_with_optZruler!9/tmp/pip-target-nv4zd3e_/lib/python/pycparser/c_parser.py__init__sN:   zCParser.__init__rcCs6||j_|jtg|_d|_|jj||j|dS)a& Parses C code and returns an AST. text: A string containing the C source code filename: Name of the file being parsed (for meaningful error messages) debuglevel: Debug level to yacc N)inputr r)rfilenameZ reset_linenorrrrparse)rtextr% debuglevelr!r!r"r&s   z CParser.parsecCs|jtdSN)rappendrrr!r!r" _push_scopeszCParser._push_scopecCs t|jdkst|jdS)Nr)lenrAssertionErrorpopr+r!r!r" _pop_scopeszCParser._pop_scopecCs4|jd|ds"|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 scopeNrget _parse_errorrnamecoordr!r!r"_add_typedef_nameszCParser._add_typedef_namecCs4|jd|dr"|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_identifierszCParser._add_identifiercCs.t|jD]}||}|dk r |Sq dS)z8 Is *name* a typedef-name in the current scope? NF)reversedrr3)rr6ZscopeZin_scoper!r!r"_is_type_in_scopes   zCParser._is_type_in_scopecCs|||||dSr))r4_coord)rmsglinecolumnr!r!r"rszCParser._lex_error_funccCs |dSr))r,r+r!r!r"rszCParser._lex_on_lbrace_funccCs |dSr))r0r+r!r!r"rszCParser._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"rs 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_tokensz!CParser._get_yacc_lookahead_tokencCs\|}|}|jr|j}qt|tjr,||_|S|}t|jtjsF|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 isinstancerTypeDecl)rdeclmodifierZ modifier_headZ modifier_tailZ decl_tailr!r!r"_type_modify_decls  zCParser._type_modify_declcCs|}t|tjs|j}q|j|_|j|_|D]:}t|tjs,t|dkrX| d|j q,||_|Sq,|st|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 declarationintr7cSsg|]}|jD]}|qqSr!)names).0idr6r!r!r" [sz/CParser._fix_decl_name_type..r) rBrrCrAdeclnamer6qualsIdentifierTyper-r4r7FuncDecl)rrDtypenamerAtnr!r!r"_fix_decl_name_type2s:      zCParser._fix_decl_name_typecCs<|ptggggd}|r(|||n||d||S)a Declaration specifiers are represented by a dictionary with the entries: * qual: a list of type qualifiers * storage: a list of storage type qualifiers * type: a list of type specifiers * function: a list of function specifiers This method is given a declaration specifier, and a new specifier of a given kind. If `append` is True, the new specifier is added to the end of the specifiers list, otherwise it's added at the beginning. Returns the declaration specifier, with the new specifier incorporated. qualstoragerAfunctionr)rr*insert)rZdeclspecZnewspeckindr*specr!r!r"_add_declaration_specifier_s z"CParser._add_declaration_specifierc CsFd|dk}g}|dddk r&n,|dddkrt|ddkstt|dd jd kst||dd jdsd }|dD]}t|d r|j}qq|d |tj|dd jddd|dd jd|dd<|dd =nnt |ddtj tj tj fsR|dd}t |tjs(|j }q|jdkrR|dd jd|_|dd =|D]} | ddk slt|rtjd|d|d| d| djd} n.rrcSs"g|]}|D]}|dk r |q qSr)r!)rJZsublistrUr!r!r"rLzs Nrrrrrrrr7rF)rr|Z listed_qualsrrr!r!r"p_direct_xxx_declarator_4psz!CParser.p_direct_xxx_declarator_4c CsZtjdt|d||d|ddkr0|dng|djd}|j|d|d|d<dS)zi direct_xxx_declarator : direct_xxx_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET Nrrrrrrrrrrr7rFrr|rr!r!r"p_direct_xxx_declarator_5sz!CParser.p_direct_xxx_declarator_5cCsztj|dd|djd}|jdkr`|jdk r`|jjD]$}t|tjrNq`| |j |jq:|j |d|d|d<dS)z direct_xxx_declarator : direct_xxx_declarator LPAREN parameter_type_list RPAREN | direct_xxx_declarator LPAREN identifier_list_opt RPAREN rNrargsrAr7LBRACErr) rrPr7r@rArparamsrB EllipsisParamr9r6rF)rr|funcparamr!r!r"p_direct_xxx_declarator_6s   z!CParser.p_direct_xxx_declarator_6cCsj||d}tj|dpgd|d}t|dkr^|d}|jdk rJ|j}q8||_|d|d<n||d<dS)zm pointer : TIMES type_qualifier_list_opt | TIMES type_qualifier_list_opt pointer rr^N)rNrAr7rr)rrZPtrDeclr-rA)rr|r7Z nested_typeZ tail_typer!r!r" p_pointers   zCParser.p_pointercCs0t|dkr|dgn|d|dg|d<dS)zs type_qualifier_list : type_qualifier | type_qualifier_list type_qualifier r^rrNrr{r!r!r"p_type_qualifier_listszCParser.p_type_qualifier_listcCs:t|dkr*|djt||d|d|d<dS)zn parameter_type_list : parameter_list | parameter_list COMMA ELLIPSIS r^rrrN)r-rr*rrrr{r!r!r"p_parameter_type_lists 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^rrrNr-rZ ParamListr7rr*r{r!r!r"p_parameter_lists zCParser.p_parameter_listcCsT|d}|ds.tjdg||ddg|d<|j|t|ddgdd|d<d S) z parameter_declaration : declaration_specifiers id_declarator | declaration_specifiers typeid_noparen_declarator rrArGrHr^rrrN)rrOrrkrrr!r!r"p_parameter_declaration_1s z!CParser.p_parameter_declaration_1cCs|d}|ds.tjdg||ddg|d<t|ddkrt|ddjdkr||ddjdr|j|t|ddd gd d}nDtjd |d |dpt ddd||dd }|d}| ||}||d<dS)zR parameter_declaration : declaration_specifiers abstract_declarator_opt rrArGrHr1rr^Nrlrr rUr6rNrAr7) rrOrr-rIr;rkrTypenamerCrS)rr|rZrDrQr!r!r"p_parameter_declaration_2s. &  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^rrrNrr{r!r!r"p_identifier_lists zCParser.p_identifier_listcCs|d|d<dS)z- initializer : assignment_expression rrNr!r{r!r!r"p_initializer_1%szCParser.p_initializer_1cCs6|ddkr&tg||d|d<n |d|d<dS)z initializer : brace_open initializer_list_opt brace_close | brace_open initializer_list COMMA brace_close r^Nrr)rInitListrr{r!r!r"p_initializer_2*s zCParser.p_initializer_2cCst|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 rrNr^rr)r-rZNamedInitializerrr7exprsr*)rr|rar!r!r"p_initializer_list3s  ((zCParser.p_initializer_listcCs|d|d<dS)z. designation : designator_list EQUALS rrNr!r{r!r!r" p_designation?szCParser.p_designationcCs0t|dkr|dgn|d|dg|d<dS)z_ designator_list : designator | designator_list designator r^rrNrr{r!r!r"p_designator_listGszCParser.p_designator_listcCs|d|d<dS)zi designator : LBRACKET constant_expression RBRACKET | PERIOD identifier r^rNr!r{r!r!r" p_designatorMszCParser.p_designatorcCsPtjd|dd|dp$tddd||dd}|||dd|d<dS) zH type_name : specifier_qualifier_list abstract_declarator_opt r rrUr^NrrAr)rrrCrrS)rr|rQr!r!r" p_type_nameSs  zCParser.p_type_namecCs(tddd}|j||dd|d<dS)z+ abstract_declarator : pointer Nrrr)rrCrF)rr|Z 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^rrNrr{r!r!r"p_abstract_declarator_2fszCParser.p_abstract_declarator_2cCs|d|d<dS)z> abstract_declarator : direct_abstract_declarator rrNr!r{r!r!r"p_abstract_declarator_3kszCParser.p_abstract_declarator_3cCs|d|d<dS)zA direct_abstract_declarator : LPAREN abstract_declarator RPAREN r^rNr!r{r!r!r"p_direct_abstract_declarator_1usz&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 Nrrrrrrrr!r!r"p_direct_abstract_declarator_2ysz&CParser.p_direct_abstract_declarator_2cCs`t|dkr|dngpg}tjtdddt|dkr@|dn|d|||dd|d<dS)zk direct_abstract_declarator : LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET rr^Nrrrr)r-rrrCr)rr|rNr!r!r"p_direct_abstract_declarator_3s  z&CParser.p_direct_abstract_declarator_3c CsFtjdt|d||dg|djd}|j|d|d|d<dS)zZ direct_abstract_declarator : direct_abstract_declarator LBRACKET TIMES RBRACKET Nrrrrrrrr!r!r"p_direct_abstract_declarator_4sz&CParser.p_direct_abstract_declarator_4c Cs@tjtdddt|d||dg||dd|d<dS)z? direct_abstract_declarator : LBRACKET TIMES RBRACKET Nrrrr)rrrCrrr{r!r!r"p_direct_abstract_declarator_5s   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 rNrrrr)rrPr7rF)rr|rr!r!r"p_direct_abstract_declarator_6s z&CParser.p_direct_abstract_declarator_6cCs.tj|dtddd||dd|d<dS)zM direct_abstract_declarator : LPAREN parameter_type_list_opt RPAREN r^Nrrr)rrPrCrr{r!r!r"p_direct_abstract_declarator_7s   z&CParser.p_direct_abstract_declarator_7cCs(t|dtr|dn|dg|d<dS)zG block_item : declaration | statement rrNrr{r!r!r" p_block_itemszCParser.p_block_itemcCs:t|dks|ddgkr"|dn|d|d|d<dS)z_ block_item_list : block_item | block_item_list block_item r^Nrrrr{r!r!r"p_block_item_listszCParser.p_block_item_listcCs"tj|d||dd|d<dS)zA compound_statement : brace_open block_item_list_opt brace_close r^rrrN)rrrr{r!r!r"p_compound_statement_1s zCParser.p_compound_statement_1cCs&t|d|d||d|d<dS)z6 labeled_statement : ID COLON pragmacomp_or_statement rrrN)rZLabelrr{r!r!r"p_labeled_statement_1szCParser.p_labeled_statement_1cCs(t|d|dg||d|d<dS)zL labeled_statement : CASE constant_expression COLON pragmacomp_or_statement r^rrrN)rZCaserr{r!r!r"p_labeled_statement_2szCParser.p_labeled_statement_2cCs"t|dg||d|d<dS)z; labeled_statement : DEFAULT COLON pragmacomp_or_statement rrrN)rZDefaultrr{r!r!r"p_labeled_statement_3szCParser.p_labeled_statement_3c Cs(t|d|dd||d|d<dS)zK selection_statement : IF LPAREN expression RPAREN pragmacomp_or_statement rrNrrrZIfrr{r!r!r"p_selection_statement_1szCParser.p_selection_statement_1c Cs,t|d|d|d||d|d<dS)zZ selection_statement : IF LPAREN expression RPAREN statement ELSE pragmacomp_or_statement rrrrNrr{r!r!r"p_selection_statement_2szCParser.p_selection_statement_2c Cs*tt|d|d||d|d<dS)zO selection_statement : SWITCH LPAREN expression RPAREN pragmacomp_or_statement rrrrN)r rZSwitchrr{r!r!r"p_selection_statement_3szCParser.p_selection_statement_3cCs&t|d|d||d|d<dS)zN iteration_statement : WHILE LPAREN expression RPAREN pragmacomp_or_statement rrrrN)rZWhilerr{r!r!r"p_iteration_statement_1szCParser.p_iteration_statement_1cCs&t|d|d||d|d<dS)zV iteration_statement : DO pragmacomp_or_statement WHILE LPAREN expression RPAREN SEMI rr^rrN)rZDoWhilerr{r!r!r"p_iteration_statement_2szCParser.p_iteration_statement_2c Cs2t|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)rForrr{r!r!r"p_iteration_statement_3szCParser.p_iteration_statement_3c CsBtt|d||d|d|d|d||d|d<dS)zp iteration_statement : FOR LPAREN declaration expression_opt SEMI expression_opt RPAREN pragmacomp_or_statement rrrrN)rrZDeclListrr{r!r!r"p_iteration_statement_4s  zCParser.p_iteration_statement_4cCs t|d||d|d<dS)z jump_statement : GOTO ID SEMI r^rrN)rZGotorr{r!r!r"p_jump_statement_1szCParser.p_jump_statement_1cCst||d|d<dS)z jump_statement : BREAK SEMI rrN)rZBreakrr{r!r!r"p_jump_statement_2szCParser.p_jump_statement_2cCst||d|d<dS)z! jump_statement : CONTINUE SEMI rrN)rContinuerr{r!r!r"p_jump_statement_3szCParser.p_jump_statement_3cCs0tt|dkr|dnd||d|d<dS)z\ jump_statement : RETURN expression SEMI | RETURN SEMI rr^Nrr)rZReturnr-rr{r!r!r"p_jump_statement_4szCParser.p_jump_statement_4cCs4|ddkr$t||d|d<n |d|d<dS)z, expression_statement : expression_opt SEMI rNr^r)rZEmptyStatementrr{r!r!r"p_expression_statements zCParser.p_expression_statementcCsjt|dkr|d|d<nLt|dtjsFt|dg|dj|d<|dj|d|d|d<dS)zn expression : assignment_expression | expression COMMA assignment_expression r^rrrN)r-rBrExprListr7rr*r{r!r!r" p_expressions  zCParser.p_expressioncCs$tj|dg||dd|d<dS)z typedef_name : TYPEID rrHrNrr{r!r!r"p_typedef_nameszCParser.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^rrrN)r-rZ Assignmentr7r{r!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!r{r!r!r"p_assignment_operator.s zCParser.p_assignment_operatorcCs|d|d<dS)z. constant_expression : conditional_expression rrNr!r{r!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^rrrrN)r-rZ TernaryOpr7r{r!r!r"p_conditional_expressionAs 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^rrrN)r-rZBinaryOpr7r{r!r!r"p_binary_expressionJs zCParser.p_binary_expressioncCs|d|d<dS)z$ cast_expression : unary_expression rrNr!r{r!r!r"p_cast_expression_1dszCParser.p_cast_expression_1cCs&t|d|d||d|d<dS)z; cast_expression : LPAREN type_name RPAREN cast_expression r^rrrN)rZCastrr{r!r!r"p_cast_expression_2hszCParser.p_cast_expression_2cCs|d|d<dS)z* unary_expression : postfix_expression rrNr!r{r!r!r"p_unary_expression_1lszCParser.p_unary_expression_1cCs$t|d|d|dj|d<dS)z unary_expression : PLUSPLUS unary_expression | MINUSMINUS unary_expression | unary_operator cast_expression rr^rNrUnaryOpr7r{r!r!r"p_unary_expression_2pszCParser.p_unary_expression_2cCs:t|dt|dkr|dn|d||d|d<dS)zx unary_expression : SIZEOF unary_expression | SIZEOF LPAREN type_name RPAREN rrr^rN)rr.r-rr{r!r!r"p_unary_expression_3ws  zCParser.p_unary_expression_3cCs|d|d<dS)z unary_operator : AND | TIMES | PLUS | MINUS | NOT | LNOT rrNr!r{r!r!r"p_unary_operatorszCParser.p_unary_operatorcCs|d|d<dS)z* postfix_expression : primary_expression rrNr!r{r!r!r"p_postfix_expression_1szCParser.p_postfix_expression_1cCs$t|d|d|dj|d<dS)zG postfix_expression : postfix_expression LBRACKET expression RBRACKET rrrN)rArrayRefr7r{r!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 rrrNr)rFuncCallr-r7r{r!r!r"p_postfix_expression_3szCParser.p_postfix_expression_3cCs>t|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 rrr^rN)rrr StructRefr7)rr|fieldr!r!r"p_postfix_expression_4szCParser.p_postfix_expression_4cCs(td|d|d|dj|d<dS)z{ postfix_expression : postfix_expression PLUSPLUS | postfix_expression MINUSMINUS r|r^rrNr-r{r!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^rrN)rZCompoundLiteralr{r!r!r"p_postfix_expression_6szCParser.p_postfix_expression_6cCs|d|d<dS)z" primary_expression : identifier rrNr!r{r!r!r"p_primary_expression_1szCParser.p_primary_expression_1cCs|d|d<dS)z primary_expression : constant rrNr!r{r!r!r"p_primary_expression_2szCParser.p_primary_expression_2cCs|d|d<dS)zp primary_expression : unified_string_literal | unified_wstring_literal rrNr!r{r!r!r"p_primary_expression_3szCParser.p_primary_expression_3cCs|d|d<dS)z0 primary_expression : LPAREN expression RPAREN r^rNr!r{r!r!r"p_primary_expression_4szCParser.p_primary_expression_4cCsB||d}tt|d|t|d|dg|||d<dS)za primary_expression : OFFSETOF LPAREN type_name COMMA offsetof_member_designator RPAREN rrrrN)rrr5rr")rr|r7r!r!r"p_primary_expression_5s  zCParser.p_primary_expression_5cCst|dkr|d|d<nrt|dkrNt|d|d|d|dj|d<n>t|dkr|t|d|d|dj|d<ntdt|dS) z offsetof_member_designator : identifier | offsetof_member_designator PERIOD identifier | offsetof_member_designator LBRACKET expression RBRACKET r^rrrrrz$Unexpected parsing state. len(p): %uN)r-rr7r7r3NotImplementedErrorr{r!r!r"p_offsetof_member_designators  ( "z$CParser.p_offsetof_member_designatorcCsNt|dkr*t|dg|dj|d<n |dj|d|d|d<dS)z argument_expression_list : assignment_expression | argument_expression_list COMMA assignment_expression r^rrrN)r-rr"r7rr*r{r!r!r"p_argument_expression_lists z"CParser.p_argument_expression_listcCs t|d||d|d<dS)z identifier : ID rrN)rrrr{r!r!r" p_identifierszCParser.p_identifiercCsd}d}|dddD]&}|dkr.|d7}q|dkr|d7}qd}|dkrVtdn|d krftd d |d |}t|d |d||d|d<dS)z constant : INT_CONST_DEC | INT_CONST_OCT | INT_CONST_HEX | INT_CONST_BIN | INT_CONST_CHAR rrNlL)uUr z.Constant cannot have more than one u/U suffix.r^z.Constant cannot have more than two l/L suffix.z unsigned zlong rG) ValueErrorrConstantr)rr|ZuCountZlCountxriprefixr!r!r" p_constant_1s$    zCParser.p_constant_1cCshd|dkrd}n0|dddkr,d}n|dddkrBd}nd}t||d||d|d <d S) zM constant : FLOAT_CONST | HEX_FLOAT_CONST rMrfloatr1)fFrFz long doubledoublerN)lowerrrLr)rr|rir!r!r" p_constant_2s zCParser.p_constant_2cCs"td|d||d|d<dS)zH constant : CHAR_CONST | WCHAR_CONST charrrN)rrLrr{r!r!r" p_constant_3 s  zCParser.p_constant_3cCsdt|dkr,td|d||d|d<n4|djdd|ddd|d_|d|d<dS)z~ unified_string_literal : STRING_LITERAL | unified_string_literal STRING_LITERAL r^stringrrNr1)r-rrLrvaluer{r!r!r"p_unified_string_literals  (z CParser.p_unified_string_literalcCsht|dkr,td|d||d|d<n8|djdd|ddd|d_|d|d<dS)z unified_wstring_literal : WSTRING_LITERAL | unified_wstring_literal WSTRING_LITERAL r^rXrrNr1)r-rrLrrYrstripr{r!r!r"p_unified_wstring_literal"s  ,z!CParser.p_unified_wstring_literalcCs"|d|d<|d|ddS)z brace_open : LBRACE rrNZ set_linenolinenor{r!r!r" p_brace_open-s zCParser.p_brace_opencCs"|d|d<|d|ddS)z brace_close : RBRACE rrNr]r{r!r!r" p_brace_close3s zCParser.p_brace_closecCs d|d<dS)zempty : Nrr!r{r!r!r"p_empty9szCParser.p_emptycCs@|r,|d|j|j|j|j|dn|d|jjdS)Nz before: %s)r^r?zAt end of input)r4rYr<r^rZfind_tok_columnr%r{r!r!r"p_error=s zCParser.p_errorN)r r)F)F)__name__ __module__ __qualname__rr#r&r,r0r8r9r;rrrrr@rFrSr[rkrprs precedencer}r~rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r r r r rrrrrrrrrrrr r!r#r$r%r&r'r(r)r*r+r,r/r0r1r2r4r6r9r:r;r<r=r>r?r@rBrCrDrOrUrWrZr\r_r`rarbr!r!r!r"r s^ o     )7-  Y     5<       &                                                         r )reZplyrr rZc_lexerrZ plyparserrrrr r Zast_transformsr r r!r!r!r" s