9(Zc@sddlZddlmZddlmZddlmZddlmZm Z m Z m Z m Z ddl mZe defd YZed krddlZddlZddlZndS( iNi(tyacc(tc_ast(tCLexer(t PLYParsertCoordt ParseErrort parameterizedttemplate(tfix_switch_casestCParserc Bs_eZeedededdZdddZdZdZdZ d Z d Z d Z d Z d ZdZdZdZdZedZedZdZdZddddddddddf Zd)Zd*Zd+Zd,Zd-Zd.Zd/Zd0Zd1Z d2Z!d3Z"d4Z#d5Z$d6Z%d7Z&d8Z'd9Z(d:Z)d;Z*d<Z+d=Z,d>Z-d?Z.d@Z/dAZ0dBZ1dCZ2dDZ3dEZ4dFZ5dGZ6dHZ7dIZ8dJZ9dKZ:dLZ;dMZ<dNZ=dOZ>dPZ?dQZ@dRZAdSZBdTZCdUZDdVZEdWZFdXZGdYZHdZZId[ZJd\ZKd]ZLeMddddcZNeMdddddZOeMddddeZPeMdddfZQeMddddgZReMddddhZSeMddddiZTeMddddjZUdkZVdlZWdmZXdnZYdoZZdpZ[dqZ\drZ]dsZ^dtZ_duZ`dvZadwZbdxZcdyZddzZed{Zfd|Zgd}Zhd~ZidZjdZkdZldZmdZndZodZpdZqdZrdZsdZtdZudZvdZwdZxdZydZzdZ{dZ|dZ}dZ~dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZRS(spycparser.lextabspycparser.yacctabtc Cs|d|jd|jd|jd|j|_|jjd|d|d||jj|_dd d d d d ddddddddg}x|D]} |j| qWtjd|ddd|d|d|d||_ t g|_ d|_ dS(s 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. t error_functon_lbrace_functon_rbrace_functtype_lookup_functoptimizetlextabt outputdirtabstract_declaratortassignment_expressiontdeclaration_listtdeclaration_specifiers_no_typet designationt expressiontidentifier_listtinit_declarator_listtid_init_declarator_listtinitializer_listtparameter_type_listtblock_item_listttype_qualifier_listtstruct_declarator_listtmoduletstartttranslation_unit_or_emptytdebugt tabmoduleN(t_lex_error_funct_lex_on_lbrace_funct_lex_on_rbrace_funct_lex_type_lookup_functclextbuildttokenst_create_opt_ruleRtcparsertdictt _scope_stacktNonet_last_yielded_token( tselft lex_optimizetlexerRt yacc_optimizetyacctabt yacc_debugt taboutputdirtrules_with_opttrule((s5/tmp/pip-build-wDUJoH/pycparser/pycparser/c_parser.pyt__init__sF:        icCsS||j_|jjtg|_d|_|jjd|d|jd|S(s& 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 tinputR4R#N( R)tfilenamet reset_linenoR.R/R0R1R-tparse(R2ttextR=t debuglevel((s5/tmp/pip-build-wDUJoH/pycparser/pycparser/c_parser.pyR?s     cCs|jjtdS(N(R/tappendR.(R2((s5/tmp/pip-build-wDUJoH/pycparser/pycparser/c_parser.pyt _push_scopescCs,t|jdkst|jjdS(Ni(tlenR/tAssertionErrortpop(R2((s5/tmp/pip-build-wDUJoH/pycparser/pycparser/c_parser.pyt _pop_scopescCsE|jdj|ts0|jd||nt|jd||djjtj|j|dn|d|d abstract_declarator : direct_abstract_declarator iiN((R2R((s5/tmp/pip-build-wDUJoH/pycparser/pycparser/c_parser.pytp_abstract_declarator_3scCs|d|d labeled_statement : CASE constant_expression COLON statement iiiiN(RtCaseR(R2R((s5/tmp/pip-build-wDUJoH/pycparser/pycparser/c_parser.pytp_labeled_statement_2scCs-tj|dg|j|d|dtjd|d|j|d|dtjd|d|j|d|d s (