±àÒëÔ­Àí¸´Ï°Ìâ-¸øѧÉú£¨¼ò£©

¡¶±àÒëÔ­Àí¡·¸´Ï°Ìâ

G(S): S ? (L) | a L ? SL¡¯ L¡¯ ? , SL¡¯| ¦Å

¹¹ÔìFIRST¼¯£¬ÈçÏ£º £¨1£©FIRST(S) = {(, a} £¨2£©FIRST(L) = {(, a} £¨3£©FIRST(L¡¯) = {,, ¦Å}

¹¹ÔìFOLLOW¼¯ÈçÏ£º £¨1£©FOLLOW(S) = {#, ,, )} £¨2£©FOLLOW(L) = {)} £¨3£©FOLLOW(L¡¯) = {)}

LL(1)·ÖÎö±í S L L¡¯ ( S ? (L) L ? SL¡¯ ) L¡¯ ? ¦Å a S ? a L ? SL¡¯ , L¡¯ ? ,SL¡¯ #

15£®ÅжÏÎÄ·¨G[S]: S ¡ú BA A ¡ú BS | d B ¡ú aA| bS | c ÊÇ·ñΪLL(1)ÎÄ·¨.

½â£º¶ÔÓÚ¸ÃÎÄ·¨ÇóÆäFIRST¼¯ÈçÏ£º

FIRST(S) = {a, b, c}; FIRST(A) = {a, b, c, d}; FIRST(B) = {a, b, c}¡£ ÇóÆäFOLLOW¼¯ÈçÏ£º

FOLLOW(S) = {a, b, c, d, #}; FOLLOW(A) = {a, b, c, d, #}; FOLLOW(B) = {a, b, c, d, #}¡£ ÓÉA ¡ú BS | d µÃ£º

FIRST(BS) ¡É FIRST(¡®d¡¯) = {a, b, c} ¡É {d} = ¦µ ÓÉB ¡ú aA| bS | c µÃ

FIRST(aA) ¡É FIRST(bS) ¡É FIRST(c) = {a} ¡É{b}¡É {c} =¦µ

ÓÉÓÚÎÄ·¨G[S]²»´æÔÚÐÎÈç¦Â¡ú¦ÅµÄ²úÉúʽ£¬¹ÊÎÞÐèÇó½âÐÎÈçFIRST(¦Á) ¡É FOLLOW(A)µÄÖµ£¬Ò²¼´ÎÄ·¨G[S]ÊÇÒ»¸öLL(1)ÎÄ·¨¡£ 16£®¶ÔÓÚÎÄ·¨G[E]: E¡úE+T | T

T¡úT+P | P P¡ú(E) | i

д³ö¾äÐÍP+T+(E+i)µÄËùÓжÌÓï¡¢Ö±½Ó¶ÌÓï¡¢¾ä±ú¡£ ½â£º¶ÌÓP¡¢i¡¢E+i¡¢(E+i )¡¢T+(E+i )¡¢P+T+(E+i )£» Ö±½Ó¶ÌÓP¡¢i£» ¾ä±ú£ºP£»

17£®ÒÑÖªÎÄ·¨G[S]: S¡úaSbS|bSaS|¦Å ÊÔÖ¤Ã÷G[S]ÊǶþÒåÎÄ·¨

21

¡¶±àÒëÔ­Àí¡·¸´Ï°Ìâ

Ö¤Ã÷£º ¸ÃÎÄ·¨²úÉúµÄÓïÑÔÊÇaµÄ¸öÊýºÍbµÄ¸öÊýÏàµÈµÄ´®µÄ¼¯ºÏ¡£¸ÃÎÄ·¨¶þÒ壬ÀýÈç¾ä×ÓababÓÐÁ½ÖÖ²»Í¬µÄ×î×óÍƵ¼¡£

S?aSbS?abS?abaSbS?ababS?abab S?aSbS?abSaSbS?abaSbS?ababS?abab

18£®½«ÏÂÃæµÄÓï¾ä·­Òë³ÉËÄԪʽÐòÁУº while(a

if (c£¾d) x=y+z

½â£º100 (j<,a,b,102)

101 (j,_,_,107) 102 (j>,c,d,104) 103 (j,_,_,106) 104 (+,y ,z ,t) 105 (=,t ,_ ,x) 106 (j,_,_,100) 107:

19£®¹¹ÔìÕý¹æ±í´ïʽa(aa)*bb(bb)*a µÄ×îС»¯µÄÈ·¶¨ÓÐÏÞ×Ô¶¯»úM¡ä¡£ ½â£º ÏÈ»­³öÕý¹æʽÏàÓ¦µÄNFA M״̬ͼ£¬ÈçÏÂͼËùʾ¡£

2 5

a a b b

a b b a X 1 3 4

ÓÃ×Ó¼¯·¨¹¹Ôì״̬ת»»¾ØÕó£¬ÈçϱíËùʾ¡£

I {x} {1} {2} {3} {4} {5} {Y} Y Ia {1} {2} {1} - {Y} - - Ib - {3} - {4} {5} {4} -

½«×´Ì¬·ÖΪÖÕ̬¼¯{Y}ºÍ·ÇÖÕ̬¼¯{X,1,2,3,4,5} ÒòΪ£ûX,1,2,3,4,5£ýa={1,2,1,_,Y,_} ËùÒÔ·ÇÖÕ̬¼¯·ÖΪ{X,1,2},{3,5},{4} ÒòΪ{X,1,2}b={_,3,_},ËùÒÔ·ÖΪ

×îºóµÃµ½¼¯ºÏ{X,2},{1},{3,5},{4},{Y}ÖØÐÂÃüÃûΪ1£¬2£¬3£¬4£¬5µÃµ½×îС»¯µÄDFA M¡ä״̬ת»»¾ØÕóºÍ

22

¡¶±àÒëÔ­Àí¡·¸´Ï°Ìâ

״̬ת»»Í¼ÈçÏÂͼËùʾ¡£ I Ia Ib 1 2 _ 2 1 3 a b b a 3 - 4 1 a 2 3 4 5 4 5 3 b 5 - _

£¨×¢Ò⣺±¾ÌâÓÉÓÚ¼¯ºÏµÄÃüÃûºÍÏȺó˳Ðò²»Í¬£¬¿ÉÄÜ×îÖÕ½á¹û²»Í¬¡££© 20£®ÊÔ¹¹ÔìÏÂÊöÎÄ·¨µÄSLR(1)·ÖÎö±í¡£

G[A]: A¡úaABl|a

B¡úBb|d

½â£ºÍعãÎÄ·¨ £¨0£©S¡úA

£¨1£©A¡úaABl £¨2£©A¡úa £¨3£©B¡úBb £¨4£©B¡úd

I0£ºS¡ú£®A A I1£ºS¡úA£® A¡ú£®aABl A¡ú£®a a I2£ºA¡úa£®ABl Bl A¡úa£® A I3£ºA¡úaA£®B¡ú£®Bb d I4£ºB¡úd£® A¡ú£®aABl B¡ú£®d A¡ú£®a B a I5£º l I6£º A¡úaAB£®l A¡úaABl£® B¡úB£®b b I7£º B¡úBb£®

First£¨A£©={a}follow£¨A£©={#£¬d} First£¨B£©={d}follow£¨B£©={l}

SLR£¨1£©·ÖÎö±íÈçÏ£º

23

¡¶±àÒëÔ­Àí¡·¸´Ï°Ìâ

a 0 1 2 3 4 5 6 7 S2 S2 b S7 ACTION d l R4 S6 R3 # ACC R2 R1 A 1 3 GOTO B 5 R2 S4 R1 21£®»­³ö±àÒë³ÌÐòµÄ×ÜÌå½á¹¹Í¼£¬¼òÊö¸÷²¿·ÖµÄÖ÷Òª¹¦ÄÜ¡£

½â£º±àÒë³ÌÐòµÄ×ÜÌå¿òͼÈçÏÂËùʾ£º

±í´Ê·¨·ÖÎöÆ÷µ¥´Ê·ûºÅÓï·¨·ÖÎöÆ÷Óï·¨µ¥Î»ÓïÒå·ÖÎöÓëÖмä´úÂëÉú³ÉÆ÷³ö¸ñ´í¹ÜËÄԪʽÓÅ»¯¶ÎËÄԪʽĿ±ê´úÂëÉú³ÉÆ÷Ä¿±ê´úÂë´¦ÀíÀí £¨1£©´Ê·¨·ÖÎöÆ÷£¬ÓÖ³ÆɨÃèÆ÷£¬Ëü½ÓÊÜÊäÈëµÄÔ´³ÌÐò£¬¶ÔÔ´³ÌÐò½øÐдʷ¨·ÖÎö£¬Ê¶±ð³öÒ»¸ö¸öµ¥´Ê·ûºÅ£¬ÆäÊä³ö½á¹ûÊǶþԪʽ(µ¥´ÊÖֱ𣬵¥´Ê×ÔÉíµÄÖµ)Á÷¡£

£¨2£©Óï·¨·ÖÎöÆ÷£¬¶Ôµ¥´Ê·ûºÅ´®½øÐÐÓï·¨·ÖÎö£¨¸ù¾ÝÓï·¨¹æÔò½øÐÐÍƵ¼»ò¹éÔ¼£©£¬Ê¶±ð³ö³ÌÐòÖеĸ÷ÀàÓï·¨µ¥Î»£¬×îÖÕÅжÏÊäÈë´®ÊÇ·ñ¹¹³ÉÓï·¨ÉÏÕýÈ·µÄ¾ä×Ó¡£

£¨3£©ÓïÒå·ÖÎö¼°Öмä´úÂëÉú³ÉÆ÷£¬°´ÕÕÓïÒå¹æÔò¶ÔÓï·¨·ÖÎöÆ÷¹éÔ¼³ö£¨»òÍƵ¼³ö£©µÄÓï·¨µ¥Î»½øÐÐÓïÒå·ÖÎö²¢°ÑËüÃÇ·­Òë³ÉÒ»¶¨ÐÎʽµÄÖмä´úÂë¡£±àÒë³ÌÐò¿ÉÒÔ¸ù¾Ý²»Í¬µÄÐèҪѡÔñ²»Í¬µÄÖмä´úÂëÐÎʽ£¬ÓеıàÒë³ÌÐòÉõÖÁûÓÐÖмä´úÂëÐÎʽ£¬¶øÖ±½ÓÉú³ÉÄ¿±ê´úÂë¡£

£¨4£©ÓÅ»¯Æ÷¶ÔÖмä´úÂë½øÐÐÓÅ»¯´¦Àí¡£Ò»°ã×î³õÉú³ÉµÄÖмä´úÂëÖ´ÐÐЧÂʶ¼±È½ÏµÍ£¬Òò´ËÒª×öÖмä´úÂëµÄÓÅ»¯£¬Æä¹ý³Ìʵ¼ÊÉÏÊǶÔÖмä´úÂë½øÐеȼÛÌæ»»£¬Ê¹³ÌÐòÔÚÖ´ÐÐʱÄܸü¿ì£¬²¢Õ¼ÓøüСµÄ¿Õ¼ä¡£ £¨5£©Ä¿±ê´úÂëÉú³ÉÆ÷£¬°ÑÖмä´úÂë·­Òë³ÉÄ¿±ê³ÌÐò¡£Öмä´úÂëÒ»°ãÊÇÒ»ÖÖÓë»úÆ÷Î޹صıíʾÐÎʽ£¬Ö»ÓаÑËüÔÙ·­Òë³ÉÓë»úÆ÷Ó²¼þÖ±½ÓÏà¹ØµÄ»úÆ÷ÄÜʶ±ðµÄÓïÑÔ£¬¼´Ä¿±ê³ÌÐò£¬²ÅÄÜÔÚ»úÆ÷ÉÏÔËÐС£

£¨6£©±í¸ñ¹ÜÀíÄ£¿é±£³ÖһϵÁеıí¸ñ£¬µÇ¼ÇÔ´³ÌÐòµÄ¸÷ÀàÐÅÏ¢ºÍ±àÒë¸÷½×¶ÎµÄ½øÕ¹×´¿ö¡£±àÒë³ÌÐò¸÷¸ö½×¶ÎËù²úÉúµÄÖмä½á¹û¶¼¼Ç¼ÔÚ±í¸ñÖУ¬ËùÐèÒªµÄÐÅÏ¢Ò²´ó¶à´Ó±í¸ñÖлñÈ¡£¬Õû¸ö±àÒë¹ý³Ì¶¼ÔÚ²»¶ÏºÍ±í¸ñ´ò½»µÀ¡£

24

ÁªÏµ¿Í·þ£º779662525#qq.com(#Ì滻Ϊ@)