Your IP : 3.129.23.110
3
��]� � @ s� d dl Z d dlmZ ddlmZ ddlmZ ddlmZm Z m
Z
ddlmZ G dd � d e�Z
ed
kr|d dlZd dlZd dlZdS )� N)�yacc� )�c_ast)�CLexer)� PLYParser�Coord�
ParseError)�fix_switch_casesc
@ sD e Zd Z�dCdd�Z�dDd d
�Zdd� Zd
d� Zdd� Zdd� Zdd� Z dd� Z
dd� Zdd� Zdd� Z
dd� Zdd � Zd!d"� Zd#d$� Z�dEd%d&�Zd'd(� Zd)d*� Z�dPZd>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�dDŽ 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�� Zv�d �d� Zw�d�d� Zx�d�d� Zy�d�d� Zz�d�d � 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��d�d� 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��d,�d-� Z��d.�d/� Z��d0�d1� Z��d2�d3� Z��d4�d5� Z��d6�d7� Z��d8�d9� Z��d:�d;� Z��d<�d=� Z��d>�d?� Z��d@�dA� Z��dBS (Q �CParserT�pycparser.lextab�pycparser.yacctabF� c C s� t | j| j| j| jd�| _| jj|||d� | jj| _ddddddd d
ddd
dddg}x|D ]}| j|� q\W t 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)�optimize�lextab� outputdirZabstract_declaratorZassignment_expressionZdeclaration_listZdeclaration_specifiersZdesignationZ
expressionZidentifier_listZinit_declarator_listZinitializer_listZparameter_type_listZspecifier_qualifier_listZblock_item_listZtype_qualifier_listZstruct_declarator_listZtranslation_unit_or_empty)�module�start�debugr Z tabmoduler N)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) �selfZlex_optimizer Z
yacc_optimizeZyacctabZ
yacc_debugZtaboutputdirZrules_with_optZrule� r �/usr/lib/python3.6/c_parser.py�__init__ sF 5
zCParser.__init__r c C s6 || j _| j j� t� g| _d| _| jj|| j |d�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 �filenameZreset_linenor r r r �parse)r �textr# Z
debuglevelr r r r$ ~ s
z
CParser.parsec C s | j jt� � d S )N)r �appendr )r r r r �_push_scope� s zCParser._push_scopec C s t | j�dkst�| jj� d S )Nr )�lenr �AssertionError�pop)r r r r �
_pop_scope� s zCParser._pop_scopec C s4 | j d j|d�s"| jd| |� d| j d |<