{"id":990127,"date":"2024-12-27T08:17:35","date_gmt":"2024-12-27T00:17:35","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/990127.html"},"modified":"2024-12-27T08:17:37","modified_gmt":"2024-12-27T00:17:37","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e5%88%b6%e4%bd%9c%e8%af%ad%e8%a8%80","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/990127.html","title":{"rendered":"\u5982\u4f55\u7528python\u5236\u4f5c\u8bed\u8a00"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25064947\/04fe3c43-0839-45b7-9a8d-405cec6f5780.webp\" alt=\"\u5982\u4f55\u7528python\u5236\u4f5c\u8bed\u8a00\" \/><\/p>\n<p><p> <strong>\u5236\u4f5c\u4e00\u95e8\u7f16\u7a0b\u8bed\u8a00\u662f\u4e00\u9879\u590d\u6742\u7684\u4efb\u52a1\uff0c\u6d89\u53ca\u591a\u4e2a\u9886\u57df\u7684\u77e5\u8bc6\u3002\u4f7f\u7528Python\u5236\u4f5c\u8bed\u8a00\u7684\u6b65\u9aa4\u4e3b\u8981\u5305\u62ec\uff1a\u8bbe\u8ba1\u8bed\u8a00\u8bed\u6cd5\u3001\u7f16\u5199\u8bcd\u6cd5\u5206\u6790\u5668\u3001\u521b\u5efa\u8bed\u6cd5\u5206\u6790\u5668\u3001\u5b9e\u73b0\u89e3\u91ca\u5668\u6216\u7f16\u8bd1\u5668\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u63a2\u8ba8\u8fd9\u51e0\u4e2a\u6b65\u9aa4\uff0c\u5e76\u4e3a\u60a8\u63d0\u4f9b\u4e00\u4e9b\u5b9e\u73b0\u7684\u5efa\u8bae\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4e00\u3001\u8bbe\u8ba1\u8bed\u8a00\u8bed\u6cd5<\/p>\n<\/p>\n<p><p>\u8bbe\u8ba1\u8bed\u8a00\u7684\u8bed\u6cd5\u662f\u521b\u5efa\u7f16\u7a0b\u8bed\u8a00\u7684\u7b2c\u4e00\u6b65\u3002\u8bed\u6cd5\u5b9a\u4e49\u4e86\u7a0b\u5e8f\u5458\u5982\u4f55\u7f16\u5199\u4ee3\u7801\u4ee5\u4fbf\u8ba1\u7b97\u673a\u80fd\u591f\u7406\u89e3\u3002\u8bbe\u8ba1\u8bed\u8a00\u8bed\u6cd5\u9700\u8981\u8003\u8651\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\uff1a\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b\u3001\u8fd0\u7b97\u7b26\u548c\u8868\u8fbe\u5f0f\u3001\u63a7\u5236\u6d41\u8bed\u53e5\u3001\u51fd\u6570\u548c\u4f5c\u7528\u57df\u3001\u9519\u8bef\u5904\u7406\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u8bbe\u8ba1\u8bed\u8a00\u8bed\u6cd5\u65f6\uff0c\u9996\u5148\u9700\u8981\u5b9a\u4e49\u652f\u6301\u7684\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b\u3002\u6570\u636e\u7c7b\u578b\u53ef\u4ee5\u5305\u62ec\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u5b57\u7b26\u4e32\u3001\u5e03\u5c14\u503c\u7b49\u3002\u53d8\u91cf\u7684\u5b9a\u4e49\u548c\u4f7f\u7528\u65b9\u5f0f\u4e5f\u9700\u8981\u660e\u786e\u3002<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u7b80\u5355\u7684\u8bed\u8a00\uff0c\u53ef\u4ee5\u9009\u62e9\u52a8\u6001\u7c7b\u578b\u7684\u53d8\u91cf\uff0c\u8fd9\u6837\u53d8\u91cf\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u6539\u53d8\u6570\u636e\u7c7b\u578b\u3002\u5b9a\u4e49\u53d8\u91cf\u65f6\u9700\u8981\u89c4\u5b9a\u53d8\u91cf\u540d\u7684\u5408\u6cd5\u6027\uff0c\u4f8b\u5982\u53ea\u80fd\u4ee5\u5b57\u6bcd\u5f00\u5934\uff0c\u540e\u7eed\u53ef\u4ee5\u5305\u542b\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u7b97\u7b26\u548c\u8868\u8fbe\u5f0f<\/strong><\/p>\n<\/p>\n<p><p>\u8fd0\u7b97\u7b26\u7528\u4e8e\u5bf9\u6570\u636e\u8fdb\u884c\u64cd\u4f5c\uff0c\u5982\u7b97\u672f\u8fd0\u7b97\u7b26\uff08+\u3001-\u3001*\u3001\/\uff09\u3001\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff08==\u3001!=\u3001&lt;\u3001&gt;\uff09\u3001\u903b\u8f91\u8fd0\u7b97\u7b26\uff08&amp;&amp;\u3001||\u3001!\uff09\u7b49\u3002\u9700\u8981\u660e\u786e\u8fd0\u7b97\u7b26\u7684\u4f18\u5148\u7ea7\u548c\u7ed3\u5408\u6027\uff0c\u4ee5\u4fdd\u8bc1\u8868\u8fbe\u5f0f\u7684\u8ba1\u7b97\u987a\u5e8f\u6b63\u786e\u3002<\/p>\n<\/p>\n<p><p>\u8868\u8fbe\u5f0f\u7531\u53d8\u91cf\u3001\u5e38\u91cf\u548c\u8fd0\u7b97\u7b26\u7ec4\u6210\uff0c\u9700\u8981\u5b9a\u4e49\u5982\u4f55\u89e3\u6790\u548c\u8ba1\u7b97\u8868\u8fbe\u5f0f\u7684\u503c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u63a7\u5236\u6d41\u8bed\u53e5<\/strong><\/p>\n<\/p>\n<p><p>\u63a7\u5236\u6d41\u8bed\u53e5\u7528\u4e8e\u6539\u53d8\u7a0b\u5e8f\u7684\u6267\u884c\u8def\u5f84\uff0c\u5e38\u89c1\u7684\u5305\u62ec\u6761\u4ef6\u8bed\u53e5\uff08if-else\uff09\u3001\u5faa\u73af\u8bed\u53e5\uff08for\u3001while\uff09\u3001\u5206\u652f\u8bed\u53e5\uff08switch-case\uff09\u7b49\u3002\u9700\u8981\u5b9a\u4e49\u8fd9\u4e9b\u8bed\u53e5\u7684\u8bed\u6cd5\u7ed3\u6784\u548c\u4f5c\u7528\u8303\u56f4\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u6761\u4ef6\u8bed\u53e5\u7684\u8bed\u6cd5\u53ef\u4ee5\u89c4\u5b9a\u4e3a<code>if (condition) { statements } else { statements }<\/code>\uff0c\u5faa\u73af\u8bed\u53e5\u53ef\u4ee5\u89c4\u5b9a\u4e3a<code>while (condition) { statements }<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u51fd\u6570\u548c\u4f5c\u7528\u57df<\/strong><\/p>\n<\/p>\n<p><p>\u51fd\u6570\u662f\u7f16\u7a0b\u8bed\u8a00\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206\uff0c\u7528\u4e8e\u5c01\u88c5\u53ef\u91cd\u7528\u7684\u4ee3\u7801\u5757\u3002\u8bbe\u8ba1\u8bed\u8a00\u8bed\u6cd5\u65f6\u9700\u8981\u5b9a\u4e49\u51fd\u6570\u7684\u58f0\u660e\u3001\u8c03\u7528\u65b9\u5f0f\u4ee5\u53ca\u53c2\u6570\u4f20\u9012\u65b9\u5f0f\u3002\u51fd\u6570\u7684\u4f5c\u7528\u57df\u89c4\u5219\u4e5f\u9700\u8981\u660e\u786e\uff0c\u4f8b\u5982\u5c40\u90e8\u53d8\u91cf\u548c\u5168\u5c40\u53d8\u91cf\u7684\u4f7f\u7528\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u51fd\u6570\u7684\u58f0\u660e\u53ef\u4ee5\u89c4\u5b9a\u4e3a<code>function_name(parameters) { statements }<\/code>\uff0c\u8c03\u7528\u65b9\u5f0f\u53ef\u4ee5\u662f<code>function_name(arguments)<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9519\u8bef\u5904\u7406<\/strong><\/p>\n<\/p>\n<p><p>\u7f16\u7a0b\u8bed\u8a00\u9700\u8981\u652f\u6301\u9519\u8bef\u5904\u7406\u673a\u5236\uff0c\u4ee5\u4fbf\u5728\u8fd0\u884c\u65f6\u6355\u83b7\u548c\u5904\u7406\u5f02\u5e38\u60c5\u51b5\u3002\u8bbe\u8ba1\u8bed\u8a00\u8bed\u6cd5\u65f6\u9700\u8981\u5b9a\u4e49\u9519\u8bef\u5904\u7406\u7684\u8bed\u6cd5\u548c\u673a\u5236\uff0c\u4f8b\u5982\u4f7f\u7528<code>try-catch<\/code>\u8bed\u53e5\u6765\u6355\u83b7\u548c\u5904\u7406\u5f02\u5e38\u3002<\/p>\n<\/p>\n<p><p>\u9519\u8bef\u5904\u7406\u7684\u673a\u5236\u53ef\u4ee5\u5305\u62ec\u629b\u51fa\u5f02\u5e38\u3001\u6355\u83b7\u5f02\u5e38\u548c\u5904\u7406\u5f02\u5e38\u7b49\u6b65\u9aa4\uff0c\u9700\u8981\u660e\u786e\u5f02\u5e38\u7684\u7c7b\u578b\u548c\u5904\u7406\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u7f16\u5199\u8bcd\u6cd5\u5206\u6790\u5668<\/p>\n<\/p>\n<p><p>\u8bcd\u6cd5\u5206\u6790\u5668\u7684\u4f5c\u7528\u662f\u5c06\u6e90\u4ee3\u7801\u8f6c\u6362\u4e3a\u4e00\u7cfb\u5217\u7684\u6807\u8bb0\uff08Token\uff09\uff0c\u8fd9\u4e9b\u6807\u8bb0\u662f\u8bed\u6cd5\u5206\u6790\u5668\u7684\u8f93\u5165\u3002\u8bcd\u6cd5\u5206\u6790\u5668\u7684\u5b9e\u73b0\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6216\u624b\u52a8\u7f16\u5199\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b9a\u4e49\u6807\u8bb0\u7c7b\u578b<\/strong><\/p>\n<\/p>\n<p><p>\u9996\u5148\u9700\u8981\u5b9a\u4e49\u7a0b\u5e8f\u4e2d\u53ef\u80fd\u51fa\u73b0\u7684\u6807\u8bb0\u7c7b\u578b\uff0c\u4f8b\u5982\u6807\u8bc6\u7b26\u3001\u5173\u952e\u5b57\u3001\u8fd0\u7b97\u7b26\u3001\u5206\u9694\u7b26\u3001\u6570\u5b57\u548c\u5b57\u7b26\u4e32\u5e38\u91cf\u7b49\u3002\u6bcf\u79cd\u6807\u8bb0\u7c7b\u578b\u90fd\u9700\u8981\u6709\u4e00\u4e2a\u552f\u4e00\u7684\u6807\u8bc6\u7b26\uff0c\u7528\u4e8e\u533a\u5206\u4e0d\u540c\u7c7b\u578b\u7684\u6807\u8bb0\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u6807\u8bc6\u7b26\u53ef\u4ee5\u5b9a\u4e49\u4e3a\u4ee5\u5b57\u6bcd\u5f00\u5934\u7684\u5b57\u6bcd\u6570\u5b57\u5e8f\u5217\uff0c\u5173\u952e\u5b57\u53ef\u4ee5\u5b9a\u4e49\u4e3a<code>if<\/code>\u3001<code>else<\/code>\u3001<code>while<\/code>\u7b49\u4fdd\u7559\u5b57\uff0c\u8fd0\u7b97\u7b26\u53ef\u4ee5\u5b9a\u4e49\u4e3a<code>+<\/code>\u3001<code>-<\/code>\u3001<code>*<\/code>\u3001<code>\/<\/code>\u7b49\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong><\/p>\n<\/p>\n<p><p>\u8bcd\u6cd5\u5206\u6790\u5668\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u5339\u914d\u6e90\u4ee3\u7801\u4e2d\u7684\u6807\u8bb0\u3002\u6bcf\u79cd\u6807\u8bb0\u7c7b\u578b\u90fd\u53ef\u4ee5\u6709\u4e00\u4e2a\u5bf9\u5e94\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u7528\u4e8e\u5339\u914d\u8be5\u7c7b\u578b\u7684\u6807\u8bb0\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u6807\u8bc6\u7b26\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u5b9a\u4e49\u4e3a<code>[a-zA-Z_][a-zA-Z0-9_]*<\/code>\uff0c\u6570\u5b57\u5e38\u91cf\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u53ef\u4ee5\u5b9a\u4e49\u4e3a<code>\\d+(\\.\\d+)?<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u89e3\u6790\u6e90\u4ee3\u7801<\/strong><\/p>\n<\/p>\n<p><p>\u8bcd\u6cd5\u5206\u6790\u5668\u9700\u8981\u9010\u5b57\u7b26\u5730\u89e3\u6790\u6e90\u4ee3\u7801\uff0c\u5e76\u6839\u636e\u5b9a\u4e49\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u5c06\u6e90\u4ee3\u7801\u5206\u5272\u6210\u4e00\u7cfb\u5217\u7684\u6807\u8bb0\u3002\u89e3\u6790\u8fc7\u7a0b\u4e2d\u9700\u8981\u5ffd\u7565\u7a7a\u767d\u5b57\u7b26\u548c\u6ce8\u91ca\uff0c\u786e\u4fdd\u53ea\u63d0\u53d6\u6709\u6548\u7684\u6807\u8bb0\u3002<\/p>\n<\/p>\n<p><p>\u89e3\u6790\u7684\u7ed3\u679c\u662f\u4e00\u4e2a\u6807\u8bb0\u5e8f\u5217\uff0c\u6bcf\u4e2a\u6807\u8bb0\u5305\u542b\u6807\u8bb0\u7c7b\u578b\u3001\u6807\u8bb0\u503c\u548c\u5728\u6e90\u4ee3\u7801\u4e2d\u7684\u4f4d\u7f6e\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5904\u7406\u9519\u8bef<\/strong><\/p>\n<\/p>\n<p><p>\u8bcd\u6cd5\u5206\u6790\u5668\u9700\u8981\u5904\u7406\u89e3\u6790\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u51fa\u73b0\u7684\u9519\u8bef\uff0c\u4f8b\u5982\u9047\u5230\u65e0\u6cd5\u8bc6\u522b\u7684\u5b57\u7b26\u6216\u4e0d\u5339\u914d\u7684\u5f15\u53f7\u3002\u9519\u8bef\u5904\u7406\u53ef\u4ee5\u5305\u62ec\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\u3001\u63d0\u793a\u9519\u8bef\u4f4d\u7f6e\u548c\u7c7b\u578b\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u5728\u9047\u5230\u9519\u8bef\u65f6\uff0c\u8bcd\u6cd5\u5206\u6790\u5668\u53ef\u4ee5\u9009\u62e9\u8df3\u8fc7\u9519\u8bef\u90e8\u5206\u7ee7\u7eed\u89e3\u6790\uff0c\u6216\u8005\u7ec8\u6b62\u89e3\u6790\u5e76\u8fd4\u56de\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u521b\u5efa\u8bed\u6cd5\u5206\u6790\u5668<\/p>\n<\/p>\n<p><p>\u8bed\u6cd5\u5206\u6790\u5668\u8d1f\u8d23\u5c06\u8bcd\u6cd5\u5206\u6790\u5668\u751f\u6210\u7684\u6807\u8bb0\u5e8f\u5217\u89e3\u6790\u4e3a\u62bd\u8c61\u8bed\u6cd5\u6811\uff08AST\uff09\u3002\u62bd\u8c61\u8bed\u6cd5\u6811\u662f\u7a0b\u5e8f\u7684\u7ed3\u6784\u5316\u8868\u793a\uff0c\u4fbf\u4e8e\u540e\u7eed\u7684\u89e3\u91ca\u6216\u7f16\u8bd1\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b9a\u4e49\u8bed\u6cd5\u89c4\u5219<\/strong><\/p>\n<\/p>\n<p><p>\u8bed\u6cd5\u5206\u6790\u5668\u7684\u5b9e\u73b0\u9700\u8981\u57fa\u4e8e\u4e0a\u4e0b\u6587\u65e0\u5173\u6587\u6cd5\uff08CFG\uff09\uff0c\u8be5\u6587\u6cd5\u5b9a\u4e49\u4e86\u8bed\u8a00\u7684\u8bed\u6cd5\u89c4\u5219\u3002\u8bed\u6cd5\u89c4\u5219\u901a\u5e38\u4ee5\u5df4\u79d1\u65af-\u7459\u5c14\u8303\u5f0f\uff08BNF\uff09\u6216\u6269\u5c55\u5df4\u79d1\u65af-\u7459\u5c14\u8303\u5f0f\uff08EBNF\uff09\u8868\u793a\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u7b80\u5355\u7b97\u672f\u8868\u8fbe\u5f0f\u7684\u8bed\u6cd5\u89c4\u5219\u53ef\u4ee5\u5b9a\u4e49\u4e3a\uff1a<\/p>\n<\/p>\n<p><pre><code>expression ::= term ((PLUS | MINUS) term)*<\/p>\n<p>term       ::= factor ((MUL | DIV) factor)*<\/p>\n<p>factor     ::= NUMBER | LPAREN expression RPAREN<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9012\u5f52\u4e0b\u964d\u89e3\u6790<\/strong><\/p>\n<\/p>\n<p><p>\u9012\u5f52\u4e0b\u964d\u89e3\u6790\u662f\u4e00\u79cd\u5e38\u7528\u7684\u8bed\u6cd5\u5206\u6790\u6280\u672f\uff0c\u9002\u7528\u4e8eLL(1)\u6587\u6cd5\u3002\u89e3\u6790\u5668\u7531\u4e00\u7ec4\u9012\u5f52\u51fd\u6570\u7ec4\u6210\uff0c\u6bcf\u4e2a\u51fd\u6570\u5bf9\u5e94\u4e00\u4e2a\u8bed\u6cd5\u89c4\u5219\u3002<\/p>\n<\/p>\n<p><p>\u89e3\u6790\u8fc7\u7a0b\u4ece\u8d77\u59cb\u7b26\u53f7\u5f00\u59cb\uff0c\u6839\u636e\u8f93\u5165\u6807\u8bb0\u7684\u7c7b\u578b\u8c03\u7528\u76f8\u5e94\u7684\u51fd\u6570\uff0c\u5e76\u6784\u5efa\u62bd\u8c61\u8bed\u6cd5\u6811\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5904\u7406\u8bed\u6cd5\u9519\u8bef<\/strong><\/p>\n<\/p>\n<p><p>\u8bed\u6cd5\u5206\u6790\u5668\u9700\u8981\u5904\u7406\u89e3\u6790\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u51fa\u73b0\u7684\u8bed\u6cd5\u9519\u8bef\uff0c\u4f8b\u5982\u7f3a\u5c11\u62ec\u53f7\u3001\u8fd0\u7b97\u7b26\u4e0d\u5339\u914d\u7b49\u3002\u9519\u8bef\u5904\u7406\u53ef\u4ee5\u5305\u62ec\u8bb0\u5f55\u9519\u8bef\u4fe1\u606f\u3001\u63d0\u793a\u9519\u8bef\u4f4d\u7f6e\u548c\u7c7b\u578b\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u5728\u9047\u5230\u9519\u8bef\u65f6\uff0c\u8bed\u6cd5\u5206\u6790\u5668\u53ef\u4ee5\u9009\u62e9\u8df3\u8fc7\u9519\u8bef\u90e8\u5206\u7ee7\u7eed\u89e3\u6790\uff0c\u6216\u8005\u7ec8\u6b62\u89e3\u6790\u5e76\u8fd4\u56de\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u5b9e\u73b0\u89e3\u91ca\u5668\u6216\u7f16\u8bd1\u5668<\/p>\n<\/p>\n<p><p>\u89e3\u91ca\u5668\u6216\u7f16\u8bd1\u5668\u8d1f\u8d23\u6267\u884c\u6216\u7ffb\u8bd1\u62bd\u8c61\u8bed\u6cd5\u6811\u3002\u89e3\u91ca\u5668\u76f4\u63a5\u6267\u884cAST\uff0c\u7f16\u8bd1\u5668\u5c06AST\u7ffb\u8bd1\u4e3a\u76ee\u6807\u4ee3\u7801\uff08\u5982\u5b57\u8282\u7801\u6216\u673a\u5668\u7801\uff09\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u8bbe\u8ba1\u62bd\u8c61\u8bed\u6cd5\u6811\u7684\u7ed3\u6784<\/strong><\/p>\n<\/p>\n<p><p>\u62bd\u8c61\u8bed\u6cd5\u6811\u7531\u8282\u70b9\u7ec4\u6210\uff0c\u6bcf\u4e2a\u8282\u70b9\u8868\u793a\u7a0b\u5e8f\u4e2d\u7684\u4e00\u4e2a\u7ed3\u6784\u5355\u5143\uff08\u5982\u8868\u8fbe\u5f0f\u3001\u8bed\u53e5\u3001\u51fd\u6570\u7b49\uff09\u3002\u8282\u70b9\u7684\u8bbe\u8ba1\u9700\u8981\u8003\u8651\u5982\u4f55\u8868\u793a\u4e0d\u540c\u7c7b\u578b\u7684\u7ed3\u6784\u5355\u5143\u53ca\u5176\u5c5e\u6027\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u4e8c\u5143\u8fd0\u7b97\u7684\u8282\u70b9\u53ef\u4ee5\u5305\u542b\u5de6\u64cd\u4f5c\u6570\u3001\u53f3\u64cd\u4f5c\u6570\u548c\u8fd0\u7b97\u7b26\uff0c\u51fd\u6570\u8c03\u7528\u7684\u8282\u70b9\u53ef\u4ee5\u5305\u542b\u51fd\u6570\u540d\u548c\u53c2\u6570\u5217\u8868\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b9e\u73b0\u89e3\u91ca\u5668<\/strong><\/p>\n<\/p>\n<p><p>\u89e3\u91ca\u5668\u9700\u8981\u904d\u5386\u62bd\u8c61\u8bed\u6cd5\u6811\uff0c\u5e76\u6839\u636e\u8282\u70b9\u7684\u7c7b\u578b\u6267\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\u3002\u89e3\u91ca\u5668\u901a\u5e38\u5305\u62ec\u4e00\u4e2a\u6216\u591a\u4e2a\u7528\u4e8e\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u8282\u70b9\u7684\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><p>\u5728\u89e3\u91ca\u8fc7\u7a0b\u4e2d\uff0c\u89e3\u91ca\u5668\u9700\u8981\u7ef4\u62a4\u7a0b\u5e8f\u7684\u8fd0\u884c\u73af\u5883\uff0c\u5305\u62ec\u53d8\u91cf\u7684\u503c\u3001\u51fd\u6570\u7684\u8c03\u7528\u6808\u7b49\u3002\u89e3\u91ca\u5668\u7684\u5b9e\u73b0\u9700\u8981\u8003\u8651\u7a0b\u5e8f\u7684\u6267\u884c\u987a\u5e8f\u3001\u4f5c\u7528\u57df\u89c4\u5219\u548c\u9519\u8bef\u5904\u7406\u673a\u5236\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b9e\u73b0\u7f16\u8bd1\u5668<\/strong><\/p>\n<\/p>\n<p><p>\u7f16\u8bd1\u5668\u9700\u8981\u5c06\u62bd\u8c61\u8bed\u6cd5\u6811\u7ffb\u8bd1\u4e3a\u76ee\u6807\u4ee3\u7801\u3002\u7f16\u8bd1\u5668\u7684\u5b9e\u73b0\u901a\u5e38\u5305\u62ec\u524d\u7aef\u548c\u540e\u7aef\u4e24\u4e2a\u90e8\u5206\uff0c\u524d\u7aef\u8d1f\u8d23\u8bed\u6cd5\u5206\u6790\u548c\u8bed\u4e49\u68c0\u67e5\uff0c\u540e\u7aef\u8d1f\u8d23\u4ee3\u7801\u751f\u6210\u548c\u4f18\u5316\u3002<\/p>\n<\/p>\n<p><p>\u7f16\u8bd1\u5668\u9700\u8981\u8003\u8651\u76ee\u6807\u4ee3\u7801\u7684\u6027\u80fd\u3001\u517c\u5bb9\u6027\u548c\u53ef\u79fb\u690d\u6027\u3002\u76ee\u6807\u4ee3\u7801\u53ef\u4ee5\u662f\u5b57\u8282\u7801\u3001\u6c47\u7f16\u4ee3\u7801\u6216\u673a\u5668\u7801\uff0c\u6839\u636e\u76ee\u6807\u5e73\u53f0\u7684\u4e0d\u540c\u8fdb\u884c\u9009\u62e9\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u6d4b\u8bd5\u548c\u4f18\u5316<\/p>\n<\/p>\n<p><p>\u7f16\u7a0b\u8bed\u8a00\u7684\u5b9e\u73b0\u9700\u8981\u7ecf\u8fc7\u5145\u5206\u7684\u6d4b\u8bd5\u548c\u4f18\u5316\uff0c\u4ee5\u786e\u4fdd\u5176\u529f\u80fd\u6b63\u786e\u3001\u6027\u80fd\u826f\u597d\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7f16\u5199\u6d4b\u8bd5\u7528\u4f8b<\/strong><\/p>\n<\/p>\n<p><p>\u6d4b\u8bd5\u7528\u4f8b\u7528\u4e8e\u9a8c\u8bc1\u8bed\u8a00\u7684\u529f\u80fd\u548c\u6027\u80fd\u3002\u6d4b\u8bd5\u7528\u4f8b\u53ef\u4ee5\u5305\u62ec\u8bed\u6cd5\u89e3\u6790\u3001\u8868\u8fbe\u5f0f\u8ba1\u7b97\u3001\u63a7\u5236\u6d41\u3001\u51fd\u6570\u8c03\u7528\u3001\u9519\u8bef\u5904\u7406\u7b49\u4e0d\u540c\u65b9\u9762\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd0\u884c\u6d4b\u8bd5\u7528\u4f8b\uff0c\u53ef\u4ee5\u53d1\u73b0\u8bed\u8a00\u5b9e\u73b0\u4e2d\u7684\u9519\u8bef\u548c\u4e0d\u8db3\uff0c\u5e76\u8fdb\u884c\u76f8\u5e94\u7684\u4fee\u6b63\u548c\u6539\u8fdb\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f18\u5316\u6027\u80fd<\/strong><\/p>\n<\/p>\n<p><p>\u6027\u80fd\u4f18\u5316\u662f\u7f16\u7a0b\u8bed\u8a00\u5b9e\u73b0\u7684\u91cd\u8981\u73af\u8282\u3002\u53ef\u4ee5\u901a\u8fc7\u4f18\u5316\u8bcd\u6cd5\u5206\u6790\u3001\u8bed\u6cd5\u5206\u6790\u3001\u4ee3\u7801\u751f\u6210\u548c\u6267\u884c\u8fc7\u7a0b\u6765\u63d0\u9ad8\u8bed\u8a00\u7684\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u66f4\u9ad8\u6548\u7684\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\uff0c\u63d0\u9ad8\u89e3\u6790\u548c\u6267\u884c\u7684\u901f\u5ea6\uff1b\u53ef\u4ee5\u901a\u8fc7\u4ee3\u7801\u4f18\u5316\u6280\u672f\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97\u548c\u5185\u5b58\u4f7f\u7528\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b8c\u5584\u6587\u6863\u548c\u793a\u4f8b<\/strong><\/p>\n<\/p>\n<p><p>\u5b8c\u5584\u7684\u6587\u6863\u548c\u793a\u4f8b\u6709\u52a9\u4e8e\u7528\u6237\u7406\u89e3\u548c\u4f7f\u7528\u7f16\u7a0b\u8bed\u8a00\u3002\u6587\u6863\u53ef\u4ee5\u5305\u62ec\u8bed\u8a00\u7684\u8bed\u6cd5\u89c4\u5219\u3001\u4f7f\u7528\u65b9\u6cd5\u3001\u793a\u4f8b\u7a0b\u5e8f\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u63d0\u4f9b\u793a\u4f8b\u7a0b\u5e8f\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u5feb\u901f\u4e0a\u624b\uff0c\u5e76\u9a8c\u8bc1\u8bed\u8a00\u7684\u529f\u80fd\u548c\u7279\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516d\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u4f7f\u7528Python\u5236\u4f5c\u7f16\u7a0b\u8bed\u8a00\u662f\u4e00\u9879\u6311\u6218\u6027\u548c\u521b\u9020\u6027\u7684\u4efb\u52a1\uff0c\u9700\u8981\u6df1\u5165\u7406\u89e3\u7f16\u7a0b\u8bed\u8a00\u7684\u8bbe\u8ba1\u548c\u5b9e\u73b0\u539f\u7406\u3002\u901a\u8fc7\u8bbe\u8ba1\u8bed\u8a00\u8bed\u6cd5\u3001\u7f16\u5199\u8bcd\u6cd5\u5206\u6790\u5668\u3001\u521b\u5efa\u8bed\u6cd5\u5206\u6790\u5668\u3001\u5b9e\u73b0\u89e3\u91ca\u5668\u6216\u7f16\u8bd1\u5668\uff0c\u5e76\u8fdb\u884c\u6d4b\u8bd5\u548c\u4f18\u5316\uff0c\u60a8\u53ef\u4ee5\u521b\u5efa\u51fa\u4e00\u95e8\u529f\u80fd\u5b8c\u6574\u7684\u7f16\u7a0b\u8bed\u8a00\u3002\u5e0c\u671b\u672c\u6587\u80fd\u591f\u4e3a\u60a8\u63d0\u4f9b\u6709\u4ef7\u503c\u7684\u6307\u5bfc\u548c\u542f\u53d1\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5f00\u59cb\u4f7f\u7528Python\u5f00\u53d1\u81ea\u5df1\u7684\u7f16\u7a0b\u8bed\u8a00\uff1f<\/strong><br \/>\u5728\u4f7f\u7528Python\u5236\u4f5c\u81ea\u5df1\u7684\u7f16\u7a0b\u8bed\u8a00\u4e4b\u524d\uff0c\u4e86\u89e3\u7f16\u7a0b\u8bed\u8a00\u7684\u57fa\u672c\u6784\u6210\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u60a8\u53ef\u4ee5\u4ece\u5b9a\u4e49\u8bcd\u6cd5\u5206\u6790\u5668\u548c\u8bed\u6cd5\u5206\u6790\u5668\u5f00\u59cb\uff0c\u8fd9\u901a\u5e38\u662f\u7f16\u7a0b\u8bed\u8a00\u8bbe\u8ba1\u7684\u7b2c\u4e00\u6b65\u3002\u63a8\u8350\u4f7f\u7528Python\u7684\u73b0\u6709\u5e93\uff0c\u5982PLY\uff08Python Lex-Yacc\uff09\u6216ANTLR\uff0c\u6765\u5e2e\u52a9\u60a8\u5b9e\u73b0\u8fd9\u4e9b\u529f\u80fd\u3002\u6b64\u5916\uff0c\u4e86\u89e3\u5982\u4f55\u5c06\u60a8\u7684\u8bed\u8a00\u7f16\u8bd1\u6210\u5b57\u8282\u7801\u6216\u89e3\u91ca\u6267\u884c\u4e5f\u662f\u5173\u952e\u3002<\/p>\n<p><strong>\u5236\u4f5c\u8bed\u8a00\u7684\u8fc7\u7a0b\u4e2d\u9700\u8981\u638c\u63e1\u54ea\u4e9bPython\u77e5\u8bc6\uff1f<\/strong><br \/>\u5728\u5236\u4f5c\u81ea\u5df1\u7684\u7f16\u7a0b\u8bed\u8a00\u65f6\uff0c\u60a8\u9700\u8981\u719f\u6089Python\u7684\u57fa\u672c\u8bed\u6cd5\u3001\u6570\u636e\u7ed3\u6784\u4ee5\u53ca\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u6982\u5ff5\u3002\u6b64\u5916\uff0c\u638c\u63e1\u5982\u4f55\u5904\u7406\u6587\u4ef6\u8f93\u5165\u8f93\u51fa\u3001\u5f02\u5e38\u5904\u7406\u548c\u6a21\u5757\u5316\u7f16\u7a0b\u4e5f\u5c06\u6709\u52a9\u4e8e\u60a8\u5728\u8bed\u8a00\u5f00\u53d1\u4e2d\u7ec4\u7ec7\u4ee3\u7801\u548c\u5904\u7406\u9519\u8bef\u3002\u6df1\u5165\u7406\u89e3Python\u7684\u5185\u5b58\u7ba1\u7406\u548c\u6267\u884c\u6a21\u578b\u4e5f\u80fd\u4e3a\u60a8\u63d0\u4f9b\u66f4\u6df1\u7684\u89c1\u89e3\u3002<\/p>\n<p><strong>\u5f00\u53d1\u8bed\u8a00\u65f6\u5982\u4f55\u8fdb\u884c\u6d4b\u8bd5\u548c\u8c03\u8bd5\uff1f<\/strong><br \/>\u5728\u5f00\u53d1\u8bed\u8a00\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6d4b\u8bd5\u548c\u8c03\u8bd5\u662f\u786e\u4fdd\u8bed\u8a00\u529f\u80fd\u6b63\u5e38\u7684\u5173\u952e\u6b65\u9aa4\u3002\u60a8\u53ef\u4ee5\u7f16\u5199\u5355\u5143\u6d4b\u8bd5\u6765\u9a8c\u8bc1\u6bcf\u4e2a\u529f\u80fd\u6a21\u5757\u7684\u6b63\u786e\u6027\uff0c\u4f7f\u7528Python\u7684unittest\u6846\u67b6\u6765\u8f85\u52a9\u6d4b\u8bd5\u3002\u540c\u65f6\uff0c\u8c03\u8bd5\u5de5\u5177\u5982pdb\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u5b9a\u4f4d\u548c\u89e3\u51b3\u4ee3\u7801\u4e2d\u7684\u95ee\u9898\u3002\u5efa\u8bae\u5c06\u6d4b\u8bd5\u4e0e\u8bed\u8a00\u5f00\u53d1\u540c\u6b65\u8fdb\u884c\uff0c\u4ee5\u4fbf\u66f4\u5feb\u53d1\u73b0\u6f5c\u5728\u7684\u9519\u8bef\u548c\u6539\u8fdb\u70b9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5236\u4f5c\u4e00\u95e8\u7f16\u7a0b\u8bed\u8a00\u662f\u4e00\u9879\u590d\u6742\u7684\u4efb\u52a1\uff0c\u6d89\u53ca\u591a\u4e2a\u9886\u57df\u7684\u77e5\u8bc6\u3002\u4f7f\u7528Python\u5236\u4f5c\u8bed\u8a00\u7684\u6b65\u9aa4\u4e3b\u8981\u5305\u62ec\uff1a\u8bbe\u8ba1\u8bed\u8a00\u8bed\u6cd5\u3001\u7f16 [&hellip;]","protected":false},"author":3,"featured_media":990134,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/990127"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=990127"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/990127\/revisions"}],"predecessor-version":[{"id":990136,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/990127\/revisions\/990136"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/990134"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=990127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=990127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=990127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}