ãŸã äžåãã®æ§æ解æãè¡ã£ãŠããŸãã ä»ã«ã©ããªãªãã·ã§ã³ããããŸããïŒ
ãã€ãœã³ãèã«çœ®ããçè«ã«æ»ããŸãã
ããã«æçš¿ïŒ
- ã¢ã€ãã¢
- å身
- ããªããŒ
- ããã¯ãã©ããã³ã°
ã¢ã€ãã¢
äžåã解æã®
äžè¬çãªèãæ¹ã¯æ¬¡ã®ãšããã§ããå
¥åè¡ãèªã¿åããäžåºŠã«1æåãã€ã¹ã¿ãã¯ã«ã·ããããŸãã ææ³èŠåã«äžèŽããçµã¿åãããã¹ã¿ãã¯ã®æäžéšã§åœ¢æããããšããã«ãããã1ã€ã®éçµç«¯èšå·ã«ãŸãšããŠç¶è¡ããŸãã
ãã®æ¹æ³ã®éèŠãªç¹åŸŽã¯ãã«ãŒã«ã®æãããã¿äžã«ãã¹ãŠã®ã³ã³ããŒãã³ããæå
ã«
çšæããå¿
èŠãªæ§é ã§
ãããããããªãŒãæ§ç¯ããã
ãèšç®ã®ããã«å€åºå
ã§ã䜿çšã§ããããšã§ãã
å察ã®ã¢ãããŒãã¯ãææ³ã®æåã®ã·ã³ãã«ã®
å±éãéå§ãã次ã®å
¥åã·ã³ãã«ã«åŸã£ãŠå±éå¯èœãªã«ãŒã«ãéžæããããšã§ãã
ããšãã°ãææ³ã«èŠåãããå Žå
OPïŒ '{' OPS '}' //ãããã¯
| EXPR ';' //åŒ
| 'if' 'ïŒ' EXPR 'ïŒ' OP
| 'if' 'ïŒ' EXPR 'ïŒ' OP 'else' OP
| 'while' 'ïŒ' EXPR 'ïŒ' OP
| 'exit' ';' ;
ããã¹ãã®ããã«å
ã«
while
ãããããšãããããŸãããã®åŸã
OP: 'while' '(' EXPR ')' OP ;
ã«ãŒã«ã«åŸã£ãŠå±éã
OP: 'while' '(' EXPR ')' OP ;
ã¹ãã¢ãã·ã³ã®å Žåããã®ãããªè§£æã¯æ¬¡ã®ããã«å®è£
ã§ããŸãã
- å±éäžã«ãã«ãŒã«ã®æ£ããéšåãã¹ã¿ãã¯ã«æžã蟌ã¿ãŸããããã«å¿ããŠããã¹ãã®ç¶ç¶ã解æããŸãã
- ã¹ã¿ãã¯ã®æäžéšã«ç«¯æ«ããããå
¥åããã¹ãã«åã端æ«ãããå Žåãããã¹ãã¯æåŸ
ã©ããã§ãã ã¹ã¿ãã¯ããäžäœç«¯æ«ãåé€ããããã¹ãã®æ¬¡ã®æåãèªã¿åããŸãã
- ã¹ã¿ãã¯ã®æäžéšãéçµç«¯ã®å Žåããããå±éããå¿
èŠããããŸãã å
¥åã·ã³ãã«ã«åºã¥ããŠéçºã®ã«ãŒã«ãéžæããŸãã
ã¹ã€ãŒãäžã«ã¢ã¯ã·ã§ã³ãå®è¡ããããšã¯ç¡æå³ã§ããããšã«ããã«æ³šæããŸããå±éãããã«ãŒã«ã®å³éšåã¯ãŸã èªã¿åãããŠããããèªã¿åããããã©ããã¯ãŸã£ããããããŸããã å±éãããšãã«ãå³ã®éšåã®ã·ã³ãã«ã®äžã®ã¹ã¿ãã¯ã«ãããŒä¿¡å·ãé
眮ããããšãã§ããŸãããã«ãŒã«ãæ£åžžã«èªã¿åãããŸãããã¢ã¯ã·ã§ã³ãå®è¡ã§ããŸããã ãããããã®ç¬éãŸã§ã«ãå³åŽå
šäœãæ¢ã«ã¹ã¿ãã¯ããæ¶å»ãããŠããŸãïŒ ã¢ã¯ã·ã§ã³ã¯äœãšé£æºããŸããïŒ
ããããäžåãæ§æ解æã®äž»ãªé£ããã¯ããã§ã¯ãªããéçºã«é©åãªã«ãŒã«ãéžæããæ¹æ³ã§ãã
ãã€ãœã³ã«ã¯åŒ·ãããææ³ãæãåºããŠãã ããã
WORDïŒS1 'a' 'i' 'l' | S2 'a' 'l' 'e';
S1ïŒ 's';
S2ïŒ 's';
次ã®æåã
's'
ãšããã©ã®ããã«
WORD
ãã¢ã³ã©ããããŸããïŒ
éžææ¹æ³ã¯äžæã§ã
WORD
äž¡æ¹ã®èŠåã¯ãæ£ç¢ºã«
's'
å§ãŸããŸãã
å身
ãã·ã³ãè€æ°ã®æåãå
èªã¿ã§ããããã«ããããšãã§ããŸããã¬ãã¥ãŒã«ããå€æãããšããã®ã¢ãããŒãã¯äººæ°ã®LLããŒãµãŒãžã§ãã¬ãŒã¿ãŒã§ããANTLRã§äœ¿çšãããŸããã
æè¡çãªé£ããã¯ãã¹ã€ãŒãã®éçºãäŸåããæ°ãããã£ã©ã¯ã¿ãŒããšã«ãé·ç§»ããŒãã«ã®
次å
ãå¢å ããããšã§ãã ãããã£ãŠãããã¹ããã3æåïŒã¹ã¿ãã¯ãã1æåïŒãèªã¿åãNç¶æ
ã®ãªãŒãããã³ã®éå§çž®ããŒãã«ã«ã¯ãNã»256
4èŠçŽ ïŒæ°åã®ã¬ãã€ãïŒãå«ãŸããŸãã
ãããã£ãŠãLLããŒã·ã³ã°ã®é©çšå
ã¯ãããŒãµãŒãžã§ãã¬ãŒã¿ãŒãããŒãã«ãå¹ççã«å§çž®ããèœåã«ãã£ãŠæ£ç¢ºã«æ±ºå®ãããŸãïŒãã€ãœã³ã258x14ã®ããŒãã«ã7ã€ã®çã1次å
é
åã«å§çž®ããæ¹æ³ãæãåºããŠãã ããïŒã
ç§ãç解ããŠããéãããã¹ãŠããã¹ãŠã®äººã«åé¡ããªããããé·è·é¢å
èªã¿ã®LRããŒãµãŒã¯ããã§ã¯ãããŸãããé·è·é¢ã®æ€çŽ¢ãäžååã§ããããšã«èµ·å ãã競åã¯LRããŒãµãŒã§ã¯ãŸãã§ãã ãã€ãœã³ãç§ãã¡ã®ææ³ãèªèã§ããããã«ã2ã€ã®åäžã®ç³ã¿èŸŒã¿ã®äžããéžæããããã«é ŒãŸãªããŠãååã§ãã
WORDïŒ 's' 'a' 'i' 'l' | ãsããaããlããeã;
äžæ¹ãLLããŒãµãŒã§ã¯äœãå€æŽãããŠããŸããã以åã®ããã«ãäž¡æ¹ã®ã«ãŒã«ã¯
's'
æåã«å¯Ÿå¿ããŠããŸãã ãããã£ãŠãLLæ§æ解æã®ææ³ããé©åããããããã«ãåãéçµç«¯èšå·ã«å¯ŸããããŸããŸãªèŠåã®äžè¬çãªå§ãŸãããè£å©éçµç«¯èšå·ãã«åãåºãããŸãã
WORD1ïŒ 's' 'a' WORD;
WORDïŒ 'i' 'l' | 'l' 'e';
ãã®ããªãã¯ã¯ãå·Šå åå解ããšåŒã°ããŸããããã¯ããå
±éå åããåçã«éå§ãããã«ãŒã«ããåãåºããããã®ããã§ãã
ããã§ã
WORD1
ã¹ã€ãŒãã¯äžæã§ããã
WORD
2ã€ã®ã¹ã€ãŒãã¯ç°ãªãæåã§å§ãŸããŸãã
ANTLR miracle-squeezerãå¿
èŠãªã ãå
èªã¿ã§ããã®ã«ããªãå åå解ã«æ©ãŸãããææ³ã«æå³ã®ãªãéçµç«¯èšå·ãçæããã®ã§ããïŒ
ææ³ã«æ»ã
OPïŒ '{' OPS '}' //ãããã¯
| EXPR ';' //åŒ
| 'if' 'ïŒ' EXPR 'ïŒ' OP
| 'if' 'ïŒ' EXPR 'ïŒ' OP 'else' OP
| 'while' 'ïŒ' EXPR 'ïŒ' OP
| 'exit' ';' ;
次ã®
if
ãã£ã©ã¯ã¿ãŒã
OP
ã«å±éããæ¹æ³ã¯ïŒ ãã®æ¹æ³ã§éå§ã§ãã2ã€ã®ã«ãŒã«ããããŸãã ãããŠããããã®å
±ééšå
'if' '(' EXPR ')' OP
ã¯
ä»»æã®é·ãã«ããããšãã§ãããããããŒãµãŒãã©ãã ãå
ãèŠãŠããããã¯åœŒãæããŸããã
LLãåŠçã§ããªããã1ã€ã®åé¡ã¯ãå·Šååž°ã§ãã åžå ŽååŒèšç®æ©ã®ææ³ãèŠããŠãããŠãã ããïŒ
EXPRïŒNUM | EXPR OP NUM;
EXPR
äž¡æ¹ã®èŠåã¯
NUM
ããå§ãŸããŸããæåã®èŠåã¯æ瀺çã§ã2çªç®ã®èŠåã¯æé»çã§ãã ãã ããã«ãŒã«ããåŒãåºãããšãã§ããäžè¬çãªãèŠå ãã¯ãããŸããã
NUM
ã®é·ãã«å¶é
NUM
ãªããšä»®å®ããå Žåãå
ãèŠè¶ããŠãåé¡ã解決ããªãããšã¯æããã§ãã
ææ³ãä¿®æ£ããããã«ããã®
æå³ããå§ããŸããè¡ã®æåã®
NUM
ã¯æ¢è£œã®åŒã§ãããä»ã®ãã¹ãŠã®åŒã«ã¯2ã€ã®ãªãã©ã³ããå«ãŸããŸãã
EXPRïŒNUM EXPR1;
EXPR1ïŒ| OP NUM EXPR1;
å·Šå æ°å解ãšå·Šååž°ã®æé€ã«ãããææ§ãã®ãªãææ³ãLLæ§æ解æã«é©åãããããšãã§ããŸãããå€ãã®è£å©çãªéçµç«¯èšå·ãè¿œå ããŠãããŸã£ããæå³ããããŸããã
ããšãã°ã
EXPR: EXPR OP NUM ;
ã«ãŒã«ã®ç³ã¿èŸŒã¿ã§ã¯ã次ã®ããã«ãªã
EXPR: EXPR OP NUM ;
æ§æããªãŒããŒããç°¡åã«äœæããŸãããå·Šã®åŒæ°-ããã«ãããŸãïŒ
$1
ã æ£ããåŒæ°ã¯ããã«ããã
$3
ã§ãã
EXPR1: OP NUM EXPR1 ;
ã®å±éã§ã§ããããš
EXPR1: OP NUM EXPR1 ;
ïŒ å·Šã®åŒæ°ã¯
æ¢ã«å±éãããŠãããã¹ã¿ãã¯ããæ¶å»ãããŠããŸã ã ãããã
EXPR1
ãæã«ããŠããŸããæ£ããåŒæ°ã®åŸã®éšååŒã§ãã äœãè¯ããã®ã®ããã§ãïŒ
éèŠãªããšã¯ãå·Šååž°ã¯ãã¹ãŠã®å·Šçµåæäœãããã³ãã®ã»ãšãã©ã«ãšã£ãŠ
èªç¶ãªããšã§ãã ãããã£ãŠãäžèšã®ãããªæ··ä¹±ã¯çãã奜å¥å¿ã§ã¯ãªããå
žåçãªã±ãŒã¹ã§ãã
äžæ¹ã§ã¯ãææ³ãLL圢åŒã«éå
ããããšã¯å®å
šã«åœ¢åŒçã§ãããéã®ãªãéçã«å§ããããšãã§ããŸãã äžæ¹ãç¹å®ã®ææ³ã§ã¯ãªããç¬èªã®ææ³ã«åŸã£ãŠåäœãããªãŒãããã³ããããã°ããæ¹æ³ã¯ïŒ
ç¹ã«ããããã€ã¡ã³ãã®ã¢ã¯ã·ã§ã³ãèšè¿°ããããšã¯èš±å¯ãããŸããããã¹ãŠåãããã«ããããã€ã¡ã³ãã¯èšå®ããã«ãŒã«ã§ã¯ãªããéçãèšå®ããä»ã®ã«ãŒã«ã«ãªãããã§ãã ãã®ãããªããŒãµãŒãç¹å®ã®è§£æããªãŒãçæã§ãããšäŸ¿å©ã§ãã ãããè¡ãã«ã¯ãç¹å®ã®ææ³ã®ã«ãŒã«ããªãŒãããã³ãå®éã«æ©èœããã«ãŒã«ãšçžé¢ãããããªãŒãåæ§ç¯ããŠãããã«ãŒã«ããå¥ã®ã«ãŒã«ã«ç§»åããããŒãããå
ã«æ»ããå¿
èŠããããŸãã
ããªããŒ
LLã®å©ç¹ã«é¢ããè°è«ã LRã¯äžè¬ã«èªå解æãšåããããå€ãã§ãã ã©ã¡ãã®ã¢ãããŒãã«ãç¬èªã®æ¯æè
ãããŸãã äŸãã°ãç§ããå人çã«æ·±ãå°æ¬ãããŠãããã¯ã©ãŠã¹ã»ã¯ãŒã¹ã¯ãLLåæã®ç©æ¥µçãªè¬çœªè
ã§ãããPascalã®éçºã«ãããèšèšç®æšã®1ã€ã¯LLïŒ1ïŒåæã®å¯èœæ§ã§ããã ããã¹ãã®æ¬¡ã®æåã1ã€ã ãèŠããªãŒãããã³ã LLã®ãçããŠããèšèªãã®ã»ãšãã©ã¯é©åããŸãããããšãã°ãCã§ã¯ãå€æ°ãŸãã¯é¢æ°ã®å®£èšã¯
int
ã§éå§ã§ããè¡ãæåŸãŸã§èªããŸã§åºå¥ã§ããŸããã
å©äŸ¿æ§ã«é¢ããŠïŒåºæ¬çã«ã誰ãã圌ãæ
£ããŠãã楜åšãè³è³ããçããããšãå«ããŸãã
ããšãã°ãã
ANTLR vs. ãã€ãœã³ "ïŒ
å人çãªå¥œã¿ã®é¢ã§ã¯ãLALRææ³ã¯æ§ç¯ãšãããã°ãã¯ããã«ç°¡åã ãšæããŸãã æ¬ ç¹ã¯ãshift-reduceãïŒæãããïŒreduce-reduceã®ãããªããäžå¯è§£ãªãšã©ãŒã«å¯ŸåŠããå¿
èŠãããããšã§ãã ãããã¯ããŒãœã³ãçæãããšãã«Bisonããã£ãããããšã©ãŒã§ããããããšã³ããŠãŒã¶ãŒãšã¯ã¹ããªãšã³ã¹ã«ã¯åœ±é¿ããŸããããéçºããã»ã¹ãå°ãé¢çœãããããšãã§ããŸãã
ãã®çŽäºã«ãããANTLRã®å©ç¹ã«ã¯ã解æèªäœã®å質以å€ã®ãããããã®ãå«ãŸããŸãã䟿å©ãªéçºç°å¢ãç°ãªãèšèªã§ã®ã³ãŒãçæããŠãŒã¶ãŒãã¬ã³ããªãŒãªçæã³ãŒãã§ãã
ANTLRãšããŒãã«ããŒãµãŒã®æ倧ã®éãã¯ã䟿å©ã«çæãããã³ãŒãã§ãã å®éãç¹æ®ãªè§£æã¹ã¿ãã¯ã®ä»£ããã«ãåŒã³åºãã¹ã¿ãã¯ã䜿çšãããåææ³èŠåã®èªèãé¢æ°åŒã³åºãïŒååž°èŠåã®å Žåãååž°é¢æ°ã®å ŽåïŒãšããŠå®è£
ãããŸãã ãããã£ãŠãåŒã³åºãã¹ã¿ãã¯ãããããã°ããå ŽåãããŒãµãŒãçŸåšã®ç¶æ
ã«ãªã£ãæ¹æ³ãããã«ããããŸãã äžæ¹ããã€ãœã³ã§ã¯ãæãåºãããã«ãç¶æ
éã®é·ç§»ã®ãããã°å°å·ããªã³ã«ããé·ç§»ã®çç±ãç解ããããã«ãã·ã³ã®å°å·ã確èªããå¿
èŠããããŸãã
ããŒãã«ã®åã®ååž°çå®è£
ã®æ¬ ç¹ãæããã§ããã³ãŒãã®éãã¯ããã«å€ããããã¡ã¢ãªãæ¶è²»ãããŸãã çæãããã³ãŒãã«ããããããæžãããšã¯äžå¯èœã§ããããã¯ãææ³ãå€æŽããããšå€æŽãããããã«æ°åã®é¢æ°ãä¹ç®ãããããã§ãã
ããã¯ãã©ããã³ã°
ã¹ã€ãŒãããšã«ã«ãŒã«ãäºåéžæããLLããŒãµãŒã¯ãããŠã³ã¹ããªãŒã 解æã®å¯äžã®ãªãã·ã§ã³ã§ã¯ãããŸããã å¥ã®ã¢ã€ãã¢ïŒããã€ãã®é©åãªã«ãŒã«ãããå Žåã
ãã¹ãŠãè©ŠããŠã¿
ãŸãã ãããã€ãã¯ããŸãã ããšãã°ã
fork()
ãªã©ã®æäœãå®è¡ã§ããŸããçŸåšã®ç¶æ
ã§ããŒãµãŒã¯ããŒã³ãäœæããåã¯ããŒã³ã«ã¹ãã£ã³ãªãã·ã§ã³ã®1ã€ãè©Šè¡ãããŸãã ã¯ããŒã³ãæ§æãšã©ãŒã«ééãããšãã¯ããŒã³ã¯æ»ã«ãŸãã ãã¹ãŠã®ã¯ããŒã³ãåæ¢ããŠããå Žåãé©åãªã¹ãã£ã³ãªãã·ã§ã³ã¯1ã€ã§ã¯ãããŸãããå
¥åããã¹ãã«æ§æãšã©ãŒããããŸãã
æ£ããããã¹ãã®å Žåããã®ã¢ãããŒãã¯å€ããå°ãªããåãå
¥ããããŸãã ãããããšã©ãŒæ€åºã«ã¯åé¡ããããŸãã ãŸããæ€åºããããšã©ãŒã®ã©ããå°å·ããŸããïŒ ãããã®ã»ãšãã©ã¯ã誀ã£ãŠéžæãããã¹ãã£ã³ã®çµæã§ãããããã°ã©ã ããã¹ãã®ãšã©ãŒã§ã¯ãããŸããã ããããããŒãµãŒã®èŠ³ç¹ããã¯ããã¹ãŠãå®å
šã«åçã§ãã
第äºã«ãåæãçµããããšã¯ãããŸãããå·Šååž°èŠåã«åŸã£ãŠã¹ã€ãŒããè¡ããã³ã«ãã¯ããŒã³ã®1ã€ã¯ã¹ã€ãŒãåãšãŸã£ããåãç¶æ
ã«ãªããŸãã ãã®ãããåã¹ãããã§ããã«1ã€ã®ãŸã£ããåãã¯ããŒã³ãå€æããç¡éã«ç¶ããŸãã ã¯ããŒã³ã®1ã€ãåæã®çµããã«éãããšãæ®ãã®ãã¹ãŠã殺ãããšãã§ããŸãã ãããŠãå察ã«ãä»ã®ãã¹ãŠã®ã¯ããŒã³ãæ§æãšã©ãŒã«ééããŠæ»ã«ãç¡é§ãªã¯ããŒã³ã ããçãç¶ããã®ãïŒ
æåŸã«ããããŸããªææ³ãã©ããããïŒ LLããã³LRããŒãµãŒã¯ãã³ã³ãã€ã«æã«ç«¶åãæ€åºããŸãã ããã§ã¯ãã³ã³ãã€ã«ãªã©ã¯ãããŸããïŒããŒãµãŒã¯ãã»ãšãã©çã®ææ³ãã€ãŸã å€åºå
ã§
解éããŸãã
ãã®ãããåãããã¹ãã«å¯ŸããŠ1ã€ã®åæãŸãã¯å¥ã®åæã®ãããããåŸãããããšãå€æããå ŽåããããŸããã©ã®ã¯ããŒã³ãåæãããæ©ãçµäºããæéããããã«ãã£ãŠç°ãªããŸãã
æåŸã®åé¡ã¯æãç¬åµçãªæ¹æ³ã§è§£æ±ºãããŸããïŒãããŸããªæ§æ解æã®å¯èœæ§ã¯ææ³ã®åºæ¬çãªåé¡ã§ããããããã®ä»£ããã«
æ§æ解æåŒã䜿çšããå¿
èŠãããããšãçºè¡šãããŸãããæ¬è³ªçã«ã¯éçºã«ãŒã«éã§å³å¯ãªåªå
é äœãäžãããããšããç¹ã§ã®ã¿ç°ãªããŸãã ããšãã°ãææ³
OP: EXPR ';' | 'if' '(' EXPR ')' OP | 'if' '(' EXPR ')' OP 'else' OP ;
ãããŠ
OP: EXPR ';' | 'if' '(' EXPR ')' OP 'else' OP | 'if' '(' EXPR ')' OP ;
-ããã¯ãŸã£ããåãææ§ãªææ³ã§ãããæ§æ解æåŒ
OP: EXPR ';' / 'if' '(' EXPR ')' OP 'else' OP / 'if' '(' EXPR ')' OP
ããŒãµãŒã«ãæåã«
if..else
ãèªèããããšãã倱æããå Žåã®ã¿if
if..else
ãèªèã
if..else
ããšæ確ã«äŒã
else
ã ãããŠãè¡šçŸ
OP: EXPR ';' / 'if' '(' EXPR ')' OP / 'if' '(' EXPR ')' OP 'else' OP
ã¯ãã-
else
if
if
else
ããæåã«èªèããããšãæå³ããããã
else
ã¯ãŸã£ããèªèãã
else
ã
ããã§ãå¯èœãªãã¹ãŠã®ã¹ã€ãŒããåæã«ãã§ãã¯ãã代ããã«ãåªå
床ã«åŸã£ãŠé çªã«ãã§ãã¯ããŸãã åã®ã¹ãã£ã³ã§ãšã©ãŒãçºçããå Žåã«ã®ã¿ã次ã®ã¹ãã£ã³ã«é²ã¿ãŸãã ã³ã¡ã³ããŒã¿ãŒãèšåãããªã³ã¯ã¯
ããã®è§£ææ¹æ³ã®
åªããæ¯metaãæäŸããŸãã
æ zyãªè±¡ã«ä¹ã£ãããšããããŸããïŒ åœŒã¯ãã£ããæ©ããæ¿ããæºããŸãã ãããŠã圌ã¯éè·¯ãæ©ããŠããŸããããããããæ¹åã«ããŸãããé¢çœããšæããŸãããããããããæãŸãããã®ãšäžèŽããªããã°ã象ã®é転æã¯ããããç§ãã¡ã¯ããã«ããŸããããšèšããŸãã ã ããããã¹ãŠã®éžæè¢ãè©ŠããåŸããŸãŠã¯ãããã§ã¯ãªã ããšèšããªãã£ãæç¹ã§èªåèªèº«ãèŠã€ããŸãã ãããã£ãŠãããŒãµãŒã³ã³ãããŒã¿ãŒã¯ããªãã·ã§ã³ã®ãããããæ©èœãããŸã§ããªãã·ã§ã³ã®ãã¹ãŠã®çµã¿åãããè©Šè¡ããŸãã ãããŠãåããŒã«ããã¯ã®åŸã圌ãã¯åã³åãä»äºããå§ããŸãã <...>æ°è¡ã®ããã°ã©ã ã¯ããã«ç解ãããŸããã ãã§ã«æ°ç§ã§3è¡ã«ãªããŸãã 5è¡ãåŸ
ããªãã£ãã èŠããŠãããŠãã ããããã®ãããªããŒãµãŒã³ã³ãããŒã¿ãŒã¯ãéåžžã«åçŽãªææ³ã«ã®ã¿é©ããŠããŸãã
æ§æ解æã«ãŒããæ€åºãã蚱容å¯èœãªäœæ¥æéãéæãããšã©ãŒãç¹å®ããããšã¯æ®ã£ãŠããŸãã
ã«ãŒãã®æ¹ãç°¡åã§ããå
¥åããã¹ããé²ããããšãªããåãç¶æ
ã«2åããå Žåã3åç®ã«ããããŠå¥œããªã ãåãç¶æ
ã«ãªããŸãã å
¥åããã¹ãã®åäœçœ®ã«ã€ããŠããã§ã«ãã®äœçœ®ã«è¡ã£ããã¹ãŠã®ç¶æ
ã®ãªã¹ããä¿æããå¿
èŠãããããšãããããŸããåãç¶æ
ã«2床ç®ã«ãªã£ãå Žåããããããããã§ååã§ããããè¡ããŸããããšèšããŸãã
ç¡æã®ããŒãã¹ãšããŠããããããããŸããããšããç®çãã ãã§ãªãã以åã®åæã®çµæïŒã¹ãã£ã³ãçºçãã/é©åããªãã£ãïŒãèŠããŠããå Žåããç·åœ¢ãã®åäœæéãåŸãããŸãã ææªã®ã·ããªãªã¯ãããã¹ãã®åäœçœ®ã«ãããã¹ãŠã®å¯èœãªç¶æ
ã蚪åããå Žåã§ãã ããã¹ãã®é·ãã
Næåã§ã
ææ³ã§
Mã«ãŒã«ã®æ§æ解æåŒïŒåéçµç«¯èšå·ã®ä»£æ¿éçºãªãã·ã§ã³ãå«ãïŒã®å Žåãæäœæé
O ïŒ
M *
N ïŒãåŸãããŸãã ããè³¢ãç®ã现ããŠã
Mãå®æ°ã§ãããµããããå Žåãããã§ããæéã¯ç·åœ¢ã§ãã æ¯èŒã®ããã«ãåç¶æ
ã§äºåå®çŸ©ãããã¢ã¯ã·ã§ã³ãæã€åŸæ¥ã®LLããŒãµãŒãšLRããŒãµãŒã¯ãææªã®å Žå
O ïŒ
M *
N ïŒã§ãŸã£ããåãã§ãã
SïŒ| T1 S;
T1ïŒT2;
T2ïŒT3;
...
TMïŒ 't';
ããã§ã
't'
åã·ããã®åŸ
't'
LRã¯
't' -> TM -> ... -> T3 -> T2 -> T1
Mç³ã¿èŸŒã¿ãå®è¡ããŸãã LLã¯ãå
't'
ãé£ã¹ããåã«ã
Mã¹ã€ãŒã
T1 -> T2 -> T3 -> ... -> TM -> 't'
ãŸãã
å
šäœã®åé¡ã¯ãå¹³åçãªã±ãŒã¹ãææªã®ã±ãŒã¹ãšã©ã®ããã«ç°ãªããã§ããå°ãªããšããç·åœ¢è±¡ãã¯ãåãææ³ã§LLãããå€ãã®è§£æã§ã¹ã€ãŒããå®è¡ããŸãã
ã¡ã¢ãªæ¶è²»ã®ãã1ã€ã®åé¡ã éå»ã®ã¹ãã£ã³
ã®çµæã®
M *
Nãä¿åããå¿
èŠããããŸããããã«å ããŠãå
¥åããã¹ããã¡ã¢ãªã«å®å
šã«ä¿åããå¿
èŠããããšããäºå®ã«å ããŠã象ã¯ç¡éã«ååŸã«å®è¡ããå¿
èŠãããããã§ãã ããã¯ãã¹ãã¢ã§èªååãããããŒãµãŒããã§ã«èªã¿åãããããã¹ãã«æ»ããªããããã¡ã¢ãªèŠä»¶ã¯ããã¹ãã®ã¿ã§ã¯ãªãææ³ã®ã¿ã«äŸåãããšããäºå®ã«ããããããã§ãã
誰ããã1ãã€ãã®æŽå²ããèªã¿ãŸãããïŒ ããã«ãæ°ããã³ã³ãã€ã©ã®æãèªç¶ãªã¢ããªã±ãŒã·ã§ã³ã®1ã€ã¯ãä¿åãããã¡ã¢ãªãéèŠãªãã¹ãŠã®ã³ã³ãã¯ããªãã©ãããã©ãŒã ããµããŒãããããšã§ãã
ãããŠãæ§æãšã©ãŒã®æ€åºã«é¢ããŠã å®éã«packratïŒskopidïŒãšããååãååŸããç§ãã¡ã®è±¡ã¯ã1åã®ã¹ãã£ã³ãè¡ãããªãã£ããšãã«ããã¹ãã«ééãããããšçµè«ä»ããŸããã ãããã£ãŠããšã©ãŒãæ€åºãããäœçœ®ã®åã«ããšã©ãŒèªäœã®å Žæãã¯ããã«å
è¡ããå ŽåããããŸããæ§æ解æåŒãæ³å®ããŸã
DECLïŒDECLVAR / DECLFN;
DECLVARïŒã¿ã€ãID ';' ;
DECLFNïŒã¿ã€ãID 'ïŒ' ARGS 'ïŒ';
-Cã®å®£èšã®æ§æã«ãªã¢ãŒãã«äŒŒãŠããŸãã
å
¥åããã¹ãã«
TYPE ID '!'
ãšããŠè§£æã§ããã·ãŒã±ã³ã¹ãå«ãŸããŠããå Žå ããã®åŸãæ§æãšã©ãŒã¯ã©ã®äœçœ®ã«ãããŸããïŒ Packratã¯æåã®ã¹ãã£ã³ããã§ãã¯ããŸãããæ©èœããŸãããããŒãµãŒã¯
TYPE
ã®å
é ã«ããŒã«ããã¯ãã2åç®ã®ã¹ãã£ã³ãè©Šã¿ãŸãã 圌女ãåããªãã
TYPE
åã«ãšã©ãŒãæ€åºãããããšã
TYPE
ãŸãã
TYPE
ãããŒãã©ã€ã³ã®ããŒãã³ã¢è¡šçŸã§ããå Žåã¯ã©ããªããŸããïŒ
å°ãªããšã1åã®ã¹ãã£ã³ã§å°éã§ããäžçªå³ã®ãã®ããšã©ãŒäœçœ®ãšããŠè¡šç€ºããããšã¯è«ççã§ãã ããŒãµãŒãããã¹ããæ£åžžã«è§£æãããããšããŸã æåŸ
ããŠããæåŸã®äœçœ®ã
ãšã©ãŒã®ããŒã«ãªãŒãŒã·ã§ã³ããã®ããã«å®è£
ãããŠããpackratå®è£
ããããšæããŸãã
ããã ãã§ããããã¯ã·ãªãŒãºã®æåŸã®æçš¿ã§ã解æãæ±ã£ãŠããŸãã
次åã¯ãã»ãã³ãã£ã¯ã¹ã«ç§»ããŸããããããããã°ãããã¡ãã®èšèªã¯æ¬åœã«
ããã°ã©ãã³ã°èšèªã«ãªããŸãã