3 ÁÌ]m8ã@s<ddlZddlZddlmZddlmZGdd„deƒZdS)éN)Úlex)ÚTOKENc<@sleZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z �d Z iZ xd«Z?d¹dº„Z@d»ZAd¼ZBd½ZCd¾ZDd¿ZEdÀZFdÁZGdÂZHdÃZIdÄZJdÅZKdÆZLdÇZMdÈZNdÉZOdÊZPdËZQdÌZRdÍZSdÎZTdÏZUdÐZVdÑZWdÒZXdÓZYdÔZZdÕZ[dÖZ\d×Z]dØZ^dÙZ_dÚZ`dÛZadÜZbdÝZcdÞZddßZedàZfdáZgdâZhdãZidäZjdåZkdæZle2dçƒdèd鄃Zme2dêƒdëd섃Zne'Zoe2e,ƒdídZpe2e/ƒdïdð„ƒZqe2eƒdñdò„ƒZre2eƒdódô„ƒZse2eƒdõdö„ƒZte2eƒd÷dø„ƒZue2eƒdùdú„ƒZve2e"ƒdûdü„ƒZwe2e#ƒdýdþ„ƒZxe2e$ƒdÿ�d„ƒZye2e%ƒ�d�d„ƒZze2e(ƒ�d�d„ƒZ{e2e)ƒ�d�d„ƒZ|e2eƒ�d�d„ƒZ}�d �d „Z~�d S(ÚCLexera A lexer for the C language. After building it, set the input text with input(), and call token() to get new tokens. The public attribute filename can be set to an initial filaneme, but the lexer will update it upon #line directives. cCs@||_||_||_||_d|_d|_tjdƒ|_tjdƒ|_ dS)ab Create a new Lexer. error_func: An error function. Will be called with an error message, line and column as arguments, in case of an error during lexing. on_lbrace_func, on_rbrace_func: Called when an LBRACE or RBRACE is encountered (likely to push/pop type_lookup_func's scope) type_lookup_func: A type lookup function. Given a string, it must return True IFF this string is a name of a type that was defined with a typedef earlier. ÚNz([ ]*line\W)|([ ]*\d+)z [ ]*pragma\W) Ú error_funcÚon_lbrace_funcÚon_rbrace_funcÚtype_lookup_funcÚfilenameÚ last_tokenÚreÚcompileÚ line_patternÚpragma_pattern)Úselfrrrr ©rú/usr/lib/python3.6/c_lexer.pyÚ__init__s zCLexer.__init__cKstjfd|i|—Ž|_dS)zù Builds the lexer from the specification. Must be called after the lexer object is created. This method exists separately, because the PLY manual warns against calling lex.lex inside __init__ ÚobjectN)rÚlexer)rÚkwargsrrrÚbuild:sz CLexer.buildcCs d|j_dS)z? Resets the internal line number counter of the lexer. éN)rÚlineno)rrrrÚ reset_linenoDszCLexer.reset_linenocCs|jj|ƒdS)N)rÚinput)rÚtextrrrrIsz CLexer.inputcCs|jjƒ|_|jS)N)rÚtokenr )rrrrrLs z CLexer.tokencCs|jjjdd|jƒ}|j|S)z3 Find the column of the token in its line. Ú r)rÚlexdataÚrfindÚlexpos)rrZlast_crrrrÚfind_tok_columnPszCLexer.find_tok_columncCs0|j|ƒ}|j||d|dƒ|jjdƒdS)Nrr)Ú_make_tok_locationrrÚskip)rÚmsgrÚlocationrrrÚ_error[s z CLexer._errorcCs|j|j|ƒfS)N)rr")rrrrrr#`szCLexer._make_tok_locationÚ_BOOLÚ_COMPLEXÚAUTOÚBREAKÚCASEÚCHARÚCONSTÚCONTINUEÚDEFAULTÚDOÚDOUBLEÚELSEÚENUMÚEXTERNÚFLOATÚFORÚGOTOÚIFÚINLINEÚINTÚLONGÚREGISTERÚOFFSETOFÚRESTRICTÚRETURNÚSHORTÚSIGNEDÚSIZEOFÚSTATICÚSTRUCTÚSWITCHÚTYPEDEFÚUNIONÚUNSIGNEDÚVOIDÚVOLATILEÚWHILEZ_BoolZ_ComplexÚIDÚTYPEIDÚ INT_CONST_DECÚ INT_CONST_OCTÚ INT_CONST_HEXÚ INT_CONST_BINÚ FLOAT_CONSTÚHEX_FLOAT_CONSTÚ CHAR_CONSTÚ WCHAR_CONSTÚSTRING_LITERALÚWSTRING_LITERALÚPLUSÚMINUSÚTIMESÚDIVIDEÚMODÚORÚANDÚNOTÚXORÚLSHIFTÚRSHIFTÚLORÚLANDÚLNOTÚLTÚLEÚGTÚGEÚEQÚNEÚEQUALSÚ TIMESEQUALÚDIVEQUALÚMODEQUALÚ PLUSEQUALÚ MINUSEQUALÚ LSHIFTEQUALÚ RSHIFTEQUALÚANDEQUALÚXOREQUALÚOREQUALÚPLUSPLUSÚ MINUSMINUSÚARROWÚCONDOPÚLPARENÚRPARENÚLBRACKETÚRBRACKETÚLBRACEÚRBRACEÚCOMMAÚPERIODÚSEMIÚCOLONÚELLIPSISÚPPHASHz[a-zA-Z_$][0-9a-zA-Z_$]*z0[xX]z [0-9a-fA-F]+z0[bB]z[01]+zD(([uU]ll)|([uU]LL)|(ll[uU]?)|(LL[uU]?)|([uU][lL])|([lL][uU]?)|[uU])?z(0z)|([1-9][0-9]*ú)z0[0-7]*z 0[0-7]*[89]z([a-zA-Z._~!=&\^\-\\?'"])z(\d+)z(x[0-9a-fA-F]+)z#([\\][^a-zA-Z._~^!=&\^\-\\?'"x0-7])z(\\(ú|z))z ([^'\\\n]|ú'ÚLz('z*\n)|('z*$)z[^' ]+')|('')|('z [^'\n]*')z ([^"\\\n]|ú"z*"Ú*z([eE][-+]?[0-9]+)z([0-9]*\.[0-9]+)|([0-9]+\.)z((((z ?)|([0-9]+z ))[FfLl]?)z([pP][+-]?[0-9]+)z(((z)?\.z)|(z\.))ú(z[FfLl]?)ÚpplineÚ exclusiveÚpppragmacCsf|jj|jj|jjd�r2|jjdƒd|_|_n0|jj|jj|jjd�rX|jjdƒn d|_ |SdS)z[ \t]*\#)Úposr�Nr‘r‡) rÚmatchrrr!ÚbeginÚpp_lineÚ pp_filenamerÚtype)rÚtrrrÚt_PPHASHõs zCLexer.t_PPHASHcCs0|jdkr|jd|ƒn|jjdƒjdƒ|_dS)Nz$filename before line number in #linerŒ)r•r'ÚvalueÚlstripÚrstripr–)rr˜rrrÚt_ppline_FILENAMEs zCLexer.t_ppline_FILENAMEcCs|jdkr|j|_ndS)N)r•rš)rr˜rrrÚt_ppline_LINE_NUMBER s  zCLexer.t_ppline_LINE_NUMBERcCsH|jdkr|jd|ƒn t|jƒ|j_|jdk r8|j|_|jjdƒdS)z\nNzline number missing in #lineÚINITIAL)r•r'Úintrrr–r r”)rr˜rrrÚt_ppline_NEWLINEs   zCLexer.t_ppline_NEWLINEcCsdS)ÚlineNr)rr˜rrrÚt_ppline_PPLINE szCLexer.t_ppline_PPLINEz cCs|jd|ƒdS)Nzinvalid #line directive)r')rr˜rrrÚt_ppline_error&szCLexer.t_ppline_errorcCs |jjd7_|jjdƒdS)z\nrrŸN)rrr”)rr˜rrrÚt_pppragma_NEWLINE,szCLexer.t_pppragma_NEWLINEcCsdS)ZpragmaNr)rr˜rrrÚt_pppragma_PPPRAGMA1szCLexer.t_pppragma_PPPRAGMAz$ <>.-{}();=+-*/$%@&^~!?:,0123456789cCsdS)Nr)rr˜rrrÚt_pppragma_STR7szCLexer.t_pppragma_STRcCsdS)Nr)rr˜rrrÚ t_pppragma_ID:szCLexer.t_pppragma_IDcCs|jd|ƒdS)Nzinvalid #pragma directive)r')rr˜rrrÚt_pppragma_error=szCLexer.t_pppragma_errorcCs|jj|jjdƒ7_dS)z\n+rN)rrršÚcount)rr˜rrrÚ t_NEWLINEFszCLexer.t_NEWLINEz\+ú-z\*ú/ú%z\|ú&ú~z\^z<>z\|\|z&&ú!ú<ú>z<=z>=z==z!=ú=z\*=z/=z%=z\+=z-=z<<=z>>=z&=z\|=z\^=z\+\+z--z->z\?z\(z\)z\[z\]ú,z\.ú;ú:z\.\.\.z\{cCs |jƒ|S)N)r)rr˜rrrÚt_LBRACEŽszCLexer.t_LBRACEz\}cCs |jƒ|S)N)r)rr˜rrrÚt_RBRACE’szCLexer.t_RBRACEcCs|S)Nr)rr˜rrrÚ t_FLOAT_CONSTžszCLexer.t_FLOAT_CONSTcCs|S)Nr)rr˜rrrÚt_HEX_FLOAT_CONST¢szCLexer.t_HEX_FLOAT_CONSTcCs|S)Nr)rr˜rrrÚt_INT_CONST_HEX¦szCLexer.t_INT_CONST_HEXcCs|S)Nr)rr˜rrrÚt_INT_CONST_BINªszCLexer.t_INT_CONST_BINcCsd}|j||ƒdS)NzInvalid octal constant)r')rr˜r%rrrÚt_BAD_CONST_OCT®szCLexer.t_BAD_CONST_OCTcCs|S)Nr)rr˜rrrÚt_INT_CONST_OCT³szCLexer.t_INT_CONST_OCTcCs|S)Nr)rr˜rrrÚt_INT_CONST_DEC·szCLexer.t_INT_CONST_DECcCs|S)Nr)rr˜rrrÚ t_CHAR_CONST¾szCLexer.t_CHAR_CONSTcCs|S)Nr)rr˜rrrÚ t_WCHAR_CONSTÂszCLexer.t_WCHAR_CONSTcCsd}|j||ƒdS)Nz Unmatched ')r')rr˜r%rrrÚt_UNMATCHED_QUOTEÆszCLexer.t_UNMATCHED_QUOTEcCsd|j}|j||ƒdS)NzInvalid char constant %s)ršr')rr˜r%rrrÚt_BAD_CHAR_CONSTËs zCLexer.t_BAD_CHAR_CONSTcCs|S)Nr)rr˜rrrÚt_WSTRING_LITERALÐszCLexer.t_WSTRING_LITERALcCsd}|j||ƒdS)Nz#String contains invalid escape code)r')rr˜r%rrrÚt_BAD_STRING_LITERALÖszCLexer.t_BAD_STRING_LITERALcCs2|jj|jdƒ|_|jdkr.|j|jƒr.d|_|S)NrMrN)Ú keyword_mapÚgetršr—r )rr˜rrrÚt_IDÛsz CLexer.t_IDcCs"dt|jdƒ}|j||ƒdS)NzIllegal character %sr)Úreprršr')rr˜r%rrrÚt_errorâszCLexer.t_errorN)%r(r)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrCrDrErFrGrHrIrJrKrL);rMrNrOrPrQrRrSrTrUrVrWrXrYrZr[r\r]r^r_r`rarbrcrdrerfrgrhrirjrkrlrmrnrorprqrrrsrtrurvrwrxryrzr{r|r}r~rr€r�r‚rƒr„r…r†r‡©r�r�©r‘r�)rÌrÍ)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrr"r'r#ÚkeywordsrÇÚkeywordÚlowerÚtokensZ identifierZ hex_prefixZ hex_digitsZ bin_prefixZ bin_digitsZinteger_suffix_optZdecimal_constantZoctal_constantZ hex_constantZ bin_constantZbad_octal_constantZ simple_escapeZdecimal_escapeZ hex_escapeZ bad_escapeZescape_sequenceZ cconst_charZ char_constZ wchar_constZunmatched_quoteZbad_char_constZ string_charZstring_literalZwstring_literalZbad_string_literalZ exponent_partZfractional_constantZfloating_constantZbinary_exponent_partZhex_fractional_constantZhex_floating_constantZstatesr™rr�ržr¡r£Zt_ppline_ignorer¤r¥r¦Zt_pppragma_ignorer§r¨r©Zt_ignorer«Zt_PLUSZt_MINUSZt_TIMESZt_DIVIDEZt_MODZt_ORZt_ANDZt_NOTZt_XORZt_LSHIFTZt_RSHIFTZt_LORZt_LANDZt_LNOTZt_LTZt_GTZt_LEZt_GEZt_EQZt_NEZt_EQUALSZ t_TIMESEQUALZ t_DIVEQUALZ t_MODEQUALZ t_PLUSEQUALZ t_MINUSEQUALZ t_LSHIFTEQUALZ t_RSHIFTEQUALZ t_ANDEQUALZ t_OREQUALZ t_XOREQUALZ t_PLUSPLUSZ t_MINUSMINUSZt_ARROWZt_CONDOPZt_LPARENZt_RPARENZ t_LBRACKETZ t_RBRACKETZt_COMMAZt_PERIODZt_SEMIZt_COLONZ t_ELLIPSISr¸r¹Zt_STRING_LITERALrºr»r¼r½r¾r¿rÀrÁrÂrÃrÄrÅrÆrÉrËrrrrrs@!             $  r)r ÚsysZplyrZply.lexrrrrrrrÚ s