3 ]@sddlZddlmZddlmZddlmZddlmZm Z m Z ddl m Z Gdd d eZ ed kr|ddlZddlZddlZdS) N)yacc)c_ast)CLexer) PLYParserCoord ParseError)fix_switch_casesc @sDeZdZdCddZdDd d Zd d Zd dZddZddZddZ ddZ ddZ ddZ ddZ ddZdd Zd!d"Zd#d$ZdEd%d&Zd'd(Zd)d*ZdPZd>d?Zd@dAZdBdCZdDdEZdFdGZdHdIZdJdKZdLdMZdNdOZdPdQZdRdSZ dTdUZ!dVdWZ"dXdYZ#dZd[Z$d\d]Z%d^d_Z&d`daZ'dbdcZ(dddeZ)dfdgZ*dhdiZ+djdkZ,dldmZ-dndoZ.dpdqZ/drdsZ0dtduZ1dvdwZ2dxdyZ3dzd{Z4d|d}Z5d~dZ6ddZ7ddZ8ddZ9ddZ:ddZ;ddZddZ?ddZ@ddZAddZBddZCddZDddZEddZFddZGddZHddZIddZJddZKddZLddZMddZNddZOddZPddZQddZRddZSddZTddZUddZVddZWddÄZXddńZYddDŽZZddɄZ[dd˄Z\dd̈́Z]ddτZ^ddфZ_ddӄZ`ddՄZaddׄZbddلZcddۄZddd݄Zedd߄ZfddZgddZhddZiddZjddZkddZlddZmddZnddZoddZpddZqddZrddZsddZtddZuddZvddZwddZxddZyddZzdd Z{d d Z|d d Z}ddZ~ddZddZddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Zd<d=Zd>d?Zd@dAZdBS(QCParserTpycparser.lextabpycparser.yacctabFc Cst|j|j|j|jd|_|jj|||d|jj|_ddddddd d d d d dddg}x|D]}|j|q\Wt j |d||||d|_ t g|_ d|_ dS)a Create a new CParser. Some arguments for controlling the debug/optimization level of the parser are provided. The defaults are tuned for release/performance mode. The simple rules for using them are: *) When tweaking CParser/CLexer, set these to False *) When releasing a stable parser, set to True lex_optimize: Set to False when you're modifying the lexer. Otherwise, changes in the lexer won't be used, if some lextab.py file exists. When releasing with a stable lexer, set to True to save the re-generation of the lexer table on each run. lextab: Points to the lex table that's used for optimized mode. Only if you're modifying the lexer and want some tests to avoid re-generating the table, make this point to a local lex table file (that's been earlier generated with lex_optimize=True) yacc_optimize: Set to False when you're modifying the parser. Otherwise, changes in the parser won't be used, if some parsetab.py file exists. When releasing with a stable parser, set to True to save the re-generation of the parser table on each run. yacctab: Points to the yacc table that's used for optimized mode. Only if you're modifying the parser, make this point to a local yacc table file yacc_debug: Generate a parser.out file that explains how yacc built the parsing table from the grammar. taboutputdir: Set this parameter to control the location of generated lextab and yacctab files. )Z error_funcZon_lbrace_funcZon_rbrace_funcZtype_lookup_func)optimizelextab outputdirZabstract_declaratorZassignment_expressionZdeclaration_listZdeclaration_specifiersZ designationZ expressionZidentifier_listZinit_declarator_listZinitializer_listZparameter_type_listZspecifier_qualifier_listZblock_item_listZtype_qualifier_listZstruct_declarator_listZtranslation_unit_or_empty)modulestartdebugrZ tabmodulerN)r_lex_error_func_lex_on_lbrace_func_lex_on_rbrace_func_lex_type_lookup_funcclexZbuildtokensZ_create_opt_rulercparserdict _scope_stack_last_yielded_token) selfZ lex_optimizerZ yacc_optimizeZyacctabZ yacc_debugZ taboutputdirZrules_with_optZruler/usr/lib/python3.6/c_parser.py__init__sF5    zCParser.__init__rcCs6||j_|jjtg|_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)inputZlexerr)rfilenameZ reset_linenorrrrparse)rtextr#Z debuglevelrrr r$~s   z CParser.parsecCs|jjtdS)N)rappendr)rrrr _push_scopeszCParser._push_scopecCs|jjdS)N)rpop)rrrr _pop_scopeszCParser._pop_scopecCs4|jdj|ds"|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 scopeNr*)rget _parse_error)rnamecoordrrr _add_typedef_names  zCParser._add_typedef_namecCs4|jdj|dr"|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_identifiers  zCParser._add_identifiercCs.x(t|jD]}|j|}|dk r |Sq WdS)z8 Is *name* a typedef-name in the current scope? NF)reversedrr+)rr-ZscopeZin_scoperrr _is_type_in_scopes  zCParser._is_type_in_scopecCs|j||j||dS)N)r,_coord)rmsglinecolumnrrr rszCParser._lex_error_funccCs |jdS)N)r')rrrr rszCParser._lex_on_lbrace_funccCs |jdS)N)r))rrrr rszCParser._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. )r2)rr-Zis_typerrr 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_token)rrrr _get_yacc_lookahead_tokensz!CParser._get_yacc_lookahead_tokencCsd|}|}x|jr|j}q Wt|tjr0||_|S|}xt|jtjsL|j}q6W|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_tailrrr _type_modify_decls    zCParser._type_modify_declcCs|}xt|tjs|j}qW|j|_|j|_x>|D]6}t|tjs2t|dkr^|j d|j q2||_|Sq2W|st|jtj s|j d|j tjdg|j d|_n tjdd|D|dj d|_|S) z- Fixes a declaration. Modifies decl. rz Invalid multiple types specifiedzMissing type in declarationint)r.cSsg|]}|jD]}|qqSr)names).0idr-rrr Usz/CParser._fix_decl_name_type..r) r9rr:r8declnamer-qualsIdentifierTypelenr,r.FuncDecl)rr;typenamer8Ztnrrr _fix_decl_name_type,s.       zCParser._fix_decl_name_typecCs(|ptggggd}||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. )qualstorager8functionr)rinsert)rZdeclspecZnewspecZkindspecrrr _add_declaration_specifierYs z"CParser._add_declaration_specifierc Cs@d|dk}g}|djddk r&n4|dddkrt|ddksvt|ddjd ksv|j|ddjd rd }x"|dD]}t|d r|j}PqW|jd |tj|ddjddd|ddjd |dd<|dd=nrt |ddtj tj tj fsZ|dd}xt |tjs.|j }qW|jdkrZ|ddjd|_|dd=x|D]} |rtjd|d|d| d| djd} nr)r.)rJrKr8rLrQ)rNr;r^r_rN)rrrEr3rr`)rrwrNrrr p_function_definition_1-szCParser.p_function_definition_1cCs.|d}|j||d|d|dd|d<dS)zi function_definition : declaration_specifiers declarator declaration_list_opt compound_statement rrQr)rNr;r^r_rN)r`)rrwrNrrr 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)rrwrrr p_statementIszCParser.p_statementc Cs|d}|ddkr|d}tjtjtjf}t|dkrzt|d|rztjd|d|d|d|ddd|djd g}q|j|t ddd gd d }n|j||dd d }||d<dS) zE decl_body : declaration_specifiers init_declarator_list_opt rrQNr8rrJrKrL)r-rDrKrTr8rSrPr.)r;rST)rNrYrZ) rrVrWEnumrFr9rXr.r]r)rrwrNZtyZs_u_or_erYrrr p_decl_body\s.   zCParser.p_decl_bodycCs|d|d<dS)z& declaration : decl_body SEMI rrNr)rrwrrr p_declarationszCParser.p_declarationcCs,t|dkr|dn|d|d|d<dS)zj declaration_list : declaration | declaration_list declaration rQrrN)rF)rrwrrr p_declaration_listszCParser.p_declaration_listcCs|j|d|dd|d<dS)zM declaration_specifiers : type_qualifier declaration_specifiers_opt rQrrJrN)rO)rrwrrr p_declaration_specifiers_1sz"CParser.p_declaration_specifiers_1cCs|j|d|dd|d<dS)zM declaration_specifiers : type_specifier declaration_specifiers_opt rQrr8rN)rO)rrwrrr p_declaration_specifiers_2sz"CParser.p_declaration_specifiers_2cCs|j|d|dd|d<dS)zV declaration_specifiers : storage_class_specifier declaration_specifiers_opt rQrrKrN)rO)rrwrrr p_declaration_specifiers_3sz"CParser.p_declaration_specifiers_3cCs|j|d|dd|d<dS)zQ declaration_specifiers : function_specifier declaration_specifiers_opt rQrrLrN)rO)rrwrrr p_declaration_specifiers_4sz"CParser.p_declaration_specifiers_4cCs|d|d<dS)z storage_class_specifier : AUTO | REGISTER | STATIC | EXTERN | TYPEDEF rrNr)rrwrrr p_storage_class_specifiersz!CParser.p_storage_class_specifiercCs|d|d<dS)z& function_specifier : INLINE rrNr)rrwrrr p_function_specifierszCParser.p_function_specifiercCs(tj|dg|j|jdd|d<dS)a type_specifier : VOID | _BOOL | CHAR | SHORT | INT | LONG | FLOAT | DOUBLE | _COMPLEX | SIGNED | UNSIGNED r)r.rN)rrEr3r)rrwrrr p_type_specifier_1s zCParser.p_type_specifier_1cCs|d|d<dS)z type_specifier : typedef_name | enum_specifier | struct_or_union_specifier rrNr)rrwrrr p_type_specifier_2szCParser.p_type_specifier_2cCs|d|d<dS)zo type_qualifier : CONST | RESTRICT | VOLATILE rrNr)rrwrrr p_type_qualifierszCParser.p_type_qualifiercCs0t|dkr|d|dgn|dg|d<dS)z init_declarator_list : init_declarator | init_declarator_list COMMA init_declarator rrrrN)rF)rrwrrr p_init_declarator_list_1sz CParser.p_init_declarator_list_1cCstd|ddg|d<dS)z6 init_declarator_list : EQUALS initializer NrQ)r;rSr)r)rrwrrr p_init_declarator_list_2sz CParser.p_init_declarator_list_2cCst|dddg|d<dS)z7 init_declarator_list : abstract_declarator rN)r;rSr)r)rrwrrr p_init_declarator_list_3sz CParser.p_init_declarator_list_3cCs,t|dt|dkr|dndd|d<dS)zb init_declarator : declarator | declarator EQUALS initializer rrQrN)r;rSr)rrF)rrwrrr p_init_declaratorszCParser.p_init_declaratorcCs|j|d|dd|d<dS)zS specifier_qualifier_list : type_qualifier specifier_qualifier_list_opt rQrrJrN)rO)rrwrrr 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 rQrr8rN)rO)rrwrrr p_specifier_qualifier_list_2 sz$CParser.p_specifier_qualifier_list_2cCs4|j|d}||dd|j|jdd|d<dS)z{ struct_or_union_specifier : struct_or_union ID | struct_or_union TYPEID rrQN)r-rYr.r)rcr3r)rrwklassrrr p_struct_or_union_specifier_1s z%CParser.p_struct_or_union_specifier_1cCs4|j|d}|d|d|j|jdd|d<dS)zd struct_or_union_specifier : struct_or_union brace_open struct_declaration_list brace_close rNrrQ)r-rYr.r)rcr3r)rrwrrrr p_struct_or_union_specifier_2s z%CParser.p_struct_or_union_specifier_2cCs8|j|d}||d|d|j|jdd|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 rrQr)r-rYr.rN)rcr3r)rrwrrrr 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)rrwrrr p_struct_or_union0szCParser.p_struct_or_unioncCs,t|dkr|dn|d|d|d<dS)z struct_declaration_list : struct_declaration | struct_declaration_list struct_declaration rQrrN)rF)rrwrrr p_struct_declaration_list8sz!CParser.p_struct_declaration_listcCs|d}|ddk r(|j||dd}nht|ddkrx|dd}t|tjrV|}n tj|}|j|t|dgd}n|j|tdddgd}||d<dS) zW struct_declaration : specifier_qualifier_list struct_declarator_list_opt SEMI rrQN)rNrYr8r)r;)r;rS)r]rFr9rZNoderEr)rrwrNrYZnodeZ decl_typerrr p_struct_declaration_1>s"    zCParser.p_struct_declaration_1cCs(|j|dt|dddgd|d<dS)zP struct_declaration : specifier_qualifier_list abstract_declarator SEMI rrQN)r;rS)rNrYr)r]r)rrwrrr p_struct_declaration_2ds zCParser.p_struct_declaration_2cCs0t|dkr|d|dgn|dg|d<dS)z struct_declarator_list : struct_declarator | struct_declarator_list COMMA struct_declarator rrrrN)rF)rrwrrr p_struct_declarator_listrsz CParser.p_struct_declarator_listcCs|ddd|d<dS)z( struct_declarator : declarator rN)r;rPrr)rrwrrr p_struct_declarator_1{szCParser.p_struct_declarator_1cCsDt|dkr$|d|dd|d<ntjddd|dd|d<dS)z struct_declarator : declarator COLON constant_expression | COLON constant_expression rr)r;rPrNrQ)rFrr:)rrwrrr p_struct_declarator_2s zCParser.p_struct_declarator_2cCs&tj|dd|j|jd|d<dS)zM enum_specifier : ENUM ID | ENUM TYPEID rQNrr)rrr3r)rrwrrr p_enum_specifier_1szCParser.p_enum_specifier_1cCs&tjd|d|j|jd|d<dS)zG enum_specifier : ENUM brace_open enumerator_list brace_close Nrrr)rrr3r)rrwrrr p_enum_specifier_2szCParser.p_enum_specifier_2cCs*tj|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 rQrrrN)rrr3r)rrwrrr p_enum_specifier_3szCParser.p_enum_specifier_3cCsht|dkr*tj|dg|dj|d<n:t|dkrD|d|d<n |djj|d|d|d<dS)z enumerator_list : enumerator | enumerator_list COMMA | enumerator_list COMMA enumerator rQrrrN)rFrZEnumeratorListr.Z enumeratorsr&)rrwrrr p_enumerator_lists   zCParser.p_enumerator_listcCsjt|dkr,tj|dd|j|jd}n"tj|d|d|j|jd}|j|j|j||d<dS)zR enumerator : ID | ID EQUALS constant_expression rQrNrr)rFrZ Enumeratorr3rr0r-r.)rrwZ enumeratorrrr p_enumerators  zCParser.p_enumeratorcCs|d|d<dS)z) declarator : direct_declarator rrNr)rrwrrr p_declarator_1szCParser.p_declarator_1cCs|j|d|d|d<dS)z1 declarator : pointer direct_declarator rQrrN)r=)rrwrrr p_declarator_2szCParser.p_declarator_2cCs:tj|ddd|j|jdd}|j||d|d<dS)z& declarator : pointer TYPEID rQN)rCr8rDr.rr)rr:r3rr=)rrwr;rrr p_declarator_3s zCParser.p_declarator_3cCs*tj|ddd|j|jdd|d<dS)z" direct_declarator : ID rN)rCr8rDr.r)rr:r3r)rrwrrr p_direct_declarator_1s zCParser.p_direct_declarator_1cCs|d|d<dS)z8 direct_declarator : LPAREN declarator RPAREN rQrNr)rrwrrr p_direct_declarator_2szCParser.p_direct_declarator_2cCsft|dkr|dngpg}tjdt|dkr6|dn|d||djd}|j|d|d|d<dS) zu direct_declarator : direct_declarator LBRACKET type_qualifier_list_opt assignment_expression_opt RBRACKET rNrr)r8dim dim_qualsr.)r;r<r)rFr ArrayDeclr.r=)rrwrDarrrrr p_direct_declarator_3szCParser.p_direct_declarator_3cCs^dd|d|dgD}dd|D}tjd|d||djd }|j|d|d |d <dS) z direct_declarator : direct_declarator LBRACKET STATIC type_qualifier_list_opt assignment_expression RBRACKET | direct_declarator LBRACKET type_qualifier_list STATIC assignment_expression RBRACKET cSs g|]}t|tr|n|gqSr)r9list)r@itemrrr rBsz1CParser.p_direct_declarator_4..rrcSs"g|]}|D]}|dk r |q qS)Nr)r@ZsublistrJrrr rBs Nrr)r8rrr.)r;r<r)rrr.r=)rrwZ listed_qualsrrrrr p_direct_declarator_4szCParser.p_direct_declarator_4cCs^tjdtj|d|j|jd|ddkr4|dng|djd}|j|d|d|d<dS)za direct_declarator : direct_declarator LBRACKET type_qualifier_list_opt TIMES RBRACKET Nrrr)r8rrr.)r;r<r)rrIDr3rr.r=)rrwrrrr p_direct_declarator_5s zCParser.p_direct_declarator_5cCs|tj|dd|djd}|jjdkrb|jdk rbx.|jjD]"}t|tjrNP|j |j |jqW||_|d|d<n||d<dS)zm pointer : TIMES type_qualifier_list_opt | TIMES type_qualifier_list_opt pointer rrQN)rDr8r.rr)r3rrZPtrDeclrFr8)rrwr.Z nested_typeZ tail_typerrr p_pointer(s   zCParser.p_pointercCs0t|dkr|dgn|d|dg|d<dS)zs type_qualifier_list : type_qualifier | type_qualifier_list type_qualifier rQrrN)rF)rrwrrr p_type_qualifier_listFszCParser.p_type_qualifier_listcCs>t|dkr.|djjtj|j|jd|d|d<dS)zn parameter_type_list : parameter_list | parameter_list COMMA ELLIPSIS rQrrrN)rFrr&rrr3r)rrwrrr p_parameter_type_listLs "zCParser.p_parameter_type_listcCsNt|dkr*tj|dg|dj|d<n |djj|d|d|d<dS)zz parameter_list : parameter_declaration | parameter_list COMMA parameter_declaration rQrrrN)rFr ParamListr.rr&)rrwrrr p_parameter_listUs zCParser.p_parameter_listcCsX|d}|ds2tjdg|j|jddg|d<|j|t|ddgdd|d<d S) zE parameter_declaration : declaration_specifiers declarator rr8r>)r.rQ)r;)rNrYrN)rrEr3rr]r)rrwrNrrr p_parameter_declaration_1_sz!CParser.p_parameter_declaration_1cCs|d}|ds2tjdg|j|jddg|d<t|ddkrt|dd jdkr|j|ddjdr|j|t|dddgd d}nHtj d |d |dptj ddd|j|jdd }|d}|j ||}||d<dS)zR parameter_declaration : declaration_specifiers abstract_declarator_opt rr8r>)r.rrQN)r;rS)rNrYr rJ)r-rDr8r.r*r*) rrEr3rrFr?r2r]rTypenamer:rI)rrwrNr;rHrrr p_parameter_declaration_2js"& z!CParser.p_parameter_declaration_2cCsNt|dkr*tj|dg|dj|d<n |djj|d|d|d<dS)ze identifier_list : identifier | identifier_list COMMA identifier rQrrrN)rFrrr.rr&)rrwrrr p_identifier_lists zCParser.p_identifier_listcCs|d|d<dS)z- initializer : assignment_expression rrNr)rrwrrr p_initializer_1szCParser.p_initializer_1cCs:|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 rQNrr)rInitListr3r)rrwrrr p_initializer_2s zCParser.p_initializer_2cCst|dkrN|ddkr |dntj|d|d}tj|g|dj|d<nD|ddkrb|dntj|d|d}|djj||d|d<dS)z initializer_list : designation_opt initializer | initializer_list COMMA designation_opt initializer rrNrQrr)rFrZNamedInitializerrr.exprsr&)rrwrSrrr p_initializer_lists  ((zCParser.p_initializer_listcCs|d|d<dS)z. designation : designator_list EQUALS rrNr)rrwrrr p_designationszCParser.p_designationcCs0t|dkr|dgn|d|dg|d<dS)z_ designator_list : designator | designator_list designator rQrrN)rF)rrwrrr p_designator_listszCParser.p_designator_listcCs|d|d<dS)zi designator : LBRACKET constant_expression RBRACKET | PERIOD identifier rQrNr)rrwrrr p_designatorszCParser.p_designatorcCsTtjd|dd|dp$tjddd|j|jdd}|j||dd|d<dS) zH type_name : specifier_qualifier_list abstract_declarator_opt r rrJrQN)r-rDr8r.r8r)rrr:r3rrI)rrwrHrrr p_type_names  zCParser.p_type_namecCs(tjddd}|j||dd|d<dS)z+ abstract_declarator : pointer Nr)r;r<r)rr:r=)rrwZ dummytyperrr p_abstract_declarator_1szCParser.p_abstract_declarator_1cCs|j|d|d|d<dS)zF abstract_declarator : pointer direct_abstract_declarator rQrrN)r=)rrwrrr p_abstract_declarator_2szCParser.p_abstract_declarator_2cCs|d|d<dS)z> abstract_declarator : direct_abstract_declarator rrNr)rrwrrr p_abstract_declarator_3szCParser.p_abstract_declarator_3cCs|d|d<dS)zA direct_abstract_declarator : LPAREN abstract_declarator RPAREN rQrNr)rrwrrr p_direct_abstract_declarator_1sz&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 Nrr)r8rrr.)r;r<r)rrr.r=)rrwrrrr p_direct_abstract_declarator_2s z&CParser.p_direct_abstract_declarator_2cCs4tjtjddd|dg|j|jdd|d<dS)zS direct_abstract_declarator : LBRACKET assignment_expression_opt RBRACKET NrQr)r8rrr.r)rrr:r3r)rrwrrr p_direct_abstract_declarator_3s  z&CParser.p_direct_abstract_declarator_3cCsJtjdtj|d|j|jdg|djd}|j|d|d|d<dS)zZ direct_abstract_declarator : direct_abstract_declarator LBRACKET TIMES RBRACKET Nrr)r8rrr.)r;r<r)rrrr3rr.r=)rrwrrrr p_direct_abstract_declarator_4s z&CParser.p_direct_abstract_declarator_4cCsHtjtjdddtj|d|j|jdg|j|jdd|d<dS)z? direct_abstract_declarator : LBRACKET TIMES RBRACKET Nrr)r8rrr.r)rrr:rr3r)rrwrrr p_direct_abstract_declarator_5 s  z&CParser.p_direct_abstract_declarator_5cCs4tj|dd|djd}|j|d|d|d<dS)zh direct_abstract_declarator : direct_abstract_declarator LPAREN parameter_type_list_opt RPAREN rNr)rr8r.)r;r<r)rrGr.r=)rrwrrrr p_direct_abstract_declarator_6s z&CParser.p_direct_abstract_declarator_6cCs2tj|dtjddd|j|jdd|d<dS)zM direct_abstract_declarator : LPAREN parameter_type_list_opt RPAREN rQNr)rr8r.r)rrGr:r3r)rrwrrr p_direct_abstract_declarator_7s z&CParser.p_direct_abstract_declarator_7cCs(t|dtr|dn|dg|d<dS)zG block_item : declaration | statement rrN)r9r)rrwrrr p_block_item*szCParser.p_block_itemcCs:t|dks|ddgkr"|dn|d|d|d<dS)z_ block_item_list : block_item | block_item_list block_item rQNrr)rF)rrwrrr p_block_item_list2szCParser.p_block_item_listcCs&tj|d|j|jdd|d<dS)zA compound_statement : brace_open block_item_list_opt brace_close rQr)Z block_itemsr.rN)rZCompoundr3r)rrwrrr p_compound_statement_19szCParser.p_compound_statement_1cCs*tj|d|d|j|jd|d<dS)z( labeled_statement : ID COLON statement rrrN)rZLabelr3r)rrwrrr p_labeled_statement_1?szCParser.p_labeled_statement_1cCs,tj|d|dg|j|jd|d<dS)z> labeled_statement : CASE constant_expression COLON statement rQrrrN)rZCaser3r)rrwrrr p_labeled_statement_2CszCParser.p_labeled_statement_2cCs&tj|dg|j|jd|d<dS)z- labeled_statement : DEFAULT COLON statement rrrN)rZDefaultr3r)rrwrrr p_labeled_statement_3GszCParser.p_labeled_statement_3cCs,tj|d|dd|j|jd|d<dS)z= selection_statement : IF LPAREN expression RPAREN statement rrNrr)rIfr3r)rrwrrr p_selection_statement_1KszCParser.p_selection_statement_1cCs0tj|d|d|d|j|jd|d<dS)zL selection_statement : IF LPAREN expression RPAREN statement ELSE statement rrrrN)rrr3r)rrwrrr p_selection_statement_2OszCParser.p_selection_statement_2cCs.ttj|d|d|j|jd|d<dS)zA selection_statement : SWITCH LPAREN expression RPAREN statement rrrrN)r rZSwitchr3r)rrwrrr p_selection_statement_3SszCParser.p_selection_statement_3cCs*tj|d|d|j|jd|d<dS)z@ iteration_statement : WHILE LPAREN expression RPAREN statement rrrrN)rZWhiler3r)rrwrrr p_iteration_statement_1XszCParser.p_iteration_statement_1cCs*tj|d|d|j|jd|d<dS)zH iteration_statement : DO statement WHILE LPAREN expression RPAREN SEMI rrQrrN)rZDoWhiler3r)rrwrrr p_iteration_statement_2\szCParser.p_iteration_statement_2cCs6tj|d|d|d|d|j|jd|d<dS)zj iteration_statement : FOR LPAREN expression_opt SEMI expression_opt SEMI expression_opt RPAREN statement rrr rrN)rForr3r)rrwrrr p_iteration_statement_3`szCParser.p_iteration_statement_3cCsJtjtj|d|j|jd|d|d|d|j|jd|d<dS)zb iteration_statement : FOR LPAREN declaration expression_opt SEMI expression_opt RPAREN statement rrrrN)rrZDeclListr3r)rrwrrr p_iteration_statement_4dszCParser.p_iteration_statement_4cCs$tj|d|j|jd|d<dS)z jump_statement : GOTO ID SEMI rQrrN)rZGotor3r)rrwrrr p_jump_statement_1iszCParser.p_jump_statement_1cCstj|j|jd|d<dS)z jump_statement : BREAK SEMI rrN)rZBreakr3r)rrwrrr p_jump_statement_2mszCParser.p_jump_statement_2cCstj|j|jd|d<dS)z! jump_statement : CONTINUE SEMI rrN)rZContinuer3r)rrwrrr p_jump_statement_3qszCParser.p_jump_statement_3cCs4tjt|dkr|dnd|j|jd|d<dS)z\ jump_statement : RETURN expression SEMI | RETURN SEMI rrQNrr)rZReturnrFr3r)rrwrrr p_jump_statement_4uszCParser.p_jump_statement_4cCs8|ddkr(tj|j|jd|d<n |d|d<dS)z, expression_statement : expression_opt SEMI rNr)rZEmptyStatementr3r)rrwrrr p_expression_statement{s zCParser.p_expression_statementcCsjt|dkr|d|d<nLt|dtjsFtj|dg|dj|d<|djj|d|d|d<dS)zn expression : assignment_expression | expression COMMA assignment_expression rQrrrN)rFr9rExprListr.rr&)rrwrrr p_expressions  zCParser.p_expressioncCs(tj|dg|j|jdd|d<dS)z typedef_name : TYPEID r)r.rN)rrEr3r)rrwrrr p_typedef_nameszCParser.p_typedef_namecCsDt|dkr|d|d<n&tj|d|d|d|dj|d<dS)z assignment_expression : conditional_expression | unary_expression assignment_operator assignment_expression rQrrrN)rFrZ Assignmentr.)rrwrrr p_assignment_expressions zCParser.p_assignment_expressioncCs|d|d<dS)a assignment_operator : EQUALS | XOREQUAL | TIMESEQUAL | DIVEQUAL | MODEQUAL | PLUSEQUAL | MINUSEQUAL | LSHIFTEQUAL | RSHIFTEQUAL | ANDEQUAL | OREQUAL rrNr)rrwrrr p_assignment_operators zCParser.p_assignment_operatorcCs|d|d<dS)z. constant_expression : conditional_expression rrNr)rrwrrr p_constant_expressionszCParser.p_constant_expressioncCsDt|dkr|d|d<n&tj|d|d|d|dj|d<dS)z conditional_expression : binary_expression | binary_expression CONDOP expression COLON conditional_expression rQrrrrN)rFrZ TernaryOpr.)rrwrrr p_conditional_expressions z CParser.p_conditional_expressioncCsDt|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 rQrrrN)rFrZBinaryOpr.)rrwrrr p_binary_expressions zCParser.p_binary_expressioncCs|d|d<dS)z$ cast_expression : unary_expression rrNr)rrwrrr p_cast_expression_1szCParser.p_cast_expression_1cCs*tj|d|d|j|jd|d<dS)z; cast_expression : LPAREN type_name RPAREN cast_expression rQrrrN)rZCastr3r)rrwrrr p_cast_expression_2szCParser.p_cast_expression_2cCs|d|d<dS)z* unary_expression : postfix_expression rrNr)rrwrrr p_unary_expression_1szCParser.p_unary_expression_1cCs$tj|d|d|dj|d<dS)z unary_expression : PLUSPLUS unary_expression | MINUSMINUS unary_expression | unary_operator cast_expression rrQrN)rUnaryOpr.)rrwrrr p_unary_expression_2szCParser.p_unary_expression_2cCs>tj|dt|dkr|dn|d|j|jd|d<dS)zx unary_expression : SIZEOF unary_expression | SIZEOF LPAREN type_name RPAREN rrrQrN)rrrFr3r)rrwrrr p_unary_expression_3szCParser.p_unary_expression_3cCs|d|d<dS)z unary_operator : AND | TIMES | PLUS | MINUS | NOT | LNOT rrNr)rrwrrr p_unary_operatorszCParser.p_unary_operatorcCs|d|d<dS)z* postfix_expression : primary_expression rrNr)rrwrrr p_postfix_expression_1szCParser.p_postfix_expression_1cCs$tj|d|d|dj|d<dS)zG postfix_expression : postfix_expression LBRACKET expression RBRACKET rrrN)rZArrayRefr.)rrwrrr p_postfix_expression_2szCParser.p_postfix_expression_2cCs4tj|dt|dkr|dnd|dj|d<dS)z postfix_expression : postfix_expression LPAREN argument_expression_list RPAREN | postfix_expression LPAREN RPAREN rrrNr)rFuncCallrFr.)rrwrrr p_postfix_expression_3szCParser.p_postfix_expression_3cCsBtj|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 rrrQrN)rrr3rZ StructRefr.)rrwZfieldrrr p_postfix_expression_4 szCParser.p_postfix_expression_4cCs(tjd|d|d|dj|d<dS)z{ postfix_expression : postfix_expression PLUSPLUS | postfix_expression MINUSMINUS rwrQrrN)rrr.)rrwrrr p_postfix_expression_5szCParser.p_postfix_expression_5cCstj|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 rQrrN)rZCompoundLiteral)rrwrrr p_postfix_expression_6szCParser.p_postfix_expression_6cCs|d|d<dS)z" primary_expression : identifier rrNr)rrwrrr p_primary_expression_1 szCParser.p_primary_expression_1cCs|d|d<dS)z primary_expression : constant rrNr)rrwrrr p_primary_expression_2$szCParser.p_primary_expression_2cCs|d|d<dS)zp primary_expression : unified_string_literal | unified_wstring_literal rrNr)rrwrrr p_primary_expression_3(szCParser.p_primary_expression_3cCs|d|d<dS)z0 primary_expression : LPAREN expression RPAREN rQrNr)rrwrrr p_primary_expression_4.szCParser.p_primary_expression_4cCsF|j|jd}tjtj|d|tj|d|dg|||d<dS)zQ primary_expression : OFFSETOF LPAREN type_name COMMA identifier RPAREN rrrrN)r3rrrrr)rrwr.rrr p_primary_expression_52szCParser.p_primary_expression_5cCsNt|dkr*tj|dg|dj|d<n |djj|d|d|d<dS)z argument_expression_list : assignment_expression | argument_expression_list COMMA assignment_expression rQrrrN)rFrrr.rr&)rrwrrr p_argument_expression_list:s z"CParser.p_argument_expression_listcCs$tj|d|j|jd|d<dS)z identifier : ID rrN)rrr3r)rrwrrr p_identifierDszCParser.p_identifiercCs&tjd|d|j|jd|d<dS)z constant : INT_CONST_DEC | INT_CONST_OCT | INT_CONST_HEX | INT_CONST_BIN r>rrN)rConstantr3r)rrwrrr p_constant_1HszCParser.p_constant_1cCs&tjd|d|j|jd|d<dS)zM constant : FLOAT_CONST | HEX_FLOAT_CONST floatrrN)rrr3r)rrwrrr p_constant_2QszCParser.p_constant_2cCs&tjd|d|j|jd|d<dS)zH constant : CHAR_CONST | WCHAR_CONST charrrN)rrr3r)rrwrrr p_constant_3XszCParser.p_constant_3cCsht|dkr0tjd|d|j|jd|d<n4|djdd|ddd|d_|d|d<dS)z~ unified_string_literal : STRING_LITERAL | unified_string_literal STRING_LITERAL rQstringrrNr*)rFrrr3rvalue)rrwrrr p_unified_string_literalds   (z CParser.p_unified_string_literalcCslt|dkr0tjd|d|j|jd|d<n8|djjdd|ddd|d_|d|d<dS)z unified_wstring_literal : WSTRING_LITERAL | unified_wstring_literal WSTRING_LITERAL rQrrrNr*)rFrrr3rrrstrip)rrwrrr p_unified_wstring_literalos   ,z!CParser.p_unified_wstring_literalcCs|d|d<dS)z brace_open : LBRACE rrNr)rrwrrr p_brace_openzszCParser.p_brace_opencCs|d|d<dS)z brace_close : RBRACE rrNr)rrwrrr p_brace_closeszCParser.p_brace_closecCs d|d<dS)zempty : Nrr)rrwrrr p_emptyszCParser.p_emptycCs<|r,|jd|j|j|j|jj|dn |jdddS)Nz before: %s)rr6zAt end of inputr )r,rr3rrZfind_tok_column)rrwrrr p_errors zCParser.p_errorN)Tr Tr Fr )r r)Frdrerdrfrdrgrdrhrdrirdrjrkrdrlrmrnrordrprqrdrrrsrdrtrurv) r r!r"r#r$r%r&r'r(r))__name__ __module__ __qualname__r!r$r'r)r/r0r2rrrrr7r=rIrOr]r`rcZ precedencerxryr{r|r}r~rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r r r r rrrrrrrrrrrrrrrr r sF c     )7- Y      ;      &                                            r __main__)reZplyrr rZc_lexerrZ plyparserrrrZast_transformsr r r*pprintZtimesysrrrr  s,