{"id":196,"date":"2021-06-07T12:01:31","date_gmt":"2021-06-07T04:01:31","guid":{"rendered":"https:\/\/swordofmorning.com\/?p=196"},"modified":"2025-10-09T13:56:21","modified_gmt":"2025-10-09T05:56:21","slug":"compilation-principle-04-select-set-and-ll1-grammar","status":"publish","type":"post","link":"https:\/\/swordofmorning.com\/index.php\/2021\/06\/07\/compilation-principle-04-select-set-and-ll1-grammar\/","title":{"rendered":"\u7f16\u8bd1\u539f\u7406 04 Select\u96c6\u548cLL(1)\u6587\u6cd5"},"content":{"rendered":"<p><div class=\"has-toc have-toc\"><\/div><br \/>\n&nbsp;&nbsp;&amp;nbsp&nbsp;\u5728\u524d\u9762\u6211\u4eec\u5df2\u7ecf\u4ecb\u7ecd\u4e86<a href=\"https:\/\/swordofmorning.com\/index.php\/2021\/06\/07\/compilation-principle-02-first-set-and-follow-set-method\/\" title=\"\u300aFirst\u96c6\u4e0eFollow\u96c6\u300b\">\u300aFirst\u96c6\u4e0eFollow\u96c6\u300b<\/a>\uff0c\u4e0b\u9762\u6211\u4eec\u5c06\u4ecb\u7ecdSelect\u96c6\uff0c\u4ee5\u53ca\u5b83\u548cLL(1)\u578b\u6587\u6cd5\u7684\u5173\u7cfb\u3002<\/p>\n<h2>\u4e00\u3001Select\u96c6\u7684\u6784\u9020<\/h2>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u7ed9\u5b9a\u6587\u6cd5 G\uff0c\u5bf9\u4e8e\u4ea7\u751f\u5f0f A\u2192\u03b1\uff0c\u03b1 \u2208 V*\uff0c\u5219\u53ef\u9009\u96c6 SELECT(A\u2192\u03b1) \u6709\uff1a<\/p>\n<ul>\n<li>\uff081\uff09\u82e5 \u03b1 \u2260 \u03b5\uff0c\u4e14 \u03b1 \u2260+&gt; \u03b5\uff0c\u5219 SELECT(A\u2192\u03b1) = FIRST(\u03b1)<\/li>\n<li>\uff082\uff09\u82e5 \u03b1 \u2260 \u03b5\uff0c\u4f46 \u03b1 =+&gt; \u03b5\uff0c\u5219 SELECT(A\u2192\u03b1) = FIRST(\u03b1) \u222a FOLLOW(A)<\/li>\n<li>\uff083\uff09\u82e5 \u03b1 = \u03b5\uff0c\u5219 SELECT(A\u2192\u03b1) = FOLLOW(A)<\/li>\n<\/ul>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u7b2c 1 \u6761\u662f\uff0c\u5f53 \u03b1 \u2260 \u03b5\uff0c\u4e14\u901a\u8fc71\u6b21\u6216\u591a\u6b21\u63a8\u4e0d\u51fa \u03b5\uff0cSELECT(A\u2192\u03b1) = FIRST(\u03b1)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\u7b2c 2 \u6761\u662f\uff0c\u5f53 \u03b1 \u2260 \u03b5\uff0c\u4f46 \u03b1 \u7ecf\u6709\u9650\u6b65\u53ef\u63a8\u51fa \u03b5\uff0cSELECT(A\u2192\u03b1) = FIRST(\u03b1) \u222a FOLLOW(A)\uff08\u6ce8\u610f\u662f\u4e00\u4e2a \u03b1\uff0c\u4e00\u4e2a A\uff09<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;\u7b2c 3 \u6761\u662f\uff0c\u5f53 \u03b1 = \u03b5\uff0cSELECT \u96c6\u5c31\u7b49\u4e8e\u5de6\u90e8 A \u7684 FOLLOW \u96c6<\/p>\n<h3>1.1 \u4e0b\u9762\u6765\u770b\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/h3>\n<p>A \u2192 BCc | gDB<br \/>\nB \u2192 bCDE | \u03b5<br \/>\nC \u2192 DaB | ca<br \/>\nD \u2192 dD | \u03b5<br \/>\nE \u2192 gAf | c<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u975e\u7ec8\u7ed3\u7b26<\/th>\n<th style=\"text-align: center;\">First<\/th>\n<th style=\"text-align: center;\">Follow<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">A<\/td>\n<td style=\"text-align: center;\">{ a, b, c, d, g }<\/td>\n<td style=\"text-align: center;\">{ f, # }<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">B<\/td>\n<td style=\"text-align: center;\">{ b, \u03b5 }<\/td>\n<td style=\"text-align: center;\">{ a, c, d, g, f, # }<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">C<\/td>\n<td style=\"text-align: center;\">{ a, c, d }<\/td>\n<td style=\"text-align: center;\">{ c, d, g }<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">D<\/td>\n<td style=\"text-align: center;\">{ d, \u03b5 }<\/td>\n<td style=\"text-align: center;\">{ a, b, c, g, f, # }<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">E<\/td>\n<td style=\"text-align: center;\">{ c, g }<\/td>\n<td style=\"text-align: center;\">{ a, c, d, g, f, # }<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u53f3\u8fb9\u7684\u4ea7\u751f\u5f0f<\/th>\n<th style=\"text-align: center;\">First<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">BCc<\/td>\n<td style=\"text-align: center;\">{ a, b, c, d }<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">gDB<\/td>\n<td style=\"text-align: center;\">{ g }<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">bCDE<\/td>\n<td style=\"text-align: center;\">{ b }<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u03b5<\/td>\n<td style=\"text-align: center;\">{ \u03b5 }<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">DaB<\/td>\n<td style=\"text-align: center;\">{a, d}<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">ca<\/td>\n<td style=\"text-align: center;\">{ c }<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">dD<\/td>\n<td style=\"text-align: center;\">{ d }<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">gAf<\/td>\n<td style=\"text-align: center;\">{ g }<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">c<\/td>\n<td style=\"text-align: center;\">{ c }<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u6839\u636e\u4e0a\u8868\uff0c\u53ef\u6c42\u51faSelect\u96c6\u5982\u4e0b\uff1a<br \/>\nSELECT(A \u2192 BCc) = { a, b, c, d }<br \/>\nSELECT(A \u2192 gDB) = { g }<br \/>\nSELECT(B \u2192 bCDE) = { b }<br \/>\nSELECT(B \u2192 \u03b5) = { a, c, d, g, f, # }<br \/>\nSELECT(C \u2192 DaB) = { a, d }<br \/>\nSELECT(C \u2192 ca) = { c }<br \/>\nSELECT(D \u2192 dD) = { d }<br \/>\nSELECT(D \u2192 \u03b5) = { a, b, c, g, f, # }<br \/>\nSELECT(E \u2192 gAf) = { g }<br \/>\nSELECT(E \u2192 c) = { c }<\/p>\n<h2>\u4e8c\u3001Select\u96c6\u4e0eLL(1)\u578b\u6587\u6cd5<\/h2>\n<h3>2.1 LL(1)\u578b\u6587\u6cd5\u7684\u5224\u5b9a<\/h3>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u5982\u679c\u6709\u76f8\u540c\u5de6\u90e8\u7684Select\u96c6\u4ea4\u96c6\u4e3a\u7a7a\uff0c\u5219\u662fLL(1)\u578b\u6587\u6cd5\u3002<\/p>\n<h3>2.2 \u4f7f\u7528Select\u96c6\u6784\u5efaLL(1)\u5206\u6790\u8868<\/h3>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u6784\u9020\u65b9\u6cd5\uff1a<\/p>\n<ol>\n<li>\u82e5 a\u2208SELECT(A\u2192\u03b1)\uff0c\u5219\u628a A\u2192\u03b1 \u52a0\u81f3 M[A, a] \u4e2d\u3002<\/li>\n<li>\u628a\u6240\u6709\u65e0\u5b9a\u4e49\u7684 M[A, a] \u6807\u4e0a\u201c\u51fa\u9519\u6807\u5fd7\u201d\u3002\u4e3a\u4e86\u4f7f\u8868\u7b80\u5316\uff0c\u8868\u4e2d\u7a7a\u767d\u5904\u4e3a\u51fa\u9519\u3002<\/li>\n<\/ol>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u4e0b\u9762\u770b\u53e6\u4e00\u4e2a\u4f8b\u5b50\uff1a<br \/>\nG[S]: S \u2192 aH<br \/>\nH \u2192 aMd<br \/>\nH \u2192 d<br \/>\nM \u2192 Ab<br \/>\nM \u2192 \u03b5<br \/>\nA \u2192 aM<br \/>\nA \u2192 e<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u4ea7\u751f\u5f0f<\/th>\n<th style=\"text-align: center;\">First<\/th>\n<th style=\"text-align: center;\">Follow<\/th>\n<th style=\"text-align: center;\">Select<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">S \u2192 aH<\/td>\n<td style=\"text-align: center;\">{ a }<\/td>\n<td style=\"text-align: center;\">FOLLOW(S) = { # }<\/td>\n<td style=\"text-align: center;\">SELECT(S\u2192aH) = FIRST(aH) = { a }<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">H \u2192 aMd<\/td>\n<td style=\"text-align: center;\">{ a }<\/td>\n<td style=\"text-align: center;\">FOLLOW(H) = { # }<\/td>\n<td style=\"text-align: center;\">SELECT(H\u2192aMd) = FIRST(aMd) = { a }<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">H \u2192 d<\/td>\n<td style=\"text-align: center;\">{ d }<\/td>\n<td style=\"text-align: center;\"><\/td>\n<td style=\"text-align: center;\">SELECT(H\u2192d) = FIRST(d) = { d }<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">M \u2192 Ab<\/td>\n<td style=\"text-align: center;\">{ a, e }<\/td>\n<td style=\"text-align: center;\">FOLLOW(M) = { b, d }<\/td>\n<td style=\"text-align: center;\">SELECT(M\u2192Ab) = FIRST(Ad) = { a, e }<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">M \u2192 \u03b5<\/td>\n<td style=\"text-align: center;\">{ \u03b5 }<\/td>\n<td style=\"text-align: center;\"><\/td>\n<td style=\"text-align: center;\">SELECT(M\u2192\u03b5) = FOLLOW(M) ={ d, b }<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">A \u2192 aM<\/td>\n<td style=\"text-align: center;\">{ a }<\/td>\n<td style=\"text-align: center;\">FOLLOW(A) = { b }<\/td>\n<td style=\"text-align: center;\">SELECT(A\u2192aM) = FIRST(aM) = { a }<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">A \u2192 e<\/td>\n<td style=\"text-align: center;\">{ e }<\/td>\n<td style=\"text-align: center;\"><\/td>\n<td style=\"text-align: center;\">SELECT(A\u2192e) = FIRST(e) = { e }<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;\u6839\u636e\u4e0a\u9762\u6c42\u51fa\u7684Select\u96c6\uff0c\u5c31\u53ef\u4ee5\u5199\u51faLL(1)\u5206\u6790\u8868\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\"><\/th>\n<th style=\"text-align: center;\">a<\/th>\n<th style=\"text-align: center;\">b<\/th>\n<th style=\"text-align: center;\">d<\/th>\n<th style=\"text-align: center;\">d<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\"><strong>S<\/strong><\/td>\n<td style=\"text-align: center;\">S \u2192 aH<\/td>\n<td style=\"text-align: center;\"><\/td>\n<td style=\"text-align: center;\"><\/td>\n<td style=\"text-align: center;\"><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\"><strong>H<\/strong><\/td>\n<td style=\"text-align: center;\">H \u2192 aMd<\/td>\n<td style=\"text-align: center;\"><\/td>\n<td style=\"text-align: center;\">H \u2192 d<\/td>\n<td style=\"text-align: center;\"><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\"><strong>M<\/strong><\/td>\n<td style=\"text-align: center;\">M \u2192 Ab<\/td>\n<td style=\"text-align: center;\">M \u2192 \u03b5<\/td>\n<td style=\"text-align: center;\">M \u2192 \u03b5<\/td>\n<td style=\"text-align: center;\">M \u2192 Ab<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\"><strong>A<\/strong><\/td>\n<td style=\"text-align: center;\">A \u2192 aM<\/td>\n<td style=\"text-align: center;\"><\/td>\n<td style=\"text-align: center;\"><\/td>\n<td style=\"text-align: center;\">A \u2192 e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;&nbsp;&amp;nbsp&nbsp;\u5728\u524d\u9762\u6211\u4eec\u5df2\u7ecf\u4ecb\u7ecd\u4e86\u300aFirst\u96c6\u4e0eFollow\u96c6\u300b\uff0c\u4e0b\u9762\u6211\u4eec\u5c06\u4ecb\u7ecdSele &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/196"}],"collection":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/comments?post=196"}],"version-history":[{"count":1,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/196\/revisions"}],"predecessor-version":[{"id":1043,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/196\/revisions\/1043"}],"wp:attachment":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/media?parent=196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/categories?post=196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/tags?post=196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}