{"id":9588,"date":"2024-01-01T11:06:00","date_gmt":"2024-01-01T03:06:00","guid":{"rendered":"https:\/\/www.orczhou.com\/?p=9588"},"modified":"2024-08-13T11:09:50","modified_gmt":"2024-08-13T03:09:50","slug":"flex-bison-3-a-sophisticated-program-part-1","status":"publish","type":"post","link":"https:\/\/www.orczhou.com\/index.php\/2024\/01\/flex-bison-3-a-sophisticated-program-part-1\/","title":{"rendered":"flex\/bison\u7cfb\u52173\uff1a\u66f4\u590d\u6742\u7684\u4e00\u4e2a\u7f16\u8bd1\u7a0b\u5e8f\u5b9e\u73b0\uff08\u4e0a\uff09"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">\u5f15\u8a00<\/h4>\n\n\n\n<p>\u8fd9\u662f\u4e00\u4e2a\u7cfb\u5217\u6587\u7ae0\uff0c\u65e8\u5728\u4e86\u89e3\u5982\u4f55\u4f7f\u7528Flex\/Lex\u548cYacc\/Bison\u8fdb\u884c\u8bcd\u6cd5\u548c\u8bed\u6cd5\u89e3\u6790\u3002\u5728\u524d\u9762\uff0c\u5df2\u7ecf\u5b8c\u6210\u4e86<a href=\"https:\/\/www.orczhou.com\/index.php\/2023\/11\/learning-flex-bison-01\/\" data-type=\"link\" data-id=\"https:\/\/www.orczhou.com\/index.php\/2023\/11\/learning-flex-bison-01\/\">\u4f7f\u7528Lex\/flex\u505a\u57fa\u7840\u7684\u8bcd\u6cd5\u89e3\u6790<\/a>\u3001<a href=\"https:\/\/www.orczhou.com\/index.php\/2023\/11\/using-yacc-bison-for-grammer\/\" data-type=\"link\" data-id=\"https:\/\/www.orczhou.com\/index.php\/2023\/11\/using-yacc-bison-for-grammer\/\">\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684\u8ba1\u7b97\u5668<\/a>\u3002\u5f00\u59cb\u8fd9\u4e2a\u7cfb\u5217\u7684\u7b2c\u4e09\u90e8\u5206\uff0c\u4f7f\u7528flex\u548cbison\u5b8c\u6210\u4e00\u4e2a\u66f4\u52a0\u590d\u6742\u7684\u7684\u7f16\u8bd1\u7a0b\u5e8f\u3002\u6574\u4f53\u4e0a\u6709\u4e00\u5b9a\u7684\u590d\u6742\u5ea6\uff0c\u6240\u4ee5\u5206\u4e0a\u4e0b\u7bc7\u5206\u522b\u4ecb\u7ecd\u3002\u4e0a\u7bc7\u4ecb\u7ecd\uff1a\u5b9e\u73b0\u6982\u8981\u3001\u8bed\u6cd5\u3001\uff0c\u4e0b\u7bc7\u4ecb\u7ecd\u6570\u636e\u7ed3\u6784\u4e0e\u5b9e\u73b0\uff08\u5305\u62ec\u89e3\u6790\u6811\u5b9e\u73b0\u3001\u6267\u884c\uff09\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e0b\u7bc7\u4ecb\u7ecd\uff1a\u6570\u636e\u7ed3\u6784\u4e0e\u5b9e\u73b0\n<ul class=\"wp-block-list\">\n<li>\u4e0eGrammar\u5bf9\u5e94\u7684\u201c\u89e3\u6790\u6811\u201d<\/li>\n\n\n\n<li>\u201c\u89e3\u6790\u6811\u201d\u7684\u6267\u884c<\/li>\n\n\n\n<li>\u89e3\u6790\u6811\u7684\u8282\u70b9\uff0cTerminals \u548c Non-Terminals<\/li>\n\n\n\n<li>\u4e00\u4e2a\u201c\u7b80\u5355\u8bed\u53e5\u201d\u7684\u89e3\u6790\u6811\u7ed3\u6784<\/li>\n\n\n\n<li>\u4e00\u4e2a\u201c\u7565\u5fae\u590d\u6742\u8bed\u53e5\u201d\u7684\u89e3\u6790\u6811\u7ed3\u6784<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u89e3\u6790\u4e0e\u6267\u884c\u5305\u542b\u8d4b\u503c\u3001IF\u3001WHILE\u7b49\u8bed\u53e5\u7684\u7a0b\u5e8f<\/h4>\n\n\n\n<p>\u5728\u524d\u9762\u7684\u6848\u4f8b\u4e2d\uff0c\u6211\u4eec\u5b9e\u73b0\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u52a0\u51cf\u4e58\u8fd0\u7b97\u7684\u8ba1\u7b97\u5668\u7a0b\u5e8f\u3002\u8fd9\u91cc\u6211\u4eec\u5c1d\u8bd5\u5b9e\u73b0\u4e00\u4e2a\u66f4\u590d\u6742\u4e00\u4e9b\u7684\u7f16\u8bd1\u7a0b\u5e8f\uff0c\u8bed\u6cd5\u80fd\u591f\u652f\u6301\u5982\u4e0b\u5185\u5bb9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5305\u542b\u4e86\u53d8\u91cf\uff0c\u53ef\u4ee5\u5bf9\u53d8\u91cf\u8d4b\u503c\uff0c\u4e5f\u53ef\u4ee5\u5728\u8868\u8fbe\u5f0f\u4e2d\u4f7f\u7528\u53d8\u91cf\u3002\u4f46\u662f\u4e3a\u4e86\u7b80\u5316\u7a0b\u5e8f\uff0c\u8fd9\u91cc\u53d8\u91cf\u4ec5\u9650\u4e8e\u4f7f\u7528\u5355\u4e2a\u5c0f\u5199\u5b57\u6bcd\uff0c\u5373[a-z]<\/li>\n\n\n\n<li>\u652f\u6301\u6761\u4ef6\u8fd0\u7b97\uff0c\u8fd9\u91cc\u5b9a\u4e49\u7b80\u5355\u7684\u8bed\u6cd5\u5982\u4e0b\uff1aif ( expr )  expre ; \uff08\u5ffd\u7565\u4e86else\u8bed\u6cd5\uff09<\/li>\n\n\n\n<li>\u652f\u6301\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff0c\u5305\u62ec\u5927\u4e8e\u3001\u5c0f\u4e8e<\/li>\n\n\n\n<li>\u652f\u6301\u5faa\u73af\u8fd0\u7b97\uff0c\u652f\u6301while\u5faa\u73af<\/li>\n\n\n\n<li>\u548c\u524d\u9762\u6848\u4f8b\u7684\u4e00\u6837\uff0c\u4ec5\u5904\u7406\u6574\u6570\uff0c\u6545\u4e0d\u5904\u7406\u9664\u6cd5\uff0c\u4e5f\u4e0d\u8003\u8651\u6574\u6570\u6ea2\u51fa\u7b49\u8fb9\u754c\u95ee\u9898<\/li>\n<\/ul>\n\n\n\n<p>\u6211\u4eec\u7528\u8fd9\u51e0\u4e2a\u80fd\u529b\uff0c\u53ef\u4ee5\u7f16\u5199\u5982\u4e0b\u7684\u7a0b\u5e8f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">i = 1;\na = 0;\nwhile ( a &lt; 100 ) {\n  i = i + 1;\n  a = a + i;\n}\nprint i;<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u7a0b\u5e8f\u5b9e\u73b0\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u529f\u80fd\uff0c\u89e3\u51b3\u7684\u95ee\u9898\u662f\uff1a\u5728\u81ea\u7136\u6570\u5e8f\u5217\uff081\u30012\u30014&#8230;\uff09\u4e2d\uff0c\u524d\u9762\u591a\u5c11\u4e2a\u81ea\u7136\u6570\u7684\u548c\u9996\u6b21\u5927\u4e8e100\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e0a\u9762\u7684\u547d\u4ee4\u7f16\u5199\u5176\u4ed6\u7684\u4efb\u610f\u7a0b\u5e8f\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u89e3\u6790\u6811\u7684\u8282\u70b9<\/h4>\n\n\n\n<p>\u5982\u679c\u53ea\u662f\u4f7f\u7528\u524d\u9762\u7684\u6307\u4ee4\uff0c\u4f3c\u4e4e\u96be\u4ee5\u5b9e\u73b0\u5bf9if\/while\u8bed\u53e5\u7684\u652f\u6301\u3002\u8fd9\u91cc\uff0c\u5c31\u9700\u8981\u4f7f\u7528\u5178\u578b\u7684\u7f16\u8bd1\u4e0e\u6267\u884c\u601d\u8def\u4e86\uff0c\u5148\u4f7f\u7528\u8bed\u6cd5\u89e3\u6790\u6784\u5efa\u4e00\u4e2a\u201c\u8bed\u6cd5\u6811\u201d\uff08\u4e5f\u53eb\u201c\u89e3\u6790\u6811\u201d\uff09\uff0c\u7136\u540e\u518d\u6267\u884c\u8be5\u89e3\u6790\u6811\u3002\u5177\u4f53\u7684\uff0c\u4e00\u4e9b\u8bbe\u8ba1\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528\u4e00\u4e2a\u5168\u5c40\u6570\u7ec4\uff08<code>int * var[26]<\/code>\uff09\u5b58\u50a8\u53d8\u91cf\uff0c\u56e0\u4e3a\u5728\u524d\u9762\u9650\u5236\u4e86\u53d8\u91cf\u540d\u53ea\u80fd\u662f[a-z]<\/li>\n\n\n\n<li>\u6bcf\u4e2agrammar rule\u5bf9\u5e94\u4e00\u4e2atree node\uff0c\u5e76\u4f9d\u6b21\u6784\u5efa\u4e00\u68f5\u8bed\u6cd5\u6811<\/li>\n\n\n\n<li>\u8bed\u6cd5\u6811\u7684\u8282\u70b9\u8bbe\u8ba1\u5982\u4e0b\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">typedef struct t_node{\n    enum NODETYPE nt;\n    struct t_node* left;\n    struct t_node* right;\n    int i;  \/\/ for NT_INTEGER NT_VAR_NAME node\n}t_node;<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc\u4e3a\u4e86\u7b80\u5316\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6240\u6709\u8bed\u6cd5\u8282\u70b9\u90fd\u5b58\u653e\u5728\u8be5\u7ed3\u6784\u4e2d<\/li>\n\n\n\n<li>\u5bf9\u4e8e\u53d8\u91cf\u540d\uff0c\u672c\u5e94\u8be5\u662f\u4e00\u4e2a\u5b57\u7b26\uff0c\u8fd9\u91cc\u5728\u5b58\u50a8\u65f6\uff0c\u76f4\u63a5\u4f7f\u7528\u5176ASCII\u7801\u5c06\u5176\u5b58\u50a8\u4e3a\u6574\u6570<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u8bed\u6cd5\u89c4\u5219\u8bbe\u8ba1<\/h4>\n\n\n\n<p>\u5728\u5f00\u59cb\u5b9e\u73b0\u4e0e\u6267\u884c\u89e3\u6790\u6811\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u5b9a\u4e49\u8bed\u6cd5\u89c4\u5219\uff0c\u4ee5\u652f\u6301\u8d4b\u503c\u3001if\u3001while\u3001print\u7b49\u8bed\u6cd5\u3002\u8bed\u6cd5\u89c4\u5219\u5b9a\u4e49\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u5c3d\u91cf\u907f\u514d\u51fa\u73b0shift\/reduce\u51b2\u7a81\uff0c\u5e76\u4e14\u8fd9\u91cc\u7684\u8bed\u6cd5\u89c4\u5219\u4e0d\u5305\u542bAction\u90e8\u5206\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">\/\/start symbol\nprogram: \n        | program statement_block   { printf(\"\\n job done! \\n\"); }\n;\n\nstatement_block: \n        | statement_block statement\n;\n\nstatement: assignment\n        | print_func\n        | if_block\n        | while_block \n;\n\nwhile_block: WHILE '('  bool_expr ')' '{' statement_block '}'\n\nif_block: IF '(' bool_expr ')' '{' statement_block '}'\n\nassignment: VAR_NAME '=' expression ';'\n\nprint_func : PRINT expression ';'  \n        | PRINT VAR_NAME ';'\n\nbool_expr: expression GT expression\n        |  expression LT expression\n\nexpression: INTEGER\n        | VAR_NAME\n        | expression O_ADD expression\n        | expression O_MINUS expression\n        | expression O_MULTIPLY expression<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u8282\u70b9\u5206\u6790<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">\u8282\u70b9\u5206\u6790\uff1aINTEGER  VAR_NAME <\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8282\u70b9\u7c7b\u578b\uff08enum NODETYPE\uff09\u5206\u522b\u662f\uff1aNT_INTEGER   NT_VAR_NAME <\/li>\n\n\n\n<li>\u6ca1\u6709\u5b50\u8282\u70b9\uff0c\u6545left\/right node\u90fd\u662fNULL<\/li>\n\n\n\n<li>\u5728\u521d\u59cb\u5316\u65f6\uff0c\n<ul class=\"wp-block-list\">\n<li>\u5bf9\u4e8eINTEGER\uff1a<code>t_node.a<\/code> \u5b58\u50a8\u7684\u662f\u5177\u4f53\u7684\u6574\u6570<\/li>\n\n\n\n<li>\u5bf9\u4e8eVAR_NAME\uff1a\u5219\u5b58\u50a8\u7684\u53d8\u91cf\u540d\uff0c\u8fd9\u4e86\u53d8\u91cf\u540d\u4e3a[a-z]\uff0c\u5219\u5c06\u5176ASCII\u5b58\u653e\u4e8e<code>t_node.a<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h5 class=\"wp-block-heading\">\u8282\u70b9\u5206\u6790\uff1aexpression \u4e0e O_ADD O_MINUS O_MULTIPLY<\/h5>\n\n\n\n<p>expression\u5bf9\u5e94\u7684\u8bed\u6cd5\u89c4\u5219\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">expression: INTEGER\n        | VAR_NAME\n        | expression O_ADD expression\n        | expression O_MINUS expression\n        | expression O_MULTIPLY expression<\/code><\/pre>\n\n\n\n<p>\u90a3\u4e48\uff0c\u518d\u770b\u770bO_ADD O_MINUS O_MULTIPLY\u8fd9\u7c7b\u8282\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>NODETYPE \u5206\u522b\u662f NT_O_ADD  NT_O_MINUS  NT_O_MULTIPLY  <\/li>\n\n\n\n<li>\u90fd\u6709\u4e24\u4e2a\u5b50\u8282\u70b9\uff0cleft \/ right<\/li>\n\n\n\n<li>\u5728execute\u4e4b\u540e\u5b58\u50a8\uff0c\u5404\u4e2aexpression\u8ba1\u7b97\u7684\u7ed3\u679c\u503c<code>t_node.a<\/code>\u4e2d<\/li>\n\n\n\n<li>\u6ce8\u610f\uff0c\u5728\u8fd9\u4e2a\u8bbe\u8ba1\u4e2d\uff0c\u65e0\u9700\u6709\u4e00\u4e2a\u72ec\u7acb\u7684expression\u8282\u70b9<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">bool\u8868\u8fbe\u5f0f\uff08bool_expr\uff09\uff0c\u901a\u5e38\u7528\u4e8e\u6761\u4ef6\u5224\u65ad<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">bool_expr: expression GT expression \n        |  expression LT expression <\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8282\u70b9\u7c7b\u578b\uff08enum NODETYPE\uff09\u4e3a <code>NT_BOOL_EXPR <\/code><\/li>\n\n\n\n<li>\u6709\u4e24\u4e2a\u5b50\u8282\u70b9\uff0c\u6267\u884c\u8be5\u8282\u70b9\u65f6\uff0c\u9700\u8981\u6267\u884c\u4e24\u4e2a\u5b50\u8282\u70b9\u4e4b\u540e\uff0c\u83b7\u5f97\u4e24\u4e2a\u5b50\u8282\u70b9\u7684\u7ed3\u679c\u503c\uff0c\u518d\u8fdb\u884c\u6bd4\u8f83 <\/li>\n\n\n\n<li>\u8fd4\u56de\u503c\u4e3a\u4e3abool\u578b\uff0c\u8fd9\u91cc\u4f7f\u7528int\u5b58\u50a8\uff0c0\u8868\u793aFALSE  1\u8868\u793aTRUE<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">print_func\u8282\u70b9<\/h4>\n\n\n\n<p>\u8fd9\u4e2a\u8282\u70b9\u5b9e\u73b0\u4e00\u4e2a\u6253\u5370\u6574\u6570\u503c\u7684\u529f\u80fd\uff0c\u53c2\u6570\u53ef\u4ee5\u662f\u4e00\u4e2a\u53d8\u91cf\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u8868\u8fbe\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">print_func : PRINT expression ';'  \n        | PRINT VAR_NAME ';' <\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>NODETYPE<\/code>\u4e3a <code>NT_PRINT_FUNC <\/code><\/li>\n\n\n\n<li>\u53ea\u6709\u4e00\u4e2a\u5b50\u8282\u70b9\uff0c\u4e3a\u4e00\u4e2a expression \u6216 VAR_NAME \uff08\u6ce8\uff1a\u8fd9\u91cc\u5e94\u8be5\u53ea\u7528expression\u5c31\u53ef\u4ee5\u4e86\uff0c\u56e0\u4e3aVAR_NAME\u4e5f\u662fexpression\uff09<\/li>\n\n\n\n<li>\u6267\u884c\u8be5\u8282\u70b9\u65f6\uff0c\u5219\u9700\u8981\u5b9e\u9645\u8c03\u7528\u4e00\u6b21\u6253\u5370\u51fd\u6570\uff0c\u5411\u6807\u51c6\u8f93\u51fa\u6253\u5370<code>expression<\/code>\u7684\u7ed3\u679c\u503c<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">assignment \u8d4b\u503c\u8bed\u53e5<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">assignment: VAR_NAME '=' expression ';'<\/code><\/pre>\n\n\n\n<p>\u8d4b\u503c\u8bed\u53e5\u5de6\u8fb9\u662f\u53d8\u91cf\u540d\uff0c\u8fd9\u91cc\u5b9a\u4e49\u662f[a-z]\uff0c\u53f3\u8fb9\u662f\u4e00\u4e2a\u8868\u8fbe\u5f0f\uff0c\u8bed\u53e5\u4ee5\u5206\u53f7\u7ed3\u675f\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5176\u8282\u70b9\u7c7b\u578b\uff08NODETYPE\uff09\u4e3a\uff1aNT_ASSIGNMENT <\/li>\n\n\n\n<li>\u5de6\u5b50\u8282\u70b9\u4e3a <code>VAR_NAME<\/code> \uff0c\u53f3\u5b50\u8282\u70b9\u4e3a <code>expression <\/code><\/li>\n\n\n\n<li>\u5176\u6267\u884c\u65f6\uff0c\u9700\u8981\u5c06expression\u7684\u7ed3\u679c\u503c\uff0c\u5b58\u50a8\u5230\u53d8\u91cf\u6570\u7ec4\u5bf9\u5e94\u7684\u6574\u578b\u53d8\u91cf\u4e2d<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">while_block WHILE\u5b50\u53e5<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">while_block: WHILE '('  bool_expr ')' '{' statement_block '}'<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5176\u8282\u70b9\u7c7b\u578b\uff08NODETYPE\uff09\u4e3a\uff1aNT_WHILE <\/li>\n\n\n\n<li>\u5de6\u5b50\u8282\u70b9\u4e3a: <code>bool_expr<\/code> \u53f3\u5b50\u8282\u70b9\u4e3a :  <code>statement_block<\/code><\/li>\n\n\n\n<li>\u6267\u884c\u8be5\u8282\u70b9\u65f6\uff0c\u4e5f\u662f\u4e5fwhile\u5faa\u73af\u6267\u884c\uff0c\u6761\u4ef6\u90e8\u5206\u662f\u6267\u884c\u5e76\u5224\u65ad<code>bool_expr<\/code>\u7684\u771f\u5047\uff0c\u518d\u51b3\u5b9a\u662f\u5426\u6267\u884c\u53f3\u5b50\u8282\u70b9\u3002\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\uff0c\u6bcf\u6b21\u83b7\u53d6bool_expr\u7684\u65f6\u5019\uff0c\u90fd\u9700\u8981\u5148\u6267\u884c\u4e00\u6b21\u8be5\u8282\u70b9\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">if_block IF\u5b50\u53e5<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">if_block: IF '(' bool_expr ')' '{' statement_block '}'<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5176\u8282\u70b9\u7c7b\u578b\uff08NODETYPE\uff09\u4e3a\uff1aNT_IF <\/li>\n\n\n\n<li>\u5de6\u5b50\u7ed3\u70b9\u4e3a bool_expr  \u53f3\u5b50\u8282\u70b9 :  statement_block <\/li>\n\n\n\n<li>\u6267\u884c\u65f6\uff0c\u5148\u6267\u884c\u5de6\u5b50\u8282\u70b9\uff0c\u518d\u83b7\u53d6\u5176\u7ed3\u679c\u7684\u771f\/\u5047\uff0c\u518d\u5224\u65ad\u662f\u5426\u6267\u884c\u53f3\u5b50\u8282\u70b9<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">statement <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">statement: assignment\n        | print_func\n        | if_block\n        | while_block<\/code><\/pre>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\uff0cstatement\u7531assignment\u3001print_func\u3001if_block\u3001while_block\u662f\u8fd9\u4e9b\u4e2d\u7684\u4efb\u4f55\u4e00\u4e2a\u3002\u6240\u4ee5\uff0c\u5728\u5b9e\u9645\u6784\u5efa\u4e2d\uff0c\u5e76\u4e0d\u4f1a\u6709\u8be5\u8282\u70b9\u3002\u4e0eexpression\u7c7b\u4f3c\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">statement_block \u591a\u4e2astatement<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">statement_block: \n        | statement_block statement\n;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5176\u8282\u70b9\u7c7b\u578b\uff08NODETYPE\uff09\u4e3a\uff1aNT_STATEMENT_BLOCK <\/li>\n\n\n\n<li>\u5de6\u5b50\u8282\u70b9\u4e3a : statement_block\uff0c\u5373\u4e3astatement_block\u6216\u8005assignment\u3001print_func\u3001if_block\u3001while_block\u4e2d\u7684\u4efb\u610f\u4e00\u4e2a\uff1b\u53f3\u5b50\u8282\u70b9\u4e3a : assignment\u3001print_func\u3001if_block\u3001while_block <\/li>\n\n\n\n<li>\u6267\u884c\u65f6\uff0c\u5148\u6267\u884c\u5de6\u5b50\u8282\u70b9\uff0c\u518d\u6267\u884c\u53f3\u5b50\u8282\u70b9<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">program <\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">program:\n        | program statement_block  { printf(\"\\n job done! \\n\"); }\n;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u4e3b\u8981\u7684\u6570\u636e\u7ed3\u6784\u4e0e\u51fd\u6570<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>build_node<\/code>\uff1a\u6784\u5efa\u5f53\u524d\u8bed\u6cd5\u89c4\u5219\u7684\u8282\u70b9\uff0c\u8be5\u51fd\u6570\u8fd4\u56de\u5f53\u524d\u6784\u5efa\u51fa\u6765\u8282\u70b9\u7684\u6307\u9488\uff0c\u901a\u5e38\u4e5f\u662f\u5404\u4e2a\u8bed\u6cd5\u89c4\u5219Action\u90e8\u5206\u7684\u8fd4\u56de\u503c\u3002<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">t_node* build_node( \n    enum NODETYPE nt,\n    t_node* left,\n    t_node* right,\n    int i)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>exec_node<\/code>\uff1a\u6267\u884c\u67d0\u4e2a\u8282\u70b9\uff0c\u5e76\u6267\u884c\u5176\u5de6\/\u53f3\u5b50\u8282\u70b9\uff08\u5982\u679c\u5b58\u5728\u7684\u8bdd\uff09\u3002\u4e0d\u540c\u7684\u8282\u70b9\u7684\u6267\u884c\u64cd\u4f5c\u4f1a\u6709\u4e00\u4e9b\u4e0d\u540c\uff0c\u4f8b\u5982\uff1a\n<ul class=\"wp-block-list\">\n<li><code>if<\/code>\u8282\u70b9\u9700\u8981\u505a\u4e00\u4e9b\u5224\u65ad\uff0c\u518d\u51b3\u5b9a\u662f\u5426\u6267\u884c\uff1b<\/li>\n\n\n\n<li><code>while<\/code>\u8282\u70b9\u5219\u9700\u8981\u5faa\u73af<code>bool_expr<\/code>\u4ee5\u51b3\u5b9a\u662f\u5426\u6267\u884c\u67d0\u6bb5\u4ee3\u7801\u3002<\/li>\n\n\n\n<li>\u52a0\u6cd5\u8282\u70b9\uff0c\u5219\u9700\u8981\u6267\u884c\u5de6\u53f3\u5b50\u8282\u70b9\u6267\u884c\u7ed3\u679c\uff0c\u5e76\u76f8\u52a0<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>\u5404\u7c7b\u8282\u70b9\u7684exec\u64cd\u4f5c\u53ef\u4ee5\u53c2\u8003\u4e0a\u4e00\u8282\u7684\u8be6\u7ec6\u63cf\u8ff0\u3002\u8be5\u51fd\u6570\u5b9a\u4e49\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">int exec_node(t_node *n)<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u89e3\u6790\u6811\u7684\u8282\u70b9\u4e0e\u8282\u70b9\u7c7b\u578b<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">typedef struct t_node{\n    enum NODETYPE nt;\n    struct t_node* left;\n    struct t_node* right;\n    struct t_node* rrnode;\n    int i;  \/\/ for NT_INTEGER NT_VAR_NAME node\n}t_node;<\/code><\/pre>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">enum NODETYPE{\n    NT_STATEMENT,\n    NT_IF,\n    NT_WHILE,\n    NT_PROGRAM,\n    NT_STATEMENT_BLOCK,\n    NT_O_ADD,\n    NT_O_MINUS,\n    NT_O_MULTIPLY,\n    NT_INTEGER,\n    NT_VAR_NAME,\n    NT_BOOL_EXPR_GT,\n    NT_BOOL_EXPR_LT,\n    NT_PRINT,\n    NT_ASSIGNMENT\n};<\/code><\/pre>\n<\/div>\n<\/div>\n\n\n\n<p>\u4e0b\u4e00\u7bc7\uff0c\u6211\u4eec\u5c06\u57fa\u4e8e\u6b64\u5b8c\u6210\u5b8c\u6574\u7684\u4ee3\u7801\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e0d\u5305\u542bAction\u4ee3\u7801\u7684\u8bed\u6cd5<\/h3>\n\n\n\n<p>\u8865\u5145\u5b8c\u6574\u7684\u8bed\u6cd5\u6587\u4ef6cal.y<\/p>\n\n\n\n<p>\u5305\u62ec\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5165\u53e3\u51fd\u6570<\/li>\n\n\n\n<li>NODETYPE \u5b9a\u4e49<\/li>\n\n\n\n<li>\u89e3\u6790\u6811\u7684\u8282\u70b9 t_node<\/li>\n\n\n\n<li>\u58f0\u660e\u8282\u70b9\u4fbf\u5229\u51fd\u6570 exec_node <\/li>\n\n\n\n<li>\u7528\u4e8e\u5b58\u50a8\u53d8\u91cf\u7684\u6570\u7ec4  int var[26];<\/li>\n\n\n\n<li>YYSTYPE \uff08\u4f3c\u4e4e\u662f\u4e0d\u9700\u8981\uff09 <\/li>\n\n\n\n<li>\u5b9a\u4e49lex\u9700\u8981\u5904\u7406\u7684TOKEN<\/li>\n\n\n\n<li>\u5b9a\u4e49\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7\u3001\u7ed3\u5408\u5f8b <\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">%{\n\/\/ \u5165\u53e3\u51fd\u6570\n\n#include &lt;stdio.h&gt;\n\nint main (){\n    yyparse();\n    return 0;\n}\n\nenum NODETYPE{\n    NT_PROGRAM,\n    NT_STATEMENT_BLOCK,\n    NT_STATEMENT,\n    NT_IF,\n    NT_WHILE,\n    NT_O_ADD, \n    NT_O_MINUS,\n    NT_O_MULTIPLY,\n    NT_INTEGER,\n    NT_VAR_NAME\n};\n\ntypedef struct t_node{\n    enum NODETYPEP nt;\n    t_node * left;\n    t_node * right;\n    t_node * rrnode;\n    YYSTYPE yval;\n}t_node;\n\n\/\/\u9012\u5f52\u6267\u884c\u6574\u4e2aparser tree\nint exec_node(t_node *n){\n    return 0;\n}\n\nint var[26];\n\n%}\n\n\/\/ \u5b9a\u4e49YYSTYPE\n%union {\n    int a;  \/\/ for integer\n    char c; \/\/ for var_name\n    bool b; \/\/ for bool_expr\n}\n\n\n\/\/ \u5b9a\u4e49Token\n%token &lt;c&gt; VAR_NAME \n%token &lt;a&gt; INTEGER\n%token O_ADD O_MINUS O_MULTIPLY \n\n%token GT LT\n\n%token WHILE IF\n%token PRINT\n\n\/\/ \u5b9a\u4e49\u8fd0\u7b97\u7b26\n%left O_ADD O_MINUS\n%left O_MULTIPLY\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u8865\u5145Lex\u6587\u4ef6<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">%{\n    #include \"cal.tab.h\"\n%}\n%option noyywrap\n%%\n[[:digit:]]+ {\n    yylval.a = atoi(yytext);\n    return INTEGER;\n}\n\n[a-z] {\n    yylval.c = yytext[0];\n    return VAR_NAME;\n}\n\n\"+\" { return O_ADD;};\n\"-\" { return O_MINUS;};\n\"*\" { return O_MULTIPLY;};\n\n\"while\"  {return WHILE;}\n\"if\"  {return IF;}\n\"print\"  {return PRINT;}\n\n\"&gt;\" {return GT;}\n\"&lt;\" {return LT;}\n\n[();={}]  {return yylval.c = *yytext;}\n\n%%<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u751f\u6210\u4ee3\u7801\u5e76\u7f16\u8bd1\u3001\u4fee\u6539<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">lex cal.l \nbison -d cal.y \ngcc cal.tab.c lex.yy.c -o a.out\n\n\nbison -W -d cal.y\n\ncal.y:62.8: warning: empty rule without %empty [-Wempty-rule]\n program:\n        ^\ncal.y:66.16: warning: empty rule without %empty [-Wempty-rule]\n statement_block:\n                ^\ncal.y: warning: 6 shift\/reduce conflicts [-Wconflicts-sr]<\/code><\/pre>\n\n\n\n<p>\u9519\u8bef1\uff1a\u8fd9\u91cc\u7684 PRINT expression &#8216;;&#8217;  <s>PRINT VAR_NAME &#8216;;&#8217;<\/s> \u662f\u6709\u5305\u542b\u5173\u7cfb\uff0c\u91cd\u590d\u7684\u3002\u56e0\u4e3aVAR_NAME\u672c\u8eab\u4e5f\u662f\u4e00\u4e2aexpression\u3002\u6545\u4fee\u6539\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">print_func : PRINT expression ';'  \n <s>       | PRINT VAR_NAME ';'<\/s> \n\nexpression: INTEGER\n        | VAR_NAME\n        | expression O_ADD expression\n        | expression O_MINUS expression\n        | expression O_MULTIPLY expression<\/code><\/pre>\n\n\n\n<p>\u7591\u95ee\u4e0e\u601d\u8003\uff1a\u5de6\u8fb9\/\u53f3\u8fb9\u7684\u8868\u8fbe\u6709\u4ec0\u4e48\u4e0d\u540c\u3002\uff08\u6ce8\u610f\uff0c\u5de6\u8fb9\u7684\u8868\u8fbe\u4f1a\u62a5shift\/reduce conflict\uff09<\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">program: \n        | program statement_block \n;\n\nstatement_block: \n        | statement_block statement\n;\n\nstatement: assignment\n        | print_func\n        | if_block\n        | while_block \n;<\/code><\/pre>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">program: statement_block \n;\n\n\nstatement_block:\n        | statement_block statement\n;\n\nstatement: assignment \n        | print_func \n        | if_block \n        | while_block \n;<\/code><\/pre>\n<\/div>\n<\/div>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u4fee\u6539\u540e\u7684cal.y\u6587\u4ef6\uff0c\u4ec5\u8bed\u6cd5\u90e8\u5206\uff0c\u4e0d\u5305\u542bAction<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"c\" class=\"language-c\">%%\nprogram:  statement_block { printf(\"\\n job done! \\n\");}\n;\n\nstatement_block:\n        | statement_block statement\n;\n\nstatement: assignment \n        | print_func \n        | if_block \n        | while_block \n;\n\nif_block: IF '(' bool_expr ')' '{' statement_block '}' \n\nwhile_block: WHILE '('  bool_expr ')' '{' statement_block '}' \n\nassignment: VAR_NAME '=' expression ';'\n\nprint_func : PRINT expression ';'\n\nbool_expr: expression GT expression\n        |  expression LT expression\n\nexpression: INTEGER\n        | VAR_NAME\n        | expression O_ADD expression\n        | expression O_MINUS expression\n        | expression O_MULTIPLY expression\n\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f15\u8a00 \u8fd9\u662f\u4e00\u4e2a\u7cfb\u5217\u6587\u7ae0\uff0c\u65e8\u5728\u4e86\u89e3\u5982\u4f55\u4f7f\u7528Flex\/Lex\u548cYacc\/Bison\u8fdb\u884c\u8bcd\u6cd5\u548c\u8bed\u6cd5\u89e3\u6790\u3002\u5728\u524d\u9762\uff0c\u5df2\u7ecf\u5b8c\u6210\u4e86\u4f7f\u7528Lex\/flex\u505a\u57fa\u7840\u7684\u8bcd\u6cd5\u89e3\u6790\u3001\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684\u8ba1\u7b97\u5668\u3002\u5f00\u59cb\u8fd9\u4e2a\u7cfb\u5217\u7684\u7b2c\u4e09\u90e8\u5206\uff0c\u4f7f\u7528flex\u548cbison\u5b8c\u6210\u4e00\u4e2a\u66f4\u52a0\u590d\u6742\u7684\u7684\u7f16\u8bd1\u7a0b\u5e8f\u3002\u6574\u4f53\u4e0a\u6709\u4e00\u5b9a\u7684\u590d\u6742\u5ea6\uff0c\u6240\u4ee5\u5206\u4e0a\u4e0b\u7bc7\u5206\u522b\u4ecb\u7ecd\u3002\u4e0a\u7bc7\u4ecb\u7ecd\uff1a\u5b9e\u73b0\u6982\u8981\u3001\u8bed\u6cd5\u3001\uff0c\u4e0b\u7bc7\u4ecb\u7ecd\u6570\u636e\u7ed3\u6784\u4e0e\u5b9e\u73b0\uff08\u5305\u62ec\u89e3\u6790\u6811\u5b9e\u73b0\u3001\u6267\u884c\uff09\u3002 \u89e3\u6790\u4e0e\u6267\u884c\u5305\u542b\u8d4b\u503c\u3001IF\u3001WHILE\u7b49\u8bed\u53e5\u7684\u7a0b\u5e8f \u5728\u524d\u9762\u7684\u6848\u4f8b\u4e2d\uff0c\u6211\u4eec\u5b9e\u73b0\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u52a0\u51cf\u4e58\u8fd0\u7b97\u7684\u8ba1\u7b97\u5668\u7a0b\u5e8f\u3002\u8fd9\u91cc\u6211\u4eec\u5c1d\u8bd5\u5b9e\u73b0\u4e00\u4e2a\u66f4\u590d\u6742\u4e00\u4e9b\u7684\u7f16\u8bd1\u7a0b\u5e8f\uff0c\u8bed\u6cd5\u80fd\u591f\u652f\u6301\u5982\u4e0b\u5185\u5bb9\uff1a \u6211\u4eec\u7528\u8fd9\u51e0\u4e2a\u80fd\u529b\uff0c\u53ef\u4ee5\u7f16\u5199\u5982\u4e0b\u7684\u7a0b\u5e8f\uff1a \u8fd9\u4e2a\u7a0b\u5e8f\u5b9e\u73b0\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u529f\u80fd\uff0c\u89e3\u51b3\u7684\u95ee\u9898\u662f\uff1a\u5728\u81ea\u7136\u6570\u5e8f\u5217\uff081\u30012\u30014&#8230;\uff09\u4e2d\uff0c\u524d\u9762\u591a\u5c11\u4e2a\u81ea\u7136\u6570\u7684\u548c\u9996\u6b21\u5927\u4e8e100\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e0a\u9762\u7684\u547d\u4ee4\u7f16\u5199\u5176\u4ed6\u7684\u4efb\u610f\u7a0b\u5e8f\u3002 \u89e3\u6790\u6811\u7684\u8282\u70b9 \u5982\u679c\u53ea\u662f\u4f7f\u7528\u524d\u9762\u7684\u6307\u4ee4\uff0c\u4f3c\u4e4e\u96be\u4ee5\u5b9e\u73b0\u5bf9if\/while\u8bed\u53e5\u7684\u652f\u6301\u3002\u8fd9\u91cc\uff0c\u5c31\u9700\u8981\u4f7f\u7528\u5178\u578b\u7684\u7f16\u8bd1\u4e0e\u6267\u884c\u601d\u8def\u4e86\uff0c\u5148\u4f7f\u7528\u8bed\u6cd5\u89e3\u6790\u6784\u5efa\u4e00\u4e2a\u201c\u8bed\u6cd5\u6811\u201d\uff08\u4e5f\u53eb\u201c\u89e3\u6790\u6811\u201d\uff09\uff0c\u7136\u540e\u518d\u6267\u884c\u8be5\u89e3\u6790\u6811\u3002\u5177\u4f53\u7684\uff0c\u4e00\u4e9b\u8bbe\u8ba1\u5982\u4e0b\uff1a \u8fd9\u91cc\u4e3a\u4e86\u7b80\u5316\uff1a \u8bed\u6cd5\u89c4\u5219\u8bbe\u8ba1 \u5728\u5f00\u59cb\u5b9e\u73b0\u4e0e\u6267\u884c\u89e3\u6790\u6811\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u5b9a\u4e49\u8bed\u6cd5\u89c4\u5219\uff0c\u4ee5\u652f\u6301\u8d4b\u503c\u3001if\u3001while\u3001print\u7b49\u8bed\u6cd5\u3002\u8bed\u6cd5\u89c4\u5219\u5b9a\u4e49\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u5c3d\u91cf\u907f\u514d\u51fa\u73b0shift\/reduce\u51b2\u7a81\uff0c\u5e76\u4e14\u8fd9\u91cc\u7684\u8bed\u6cd5\u89c4\u5219\u4e0d\u5305\u542bAction\u90e8\u5206\uff1a \u8282\u70b9\u5206\u6790 \u8282\u70b9\u5206\u6790\uff1aINTEGER VAR_NAME \u8282\u70b9\u5206\u6790\uff1aexpression \u4e0e O_ADD O_MINUS O_MULTIPLY expression\u5bf9\u5e94\u7684\u8bed\u6cd5\u89c4\u5219\u5982\u4e0b \u90a3\u4e48\uff0c\u518d\u770b\u770bO_ADD O_MINUS O_MULTIPLY\u8fd9\u7c7b\u8282\u70b9\uff1a bool\u8868\u8fbe\u5f0f\uff08bool_expr\uff09\uff0c\u901a\u5e38\u7528\u4e8e\u6761\u4ef6\u5224\u65ad print_func\u8282\u70b9 \u8fd9\u4e2a\u8282\u70b9\u5b9e\u73b0\u4e00\u4e2a\u6253\u5370\u6574\u6570\u503c\u7684\u529f\u80fd\uff0c\u53c2\u6570\u53ef\u4ee5\u662f\u4e00\u4e2a\u53d8\u91cf\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u8868\u8fbe\u5f0f\uff1a assignment \u8d4b\u503c\u8bed\u53e5 \u8d4b\u503c\u8bed\u53e5\u5de6\u8fb9\u662f\u53d8\u91cf\u540d\uff0c\u8fd9\u91cc\u5b9a\u4e49\u662f[a-z]\uff0c\u53f3\u8fb9\u662f\u4e00\u4e2a\u8868\u8fbe\u5f0f\uff0c\u8bed\u53e5\u4ee5\u5206\u53f7\u7ed3\u675f\u3002 while_block WHILE\u5b50\u53e5 if_block IF\u5b50\u53e5 statement \u53ef\u4ee5\u770b\u5230\uff0cstatement\u7531assignment\u3001print_func\u3001if_block\u3001while_block\u662f\u8fd9\u4e9b\u4e2d\u7684\u4efb\u4f55\u4e00\u4e2a\u3002\u6240\u4ee5\uff0c\u5728\u5b9e\u9645\u6784\u5efa\u4e2d\uff0c\u5e76\u4e0d\u4f1a\u6709\u8be5\u8282\u70b9\u3002\u4e0eexpression\u7c7b\u4f3c\u3002 statement_block \u591a\u4e2astatement program \u4e3b\u8981\u7684\u6570\u636e\u7ed3\u6784\u4e0e\u51fd\u6570 \u5404\u7c7b\u8282\u70b9\u7684exec\u64cd\u4f5c\u53ef\u4ee5\u53c2\u8003\u4e0a\u4e00\u8282\u7684\u8be6\u7ec6\u63cf\u8ff0\u3002\u8be5\u51fd\u6570\u5b9a\u4e49\u5982\u4e0b \u4e0b\u4e00\u7bc7\uff0c\u6211\u4eec\u5c06\u57fa\u4e8e\u6b64\u5b8c\u6210\u5b8c\u6574\u7684\u4ee3\u7801\u3002 \u4e0d\u5305\u542bAction\u4ee3\u7801\u7684\u8bed\u6cd5 \u8865\u5145\u5b8c\u6574\u7684\u8bed\u6cd5\u6587\u4ef6cal.y \u5305\u62ec\uff1a \u8865\u5145Lex\u6587\u4ef6 \u751f\u6210\u4ee3\u7801\u5e76\u7f16\u8bd1\u3001\u4fee\u6539 \u9519\u8bef1\uff1a\u8fd9\u91cc\u7684 PRINT expression &#8216;;&#8217; PRINT VAR_NAME &#8216;;&#8217; \u662f\u6709\u5305\u542b\u5173\u7cfb\uff0c\u91cd\u590d\u7684\u3002\u56e0\u4e3aVAR_NAME\u672c\u8eab\u4e5f\u662f\u4e00\u4e2aexpression\u3002\u6545\u4fee\u6539\u5982\u4e0b\uff1a \u7591\u95ee\u4e0e\u601d\u8003\uff1a\u5de6\u8fb9\/\u53f3\u8fb9\u7684\u8868\u8fbe\u6709\u4ec0\u4e48\u4e0d\u540c\u3002\uff08\u6ce8\u610f\uff0c\u5de6\u8fb9\u7684\u8868\u8fbe\u4f1a\u62a5shift\/reduce [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","inline_featured_image":false,"_tocer_settings":[],"footnotes":""},"categories":[4,137],"tags":[],"class_list":["post-9588","post","type-post","status-publish","format-standard","hentry","category-code-detail","category-learning-more"],"_links":{"self":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/9588","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/comments?post=9588"}],"version-history":[{"count":53,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/9588\/revisions"}],"predecessor-version":[{"id":13002,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/9588\/revisions\/13002"}],"wp:attachment":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/media?parent=9588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/categories?post=9588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/tags?post=9588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}