{"id":149,"date":"2025-06-29T12:46:50","date_gmt":"2025-06-29T04:46:50","guid":{"rendered":"https:\/\/blog.wendianli.cn\/?p=149"},"modified":"2025-06-29T12:46:50","modified_gmt":"2025-06-29T04:46:50","slug":"%e4%b8%80%e4%b8%aa%e4%be%8b%e9%a2%98%e8%a7%a3%e5%86%b3%e9%a2%84%e6%b5%8b%e5%88%86%e6%9e%90%e8%a1%a8%e6%b1%82%e6%b3%95","status":"publish","type":"post","link":"https:\/\/blog.notiq.cn\/index.php\/2025\/06\/29\/%e4%b8%80%e4%b8%aa%e4%be%8b%e9%a2%98%e8%a7%a3%e5%86%b3%e9%a2%84%e6%b5%8b%e5%88%86%e6%9e%90%e8%a1%a8%e6%b1%82%e6%b3%95\/","title":{"rendered":"\u4e00\u4e2a\u4f8b\u9898\u89e3\u51b3\u9884\u6d4b\u5206\u6790\u8868\u6c42\u6cd5"},"content":{"rendered":"<p><strong>\u539f\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u7ed9\u5b9a\u6587\u6cd5 G[S]:<br \/>\nS \u2192 A<br \/>\nA \u2192 B | A i B<br \/>\nB \u2192 C | B + C<br \/>\nC \u2192 ) A * | (<\/p>\n<p>\u8981\u6c42\uff1a<br \/>\n(1) \u5c06\u6587\u6cd5 G[S] \u6539\u5199\u4e3a LL(1) \u6587\u6cd5\u3002<br \/>\n(2) \u6c42\u7ecf\u6539\u5199\u540e\u7684\u6587\u6cd5\u7684\u6bcf\u4e2a\u975e\u7ec8\u7ed3\u7b26\u7684 FIRST \u96c6\u548c FOLLOW \u96c6\u3002<br \/>\n(3) \u6784\u9020\u76f8\u5e94\u7684\u9884\u6d4b\u5206\u6790\u8868\u3002<\/p>\n<hr \/>\n<h3><strong>\u7b2c\u4e00\u6b65\uff1a\u7406\u89e3\u539f\u59cb\u6587\u6cd5<\/strong><\/h3>\n<p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u660e\u786e\u6587\u6cd5\u4e2d\u7684\u7b26\u53f7\uff1a<\/p>\n<ul>\n<li><strong>\u975e\u7ec8\u7ed3\u7b26 (Non-terminals):<\/strong> S, A, B, C (\u5927\u5199\u5b57\u6bcd)<\/li>\n<li><strong>\u7ec8\u7ed3\u7b26 (Terminals):<\/strong> i, +, *, (, ) (\u5c0f\u5199\u5b57\u6bcd\u6216\u7279\u6b8a\u7b26\u53f7)\u3002\u8fd9\u91cc <code>i<\/code> \u4ee3\u8868\u4e00\u4e2a\u6807\u8bc6\u7b26\u6216\u539f\u5b50\u8868\u8fbe\u5f0f\u3002<\/li>\n<li><strong>\u4ea7\u751f\u5f0f (Productions):<\/strong> \u4e0a\u8ff0\u89c4\u5219\u3002<\/li>\n<li><strong>\u5f00\u59cb\u7b26\u53f7 (Start Symbol):<\/strong> S<\/li>\n<\/ul>\n<hr \/>\n<h3><strong>\u7b2c\u4e8c\u6b65\uff1a\u5c06\u6587\u6cd5 G[S] \u6539\u5199\u4e3a LL(1) \u6587\u6cd5 (\u6d88\u9664\u5de6\u9012\u5f52\u548c\u63d0\u53d6\u5de6\u516c\u56e0\u5b50)<\/strong><\/h3>\n<p>LL(1) \u6587\u6cd5\u8981\u6c42\uff1a<\/p>\n<ol>\n<li><strong>\u65e0\u5de6\u9012\u5f52 (No Left Recursion):<\/strong> \u4efb\u4f55\u975e\u7ec8\u7ed3\u7b26 A \u90fd\u4e0d\u80fd\u901a\u8fc7 A $\\Rightarrow^+$ A$\\alpha$ \u5bfc\u51fa\u81ea\u8eab\u3002<\/li>\n<li><strong>\u65e0\u5de6\u516c\u56e0\u5b50 (No Common Prefixes):<\/strong> \u5bf9\u4e8e A $\\rightarrow \\alpha \\beta_1 | \\alpha \\beta_2$\uff0c\u9700\u8981\u63d0\u53d6\u5de6\u516c\u56e0\u5b50\u3002<\/li>\n<li><strong>LL(1) \u6761\u4ef6\u6ee1\u8db3\uff1a<\/strong> \u5bf9\u4e8e A $\\rightarrow \\alpha | \\beta$\uff0c\u5fc5\u987b\u6ee1\u8db3 FIRST($\\alpha$) $\\cap$ FIRST($\\beta$) = $\\emptyset$\u3002\u5982\u679c\u5176\u4e2d\u4e00\u4e2a\u4ea7\u751f\u5f0f\u53ef\u4ee5\u5bfc\u51fa $\\epsilon$\uff0c\u5219\u9700\u8981\u8fdb\u4e00\u6b65\u68c0\u67e5 FIRST($\\alpha$) $\\cap$ FOLLOW(A) = $\\emptyset$\u3002<\/li>\n<\/ol>\n<p>\u73b0\u5728\u6211\u4eec\u68c0\u67e5\u539f\u59cb\u6587\u6cd5\uff1a<\/p>\n<ol>\n<li><strong>S \u2192 A<\/strong> (\u65e0\u5de6\u9012\u5f52\uff0c\u65e0\u5de6\u516c\u56e0\u5b50)<\/li>\n<li><strong>A \u2192 B | A i B<\/strong>\n<ul>\n<li>\u5b58\u5728\u5de6\u9012\u5f52\uff1a<code>A \u2192 A i B<\/code>\u3002<\/li>\n<li>\u6d88\u9664\u5de6\u9012\u5f52\u7684\u901a\u7528\u89c4\u5219\uff1a\u5bf9\u4e8e $A \\rightarrow A\\alpha | \\beta$\uff0c\u6539\u5199\u4e3a $A \\rightarrow \\beta A'$\uff0c$A' \\rightarrow \\alpha A' | \\epsilon$\u3002<\/li>\n<li>\u8fd9\u91cc $\\beta = B$\uff0c$\\alpha = i B$\u3002<\/li>\n<li>\u6539\u5199\u540e\uff1a\n<ul>\n<li><code>A \u2192 B A&#039;<\/code><\/li>\n<li><code>A&#039; \u2192 i B A&#039; | \u03b5<\/code> (\u03b5 \u8868\u793a\u7a7a\u4e32)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>B \u2192 C | B + C<\/strong>\n<ul>\n<li>\u5b58\u5728\u5de6\u9012\u5f52\uff1a<code>B \u2192 B + C<\/code>\u3002<\/li>\n<li>\u8fd9\u91cc $\\beta = C$\uff0c$\\alpha = + C$\u3002<\/li>\n<li>\u6539\u5199\u540e\uff1a\n<ul>\n<li><code>B \u2192 C B&#039;<\/code><\/li>\n<li><code>B&#039; \u2192 + C B&#039; | \u03b5<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>*<em>C \u2192 ) A <\/em> | (** (\u65e0\u5de6\u9012\u5f52\uff0c\u65e0\u5de6\u516c\u56e0\u5b50)<\/li>\n<\/ol>\n<p><strong>\u6539\u5199\u540e\u7684 LL(1) \u6587\u6cd5 G'[S]\uff1a<\/strong><\/p>\n<ol>\n<li>S \u2192 A<\/li>\n<li>A \u2192 B A'<\/li>\n<li>A' \u2192 i B A' | \u03b5<\/li>\n<li>B \u2192 C B'<\/li>\n<li>B' \u2192 + C B' | \u03b5<\/li>\n<li>C \u2192 ) A * | (<\/li>\n<\/ol>\n<hr \/>\n<h3><strong>\u7b2c\u4e09\u6b65\uff1a\u8ba1\u7b97 FIRST \u96c6\u548c FOLLOW \u96c6<\/strong><\/h3>\n<p><strong>\u7ec8\u7ed3\u7b26\uff1a<\/strong> i, +, *, (, ), $ (\u5176\u4e2d <code>$<\/code> \u662f\u8868\u793a\u8f93\u5165\u7ed3\u675f\u7684\u7279\u6b8a\u7b26\u53f7)<br \/>\n<strong>\u975e\u7ec8\u7ed3\u7b26\uff1a<\/strong> S, A, A', B, B', C<\/p>\n<h4><strong>\u8ba1\u7b97 FIRST \u96c6 (First Set)<\/strong><\/h4>\n<p><strong>\u5b9a\u4e49\uff1a<\/strong> FIRST(X) \u662f\u6240\u6709\u53ef\u4ee5\u7531 X \u5bfc\u51fa\u7684\u4e32\u7684\u7b2c\u4e00\u4e2a\u7ec8\u7ed3\u7b26\u7684\u96c6\u5408\u3002\u5982\u679c X \u53ef\u4ee5\u5bfc\u51fa\u7a7a\u4e32 \u03b5\uff0c\u5219 \u03b5 \u4e5f\u5305\u542b\u5728 FIRST(X) \u4e2d\u3002<\/p>\n<p><strong>\u89c4\u5219\uff1a<\/strong><\/p>\n<ol>\n<li>\u5982\u679c X \u662f\u7ec8\u7ed3\u7b26\uff0c\u5219 FIRST(X) = {X}\u3002<\/li>\n<li>\u5982\u679c X \u662f\u975e\u7ec8\u7ed3\u7b26\uff0c\u4e14\u6709\u4ea7\u751f\u5f0f X \u2192 a... (\u5176\u4e2d a \u662f\u7ec8\u7ed3\u7b26)\uff0c\u5219\u5c06 a \u52a0\u5165 FIRST(X)\u3002<\/li>\n<li>\u5982\u679c X \u662f\u975e\u7ec8\u7ed3\u7b26\uff0c\u4e14\u6709\u4ea7\u751f\u5f0f X \u2192 Y1 Y2 ... Yk\uff1a\n<ul>\n<li>\u5c06 FIRST(Y1) \u4e2d\u9664 \u03b5 \u5916\u7684\u6240\u6709\u7b26\u53f7\u52a0\u5165 FIRST(X)\u3002<\/li>\n<li>\u5982\u679c \u03b5 \u5c5e\u4e8e FIRST(Y1)\uff0c\u5219\u5c06 FIRST(Y2) \u4e2d\u9664 \u03b5 \u5916\u7684\u6240\u6709\u7b26\u53f7\u52a0\u5165 FIRST(X)\u3002<\/li>\n<li>\u4f9d\u6b64\u7c7b\u63a8\uff0c\u76f4\u5230\u67d0\u4e2a Yi \u7684 FIRST \u96c6\u4e2d\u4e0d\u5305\u542b \u03b5\uff0c\u6216\u8005\u6240\u6709 Yi \u7684 FIRST \u96c6\u4e2d\u90fd\u5305\u542b \u03b5\u3002<\/li>\n<li>\u5982\u679c\u6240\u6709 Yi \u7684 FIRST \u96c6\u4e2d\u90fd\u5305\u542b \u03b5\uff0c\u5219\u5c06 \u03b5 \u52a0\u5165 FIRST(X)\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>\u8ba1\u7b97\u8fc7\u7a0b\uff1a<\/strong><\/p>\n<ol>\n<li>\n<p><strong>\u76f4\u63a5\u6839\u636e\u4ea7\u751f\u5f0f\u5224\u65ad\uff1a<\/strong><\/p>\n<ul>\n<li><code>A&#039; \u2192 i B A&#039; | \u03b5<\/code> $\\Rightarrow$ FIRST(A') = {i, \u03b5}<\/li>\n<li><code>B&#039; \u2192 + C B&#039; | \u03b5<\/code> $\\Rightarrow$ FIRST(B') = {+, \u03b5}<\/li>\n<li><code>C \u2192 ) A * | (<\/code> $\\Rightarrow$ FIRST(C) = {), (}<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6839\u636e\u5df2\u77e5\u7684 FIRST \u96c6\u63a8\u5bfc\uff1a<\/strong><\/p>\n<ul>\n<li><code>B \u2192 C B&#039;<\/code>\uff1aB \u7684\u7b2c\u4e00\u4e2a\u7b26\u53f7\u53d6\u51b3\u4e8e C\u3002\n<ul>\n<li>FIRST(B) = FIRST(C) = {), (} (\u56e0\u4e3a FIRST(C) \u4e0d\u542b \u03b5)<\/li>\n<\/ul>\n<\/li>\n<li><code>A \u2192 B A&#039;<\/code>\uff1aA \u7684\u7b2c\u4e00\u4e2a\u7b26\u53f7\u53d6\u51b3\u4e8e B\u3002\n<ul>\n<li>FIRST(A) = FIRST(B) = {), (} (\u56e0\u4e3a FIRST(B) \u4e0d\u542b \u03b5)<\/li>\n<\/ul>\n<\/li>\n<li><code>S \u2192 A<\/code>\uff1aS \u7684\u7b2c\u4e00\u4e2a\u7b26\u53f7\u53d6\u51b3\u4e8e A\u3002\n<ul>\n<li>FIRST(S) = FIRST(A) = {), (}<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>\u6700\u7ec8\u7684 FIRST \u96c6\uff1a<\/strong><\/p>\n<ul>\n<li>FIRST(S) = {), (}<\/li>\n<li>FIRST(A) = {), (}<\/li>\n<li>FIRST(A') = {i, \u03b5}<\/li>\n<li>FIRST(B) = {), (}<\/li>\n<li>FIRST(B') = {+, \u03b5}<\/li>\n<li>FIRST(C) = {), (}<\/li>\n<\/ul>\n<h4><strong>\u8ba1\u7b97 FOLLOW \u96c6 (Follow Set)<\/strong><\/h4>\n<p><strong>\u5b9a\u4e49\uff1a<\/strong> FOLLOW(A) \u662f\u6240\u6709\u53ef\u80fd\u51fa\u73b0\u5728\u975e\u7ec8\u7ed3\u7b26 A \u4e4b\u540e\u7684\u7ec8\u7ed3\u7b26\u7684\u96c6\u5408\u3002\u5982\u679c A \u662f\u53e5\u5b50\u7684\u6700\u540e\u4e00\u4e2a\u7b26\u53f7\uff0c\u5219 <code>$<\/code> (\u8f93\u5165\u7ed3\u675f\u7b26) \u5305\u542b\u5728 FOLLOW(A) \u4e2d\u3002<\/p>\n<p><strong>\u89c4\u5219\uff1a<\/strong><\/p>\n<ol>\n<li>\u5c06 <code>$<\/code> \u52a0\u5165 FOLLOW(S) (S \u662f\u5f00\u59cb\u7b26\u53f7)\u3002<\/li>\n<li>\u5982\u679c\u5b58\u5728\u4ea7\u751f\u5f0f A \u2192 $\\alpha$ B $\\beta$\uff1a\n<ul>\n<li>\u5c06 FIRST($\\beta$) \u4e2d\u9664 \u03b5 \u5916\u7684\u6240\u6709\u7b26\u53f7\u52a0\u5165 FOLLOW(B)\u3002<\/li>\n<li>\u5982\u679c \u03b5 \u5c5e\u4e8e FIRST($\\beta$)\uff0c\u5219\u5c06 FOLLOW(A) \u7684\u6240\u6709\u7b26\u53f7\u52a0\u5165 FOLLOW(B)\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5982\u679c\u5b58\u5728\u4ea7\u751f\u5f0f A \u2192 $\\alpha$ B\uff1a\n<ul>\n<li>\u5c06 FOLLOW(A) \u7684\u6240\u6709\u7b26\u53f7\u52a0\u5165 FOLLOW(B)\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>\u8ba1\u7b97\u8fc7\u7a0b (\u8fed\u4ee3\u8fdb\u884c\uff0c\u76f4\u5230\u96c6\u5408\u4e0d\u518d\u53d8\u5316)\uff1a<\/strong><\/p>\n<p><strong>\u521d\u59cb\u72b6\u6001\uff1a<\/strong><\/p>\n<ul>\n<li>FOLLOW(S) = {$}<\/li>\n<li>FOLLOW(A) = {}<\/li>\n<li>FOLLOW(A') = {}<\/li>\n<li>FOLLOW(B) = {}<\/li>\n<li>FOLLOW(B') = {}<\/li>\n<li>FOLLOW(C) = {}<\/li>\n<\/ul>\n<p><strong>\u8fed\u4ee3 1\uff1a<\/strong><\/p>\n<ul>\n<li><code>S \u2192 A<\/code>: \u6839\u636e\u89c4\u5219 3\uff0cFOLLOW(A) += FOLLOW(S) = {$}\u3002\n<ul>\n<li>FOLLOW(A) = {$}<\/li>\n<\/ul>\n<\/li>\n<li><code>A \u2192 B A&#039;<\/code>:\n<ul>\n<li>\u6839\u636e\u89c4\u5219 2\uff0cFOLLOW(B) += FIRST(A') = {i, \u03b5}\u3002\u6240\u4ee5 FOLLOW(B) += {i}\u3002<\/li>\n<li>\u56e0\u4e3a \u03b5 \u5c5e\u4e8e FIRST(A')\uff0c\u6240\u4ee5 FOLLOW(B) += FOLLOW(A) = {$}\u3002<\/li>\n<li>FOLLOW(B) = {i, $}<\/li>\n<\/ul>\n<\/li>\n<li><code>A&#039; \u2192 i B A&#039;<\/code>:\n<ul>\n<li>\u6839\u636e\u89c4\u5219 2\uff0cFOLLOW(B) += FIRST(A') = {i, \u03b5}\u3002\u6240\u4ee5 FOLLOW(B) += {i} (\u5df2\u5b58\u5728)\u3002<\/li>\n<li>\u56e0\u4e3a \u03b5 \u5c5e\u4e8e FIRST(A')\uff0c\u6240\u4ee5 FOLLOW(B) += FOLLOW(A')\u3002<\/li>\n<\/ul>\n<\/li>\n<li><code>B \u2192 C B&#039;<\/code>:\n<ul>\n<li>\u6839\u636e\u89c4\u5219 2\uff0cFOLLOW(C) += FIRST(B') = {+, \u03b5}\u3002\u6240\u4ee5 FOLLOW(C) += {+}\u3002<\/li>\n<li>\u56e0\u4e3a \u03b5 \u5c5e\u4e8e FIRST(B')\uff0c\u6240\u4ee5 FOLLOW(C) += FOLLOW(B) = {i, $}\u3002<\/li>\n<li>FOLLOW(C) = {+, i, $}<\/li>\n<\/ul>\n<\/li>\n<li><code>B&#039; \u2192 + C B&#039;<\/code>:\n<ul>\n<li>\u6839\u636e\u89c4\u5219 2\uff0cFOLLOW(C) += FIRST(B') = {+, \u03b5}\u3002\u6240\u4ee5 FOLLOW(C) += {+} (\u5df2\u5b58\u5728)\u3002<\/li>\n<li>\u56e0\u4e3a \u03b5 \u5c5e\u4e8e FIRST(B')\uff0c\u6240\u4ee5 FOLLOW(C) += FOLLOW(B')\u3002<\/li>\n<\/ul>\n<\/li>\n<li><code>C \u2192 ) A *<\/code>:\n<ul>\n<li>\u6839\u636e\u89c4\u5219 2\uff0cFOLLOW(A) += {*}\u3002<\/li>\n<li>FOLLOW(A) = {$, *}<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u5f53\u524d\u72b6\u6001 (\u8fed\u4ee3 1 \u7ed3\u675f)\uff1a<\/strong><\/p>\n<ul>\n<li>FOLLOW(S) = {$}<\/li>\n<li>FOLLOW(A) = {$, *}<\/li>\n<li>FOLLOW(A') = {}<\/li>\n<li>FOLLOW(B) = {i, $}<\/li>\n<li>FOLLOW(B') = {}<\/li>\n<li>FOLLOW(C) = {+, i, $}<\/li>\n<\/ul>\n<p><strong>\u8fed\u4ee3 2\uff1a<\/strong> (\u4e3b\u8981\u4f20\u64ad\u4e0a\u4e00\u6b65\u66f4\u65b0\u7684 FOLLOW \u96c6)<\/p>\n<ul>\n<li><code>A \u2192 B A&#039;<\/code>: FOLLOW(B) += FOLLOW(A) = {$, *}\u3002\n<ul>\n<li>FOLLOW(B) = {i, $, *} (\u66f4\u65b0)<\/li>\n<\/ul>\n<\/li>\n<li><code>B \u2192 C B&#039;<\/code>: FOLLOW(C) += FOLLOW(B) = {i, $, *}\u3002\n<ul>\n<li>FOLLOW(C) = {+, i, $, *} (\u66f4\u65b0)<\/li>\n<\/ul>\n<\/li>\n<li><code>A&#039; \u2192 i B A&#039;<\/code>: FOLLOW(B) += FOLLOW(A') (\u65e0\u65b0\u5185\u5bb9\uff0c\u56e0\u4e3a FOLLOW(A') \u4ecd\u4e3a\u7a7a)\u3002<\/li>\n<li><code>B&#039; \u2192 + C B&#039;<\/code>: FOLLOW(C) += FOLLOW(B') (\u65e0\u65b0\u5185\u5bb9\uff0c\u56e0\u4e3a FOLLOW(B') \u4ecd\u4e3a\u7a7a)\u3002<\/li>\n<\/ul>\n<p><strong>\u5f53\u524d\u72b6\u6001 (\u8fed\u4ee3 2 \u7ed3\u675f)\uff1a<\/strong><\/p>\n<ul>\n<li>FOLLOW(S) = {$}<\/li>\n<li>FOLLOW(A) = {$, *}<\/li>\n<li>FOLLOW(A') = {}<\/li>\n<li>FOLLOW(B) = {i, $, *}<\/li>\n<li>FOLLOW(B') = {}<\/li>\n<li>FOLLOW(C) = {+, i, $, *}<\/li>\n<\/ul>\n<p><strong>\u8fed\u4ee3 3\uff1a<\/strong> (\u7ee7\u7eed\u4f20\u64ad)<\/p>\n<ul>\n<li><code>A&#039; \u2192 i B A&#039;<\/code>: A' \u5728\u4ea7\u751f\u5f0f <code>A \u2192 B A&#039;<\/code> \u4e2d\uff0c\u4e14 A' \u53ef\u5bfc\u51fa \u03b5\u3002\u6240\u4ee5 FOLLOW(A') += FOLLOW(A) = {$, *}\u3002\n<ul>\n<li>FOLLOW(A') = {$, *} (\u66f4\u65b0)<\/li>\n<\/ul>\n<\/li>\n<li><code>B&#039; \u2192 + C B&#039;<\/code>: B' \u5728\u4ea7\u751f\u5f0f <code>B \u2192 C B&#039;<\/code> \u4e2d\uff0c\u4e14 B' \u53ef\u5bfc\u51fa \u03b5\u3002\u6240\u4ee5 FOLLOW(B') += FOLLOW(B) = {i, $, *}\u3002\n<ul>\n<li>FOLLOW(B') = {i, $, *} (\u66f4\u65b0)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>\u5f53\u524d\u72b6\u6001 (\u8fed\u4ee3 3 \u7ed3\u675f)\uff1a<\/strong><\/p>\n<ul>\n<li>FOLLOW(S) = {$}<\/li>\n<li>FOLLOW(A) = {$, *}<\/li>\n<li>FOLLOW(A') = {$, *}<\/li>\n<li>FOLLOW(B) = {i, $, *}<\/li>\n<li>FOLLOW(B') = {i, $, *}<\/li>\n<li>FOLLOW(C) = {+, i, $, *}<\/li>\n<\/ul>\n<p><strong>\u68c0\u67e5\uff1a<\/strong> \u96c6\u5408\u4e0d\u518d\u53d8\u5316\u3002<\/p>\n<p><strong>\u6700\u7ec8\u7684 FOLLOW \u96c6\uff1a<\/strong><\/p>\n<ul>\n<li>FOLLOW(S) = {$}<\/li>\n<li>FOLLOW(A) = {$, *}<\/li>\n<li>FOLLOW(A') = {$, *}<\/li>\n<li>FOLLOW(B) = {i, $, *}<\/li>\n<li>FOLLOW(B') = {i, $, *}<\/li>\n<li>FOLLOW(C) = {+, i, $, *}<\/li>\n<\/ul>\n<hr \/>\n<h3><strong>\u7b2c\u56db\u6b65\uff1a\u6784\u9020\u9884\u6d4b\u5206\u6790\u8868<\/strong><\/h3>\n<p><strong>\u5b9a\u4e49\uff1a<\/strong> \u9884\u6d4b\u5206\u6790\u8868 M \u662f\u4e00\u4e2a\u4e8c\u7ef4\u8868\uff0c\u884c\u662f\u975e\u7ec8\u7ed3\u7b26\uff0c\u5217\u662f\u7ec8\u7ed3\u7b26\uff08\u5305\u62ec <code>$<\/code>\uff09\u3002M[A, a] \u5b58\u50a8\u5f53\u6808\u9876\u662f\u975e\u7ec8\u7ed3\u7b26 A \u4e14\u5f53\u524d\u8f93\u5165\u7b26\u53f7\u662f\u7ec8\u7ed3\u7b26 a \u65f6\uff0c\u5e94\u8be5\u4f7f\u7528\u7684\u4ea7\u751f\u5f0f A \u2192 $\\alpha$\u3002<\/p>\n<p><strong>\u6784\u9020\u89c4\u5219\uff1a<\/strong><br \/>\n\u5bf9\u4e8e\u6587\u6cd5 G' \u4e2d\u7684\u6bcf\u4e2a\u4ea7\u751f\u5f0f A \u2192 $\\alpha$\uff1a<\/p>\n<ol>\n<li>\u5bf9\u4e8e FIRST($\\alpha$) \u4e2d\u7684\u6bcf\u4e00\u4e2a\u7ec8\u7ed3\u7b26 <code>a<\/code>\uff0c\u5c06 A \u2192 $\\alpha$ \u52a0\u5165 M[A, a]\u3002<\/li>\n<li>\u5982\u679c \u03b5 \u5c5e\u4e8e FIRST($\\alpha$)\uff0c\u5219\u5bf9\u4e8e FOLLOW(A) \u4e2d\u7684\u6bcf\u4e00\u4e2a\u7ec8\u7ed3\u7b26 <code>b<\/code>\uff0c\u5c06 A \u2192 $\\alpha$ \u52a0\u5165 M[A, b]\u3002<\/li>\n<\/ol>\n<p><strong>\u6784\u5efa\u8fc7\u7a0b\uff1a<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u4ea7\u751f\u5f0f<\/th>\n<th>FIRST($\\alpha$)<\/th>\n<th>FOLLOW(A) (\u4ec5\u5f53 $\\epsilon \\in$ FIRST($\\alpha$) \u65f6\u9700\u8981)<\/th>\n<th>\u586b\u5145 M[A, a]<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>S \u2192 A<\/td>\n<td>FIRST(A) = {), (}<\/td>\n<td><\/td>\n<td>M[S, )] = S\u2192A, M[S, (] = S\u2192A<\/td>\n<\/tr>\n<tr>\n<td>A \u2192 B A'<\/td>\n<td>FIRST(B A') = FIRST(B) = {), (}<\/td>\n<td><\/td>\n<td>M[A, )] = A\u2192BA', M[A, (] = A\u2192BA'<\/td>\n<\/tr>\n<tr>\n<td>A' \u2192 i B A'<\/td>\n<td>FIRST(i B A') = {i}<\/td>\n<td><\/td>\n<td>M[A', i] = A'\u2192iBA'<\/td>\n<\/tr>\n<tr>\n<td>A' \u2192 \u03b5<\/td>\n<td>FIRST(\u03b5) = {\u03b5}<\/td>\n<td>FOLLOW(A') = {$, *}<\/td>\n<td>M[A', $] = A'\u2192\u03b5, M[A', *] = A'\u2192\u03b5<\/td>\n<\/tr>\n<tr>\n<td>B \u2192 C B'<\/td>\n<td>FIRST(C B') = FIRST(C) = {), (}<\/td>\n<td><\/td>\n<td>M[B, )] = B\u2192CB', M[B, (] = B\u2192CB'<\/td>\n<\/tr>\n<tr>\n<td>B' \u2192 + C B'<\/td>\n<td>FIRST(+ C B') = {+}<\/td>\n<td><\/td>\n<td>M[B', +] = B'\u2192+CB'<\/td>\n<\/tr>\n<tr>\n<td>B' \u2192 \u03b5<\/td>\n<td>FIRST(\u03b5) = {\u03b5}<\/td>\n<td>FOLLOW(B') = {i, $, *}<\/td>\n<td>M[B', i] = B'\u2192\u03b5, M[B', $] = B'\u2192\u03b5, M[B', *] = B'\u2192\u03b5<\/td>\n<\/tr>\n<tr>\n<td>C \u2192 ) A *<\/td>\n<td>FIRST() A *) = {)}<\/td>\n<td><\/td>\n<td>M[C, )] = C\u2192)A*<\/td>\n<\/tr>\n<tr>\n<td>C \u2192 (<\/td>\n<td>FIRST(() = {(}<\/td>\n<td><\/td>\n<td>M[C, (] = C\u2192(<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u9884\u6d4b\u5206\u6790\u8868 M\uff1a<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u975e\u7ec8\u7ed3\u7b26<\/th>\n<th>(<\/th>\n<th>)<\/th>\n<th>i<\/th>\n<th>+<\/th>\n<th>*<\/th>\n<th>$<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>S<\/strong><\/td>\n<td>S\u2192A<\/td>\n<td>S\u2192A<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><strong>A<\/strong><\/td>\n<td>A\u2192BA'<\/td>\n<td>A\u2192BA'<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><strong>A'<\/strong><\/td>\n<td><\/td>\n<td><\/td>\n<td>A'\u2192iBA'<\/td>\n<td><\/td>\n<td>A'\u2192\u03b5<\/td>\n<td>A'\u2192\u03b5<\/td>\n<\/tr>\n<tr>\n<td><strong>B<\/strong><\/td>\n<td>B\u2192CB'<\/td>\n<td>B\u2192CB'<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><strong>B'<\/strong><\/td>\n<td><\/td>\n<td><\/td>\n<td>B'\u2192\u03b5<\/td>\n<td>B'\u2192+CB'<\/td>\n<td>B'\u2192\u03b5<\/td>\n<td>B'\u2192\u03b5<\/td>\n<\/tr>\n<tr>\n<td><strong>C<\/strong><\/td>\n<td>C\u2192(<\/td>\n<td>C\u2192)A*<\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>LL(1) \u6587\u6cd5\u5224\u65ad\uff1a<\/strong><br \/>\n\u89c2\u5bdf\u4e0a\u8ff0\u9884\u6d4b\u5206\u6790\u8868\uff0c\u6bcf\u4e2a\u5355\u5143\u683c\u6700\u591a\u53ea\u5305\u542b\u4e00\u4e2a\u4ea7\u751f\u5f0f\u3002\u8fd9\u8868\u660e\u8be5\u6587\u6cd5\u662f\u4e00\u4e2a LL(1) \u6587\u6cd5\u3002\u5982\u679c\u4efb\u4f55\u5355\u5143\u683c\u5305\u542b\u591a\u4e2a\u4ea7\u751f\u5f0f\uff0c\u5219\u8be5\u6587\u6cd5\u4e0d\u662f LL(1) \u6587\u6cd5\u3002<\/p>\n<hr \/>\n<h3><strong>\u603b\u7ed3<\/strong><\/h3>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u6211\u4eec\u6210\u529f\u5730\u5c06\u539f\u59cb\u6587\u6cd5\u6539\u5199\u4e3a LL(1) \u6587\u6cd5\uff0c\u8ba1\u7b97\u4e86\u6240\u6709\u975e\u7ec8\u7ed3\u7b26\u7684 FIRST \u548c FOLLOW \u96c6\uff0c\u5e76\u6784\u5efa\u4e86\u76f8\u5e94\u7684\u9884\u6d4b\u5206\u6790\u8868\u3002\u8fd9\u4e2a\u9884\u6d4b\u5206\u6790\u8868\u53ef\u4ee5\u7528\u4e8e\u81ea\u9876\u5411\u4e0b\u7684\u8bed\u6cd5\u5206\u6790\u5668\uff0c\u6839\u636e\u8f93\u5165\u7b26\u53f7\u548c\u6808\u9876\u975e\u7ec8\u7ed3\u7b26\u6765\u786e\u5b9a\u4e0b\u4e00\u6b65\u7684\u63a8\u5bfc\u89c4\u5219\uff0c\u4ece\u800c\u89e3\u6790\u8f93\u5165\u5b57\u7b26\u4e32\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u95ee\u9898\uff1a \u7ed9\u5b9a\u6587\u6cd5 G[S]: S \u2192 A A \u2192 B | A i B B \u2192 C | B + C C \u2192 ) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[11],"class_list":["post-149","post","type-post","status-publish","format-standard","hentry","category-8","tag-11"],"_links":{"self":[{"href":"https:\/\/blog.notiq.cn\/index.php\/wp-json\/wp\/v2\/posts\/149","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.notiq.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.notiq.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.notiq.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.notiq.cn\/index.php\/wp-json\/wp\/v2\/comments?post=149"}],"version-history":[{"count":0,"href":"https:\/\/blog.notiq.cn\/index.php\/wp-json\/wp\/v2\/posts\/149\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.notiq.cn\/index.php\/wp-json\/wp\/v2\/media?parent=149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.notiq.cn\/index.php\/wp-json\/wp\/v2\/categories?post=149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.notiq.cn\/index.php\/wp-json\/wp\/v2\/tags?post=149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}