ðLL LR SLR LALR CLRãªã©ããããã æ§æ解æã®ã¢ãããŒã
ãŸãã¯ããã ã¢ãã(LR)ããããããŠã³ïŒLLïŒã®å·®ãç¥ãã
ããã ã¢ãã(LR)
ãããããŠã³(LL)
倧ããLRïŒããã ã¢ããïŒãšLLïŒãããããŠã³ïŒããã£ãŠãLRã®çš®é¡ããããžãå€ã
ããã ã¢ããæ§æ解æã¯ããã¯ãã©ãã¯ã«ãã£ãŠè¡ãããããšããããŸããããããããäžè¬çã«ã¯ãããã ã¢ãã ããŒã·ã³ã°ã¯ LALR ããŒãµãŒãªã©ã®ã·ãã ãªãã¯ã·ã§ã³ ããŒãµãŒã«ãã£ãŠè¡ãããŸãã
æ§ææšã«ã€ããŠãç¥ã
ã³ã³ãã¥ãŒã¿ãµã€ãšã³ã¹ã®åéã§ã¯ãããã°ã©ãã³ã°èšèªã§æžããããœãŒã¹ã³ãŒãã®æœè±¡çãªæ§ææ§é ãæšã§è¡šçŸãããã®ãæœè±¡æ§ææšïŒASTïŒãšåŒãã§ããã
LR
ã³ã³ãã¥ãŒã¿ãµã€ãšã³ã¹ã§ã¯ãLR ããŒãµãŒã¯æ±ºå®è«çæèèªç±èšèªãç·åœ¢æéã§è§£æããããã ã¢ãã ããŒãµãŒã®äžçš®ã§ãã
LR ããŒãµãŒã¯æ±ºå®è«çã§ãããæšæž¬ãããã¯ãã©ãã¯ãè¡ãããç·åœ¢æéå ã«æ£ããæ§æã 1 ã€ã ãçæããŸããããã¯ã³ã³ãã¥ãŒã¿èšèªã«ã¯çæ³çã§ãããLR ããŒãµãŒã¯äººéã®èšèªã«ã¯é©ããŠããããããæè»ãªæ¹æ³ãå¿ èŠã§ãããå¿ ç¶çã«æéããããããšã«ãªããŸãã
LR ããŒãµãŒã¯å è¡ããŒãµãŒããããããŠã³ LL æ§æ解æãããåºç¯å²ã®èšèªãšææ³ãåŠçã§ããŸãã ãã㯠LR ããŒãµãŒãèŠã€ãããã®ã«å°å¿µããåã«ãããææ³ãã¿ãŒã³ã®ã€ã³ã¹ã¿ã³ã¹ã®å šäœãèŠããŸã§åŸ ã£ãŠããããã§ã[3]ãLLããŒãµãŒã¯ããã®ãã¿ãŒã³ã®å·Šç«¯ã®å ¥åèšå·ãèŠãã ãã§ãäœãèŠããããã£ãšæ©ã決å®ãããæšæž¬ãããããå¿ èŠããããŸãã
LL
LLææ³ãç¹ã«LL(1)ææ³ã¯ããŒãµãŒã®æ§ç¯ã容æã§ãããå€ãã®ã³ã³ãã¥ãŒã¿èšèªãLL(1)ã«èšèšãããŠãããããå®çšäžéåžžã«èå³æ·±ã[8]ããŸããLLææ³ã¯ååž°çéäžããŒãµãŒã«ãã£ãŠè§£æããããšãã§ãã
LLããŒãµãŒïŒLeft-to-right, leftmost derivationïŒã¯å¶éä»ãæèèªç±èšèªçšã®ãããããŠã³ããŒãµãŒã§ããã
æ§æ解æã¯ãããŒã¯ã³åããææ³èŠåã«åŸã£ãæã®è§£æãè¡ãããã®ææ³ã§ãããã®äžã§ããLLãLRãSLRãLALRãCLRãªã©ã®ã¢ã«ãŽãªãºã ããããŸãã
LL: å·Šããå³ã«èªã¿é²ããæãå·Šã®å°åºãæ¡çšããååž°äžéããŒãµãŒãçæããææ³ã§ããå·Šååž°ã«åŒ±ããšããæ¬ ç¹ããããŸãããåçŽãªææ³ã«å¯ŸããŠé«éãªåŠçãã§ãããšããã¡ãªããããããŸãã
LR: å·Šããå³ã«èªã¿é²ããæãå³ã®å°åºãæ¡çšããã·ãã-ãªãã¥ãŒã¹ããŒãµãŒãçæããææ³ã§ããã¹ã¿ãã¯ãçšããæ§æ解æææ³ã§ã匷åãªææ³ã«ã察å¿ã§ãããšããã¡ãªããããããŸãããããŒã¹ããŒãã«ã®çæãè€éã§ãããšãããã¡ãªããããããŸãã
SLR: LRã®äžçš®ã§ãã¹ããŒãæ°ãåæžããããšã§ãããŒã¹ããŒãã«ã®ãµã€ãºãå°ããããããšãã§ããææ³ã§ããããããLRã«æ¯ã¹ãŠåŒ·åãªææ³ã«å¯Ÿå¿ã§ããªããšãããã¡ãªããããããŸãã
LALR: LRã®äžçš®ã§ãããŒã¹ããŒãã«ã®ãµã€ãºãå°ããããããšãã§ããææ³ã§ããã¹ããŒãæ°ãåæžããããšã§ãSLRã«æ¯ã¹ãŠåŒ·åãªææ³ã«å¯Ÿå¿ã§ãããšããã¡ãªããããããŸãããæ£ç¢ºæ§ãå£ãå ŽåããããŸãã
CLR: LRã®äžçš®ã§ãLRããã匷åãªææ³ã«å¯Ÿå¿ã§ããææ³ã§ããããŒã¹ããŒãã«ã®ãµã€ãºãæå°ã§ãããããæ£ç¢ºæ§ãé«ããšããã¡ãªããããããŸãããããŒã¹ããŒãã«ã®çæãéåžžã«è€éã§ãããšãããã¡ãªããããããŸãã
ææ³ãå·Šååž°ãšã¯ã©ãããäºãèšããŸããïŒ
å
·äœçãªããã°ã©ãã³ã°èšèªã«ãããå·Šååž°ææ³ã®äŸãæãããšãCèšèªããã®æŽŸçèšèªïŒäŸãã°C++ãJavaïŒãè¯ãäŸã§ãããããã®èšèªã§ã¯ãç¹ã«åŒã®è§£æã«å·Šååž°ææ³ãããçšããããŠããŸã
ææ³ãå·Šååž°ã§ãããšã¯ããã®ææ³ã®çæèŠåã®äžã«ãããéçµç«¯èšå·ãèªèº«ãå«ãå°åºèŠåãæã¡ããã®ååž°ãå·ŠåŽïŒå°åºèŠåã®å§ãã®éšåïŒã«ããç¶æ ãæããŸããããã¯æ§æ解ææã«ç¹ã«æ³šæãå¿ èŠãªç¹ã§ãç¹ã«LLããŒãµãŒã®ãããªãããããŠã³æ§æ解ææ³ã§ã¯åé¡ãåŒãèµ·ããããšããããŸãã
å·Šååž°ã¯ãç¡éã«ãŒãã«é¥ãå¯èœæ§ããããããç¹ã«ãããããŠã³æ§æ解æã§ã¯åé¡ãšãªããŸãããããããŠã³ããŒãµãŒã¯éçµç«¯èšå·ããå§ããŠå°åºãè¡ããããå·Šååž°ããããšããŒãµãŒãç¡éã«ãã®éçµç«¯èšå·ã®å°åºãç¹°ãè¿ããŠããŸãå¯èœæ§ããããŸãã
ãã®åé¡ã解決ããäžã€ã®æ¹æ³ã¯ã
å·Šååž°ã®é€å»ã§ããå·Šååž°ã®ããææ³ãæžãæããŠãåçã®éå·Šååž°çææ³ã«å€æããããšãã§ããŸããããã«ããããããããŠã³ããŒãµãŒã§ãç¡éã«ãŒãã«é¥ãããšãªããææ³ã解æããããšãå¯èœã«ãªããŸãã
å·Šååž°ã®é€å»ã®äžè¬çãªæ¹æ³ã¯ãå·Šååž°çãªèŠåãå³ååž°çãªèŠåã«æžãæããããšã§ãã
LL LR SLR LALR CLRãªã©ãã³ã³ãã€ã«ææ³ãæäœã§ããããŒã«ã©ã€ãã©ãªã¯ãããŸããïŒ
ã³ã³ãã€ã©æ§ç¯ã§äœ¿çšãããLLãLRãSLRãLALRãCLRãªã©ã®ããŒãµçæã¢ã«ãŽãªãºã ãæäœã§ããããŒã«ãã©ã€ãã©ãªã¯ããã€ããããŸãããããã¯ãèšèªã®ææ³ãå®çŸ©ãããã®ææ³ã«åºã¥ããŠãœãŒã¹ã³ãŒãã解æããããŒãµãèªåçæããããã«äœ¿çšãããŸãã以äžã¯ãã®ãããªããŒã«ãã©ã€ãã©ãªã®äŸã§ãïŒ
ANTLR (ANother Tool for Language Recognition): LL(*)ããŒãµãçæããããã®åŒ·åãªããŒã«ã§ããè€æ°ã®èšèªãžã®åºåããµããŒãããŠãããæ§ã ãªããã°ã©ãã³ã°èšèªã§äœ¿çšããããšãã§ããŸãã
Bison: GNUãããžã§ã¯ãã®äžéšãšããŠéçºãããBisonã¯ãLALRããŒãµãçæããããã®ããŒã«ã§ããYaccã®äºææ§ãæã€ãããå€ãã®UNIXã·ã¹ãã ã§åºã䜿çšãããŠããŸãã
Yacc (Yet Another Compiler Compiler): äŒçµ±çãªLRããŒãµãžã§ãã¬ãŒã¿ã§ãããå€ãã®UNIXã·ã¹ãã ã«æšæºã§å«ãŸããŠããŸããBisonã¯Yaccã®ä»£æ¿åãšããŠéçºãããŸããã
Flex: ã¬ãã·ã«ã«ã¢ãã©ã€ã¶ãžã§ãã¬ãŒã¿ã§ãBisonãYaccãšçµã¿åãããŠäœ¿çšãããããšãå€ãã§ããFlexèªäœã¯ããŒãµãçæãããã®ã§ã¯ãããŸããããããŒãµãšé£æºããŠäœ¿çšãããŸãã
Gold Parsing System: LRãLALRãããã³LLããŒã·ã³ã°ã¢ã«ãŽãªãºã ããµããŒãããããŒãµãžã§ãã¬ãŒã¿ã§ããæè»ãªææ³å®çŸ©ãšè€æ°ã®ããã°ã©ãã³ã°èšèªãžã®åºåããµããŒãããŠããŸãã
Menhir: OCamlã§æžãããLR(1)ããŒãµãžã§ãã¬ãŒã¿ã§ãOCamlããã°ã©ããŒã«ãšã£ãŠã®éžæè¢ã§ãã