説æ å帰ä¸éåæ§æ解æ㯠BNF ã§ä¸ããããææ³ã解æããææ³ã§ããï¼ä¸ãããã BNF ãç´æ¥æ¸ãä¸ããã¨ã§ãã¼ã·ã³ã°ãè¡ããã¨ãã§ããï¼ããã§ã¯ LL(1) ãã¼ã¶ã®ä¾ã¨ãã¦ååæ¼ç®ãã¼ã¶ãé¡æã«ï¼ä½ææ³ã示ãï¼ 1. BNF ãæ¸ã å帰ä¸éåã®ãã¼ã¶ãæ¸ãããã«ã¯ï¼ã¾ã BNF ãæ¸ããªããã°ãªããªãï¼BNF ã§ãããææ³ã¯äºåææ³(æèèªç±ææ³)ã¨ãã°ããã¯ã©ã¹ã«ãªãï¼ããã¯å®ç¨ä¸æãæç¨ãªã¯ã©ã¹ãªã®ã§ï¼å¤ãã®ç¨éã«ã¯ããã§è¶³ããï¼ ååæ¼ç®ã® BNF ã¯æ¬¡ã®ããã«ãªãï¼ã©ããèªåã§ãã¼ã¶ãæ¸ãã®ã§ BNF ã®ãã¡ãã¨ããã«ã¼ã«ã«å¾ã£ã¦ããªãã¦ãæ¸ããæ°ãããã°é©å½ãªã«ã¼ã«ã追å ãã¦ããï¼ equation := equation + factor | factor factor := factor * term | term term := (equation) | Num
boost::spiritã§ããã£ã¨ããååã®Expressionãªãã¸ã§ã¯ããä½æã§ããã ã²ã©ããã²ã©ãã£ã⦠俺ã¿ãããªãã«ããããã°ã©ãããæãåºããããªã·ãã¢ãã§ã¯ãªãã£ãã⦠å±ãããé¢æ°åããã°ã©ãã³ã°ææçãã«é¥ãã¨ããã ã£ãã ãããã©ã¤ãã©ãªãã®ãã®ã¯ãããè¯ãåºæ¥ã¦ãï¼ãã ã¨æãï¼ããä¸åº¦ä½¿ããããã«ãªãã¨ä¾¿å©ãªãã§ãã¾ã使ãã¨æããã ãã©ãã ç¨èªããããããã®ã§ãä»åã¯BNFãã³ã¼ãã«è½ã¨ãã¨ããã¾ã§ã LLæ§æ解æãè¡ãã©ã¤ãã©ãªã åååæ§boost1.42ã boost::spirit::classicï¼æ§spiritï¼ï¼ãboost::spirit::qiï¼æ§æ解æï¼ãboost::spirit::lexï¼åå¥è§£æï¼ãboost::spirit::karmaï¼ã³ã¼ãã¸ã§ãã¬ã¼ã¿ï¼ï¼ã®ã©ã¤ãã©ãªããæããããã ä»å使ã解æé¨åãè¡ãã©ã¤ã
1. ã¯ããã« ã³ã³ãã¤ã©ãæ§æããå¦çè¦ç´ ã®ãã¡ãã1. åå¥è§£æãã«ãã£ã¦ãããã°ã©ã ä¸ã®ãã¼ã¯ã³ï¼å½ä»¤èªããªãã©ã«ï¼ãåãåºããå¾ã®æ®µéã§ã¯ããã®ãã¼ã¯ã³ã®å±æ§ã¨ææ³ã«è¨è¿°ãããæ§æè¦åã«åºã¥ãã¦ãå°åºæ¨ãæ§æããå¿ è¦ãããããã®å¦çããæ§æ解æï¼parserï¼ãã¨å¼ã¶ãã³ã³ãã¤ã©å é¨ã§å°åºæ¨ã®æ§æä½æ¥ãè¡ããããªæ©è½ã¢ã¸ã¥ã¼ã«ããæ§æ解æå¨ãã¨å¼ã¶ã åå¥è§£æå¨ã®å ¥åãã¼ã¯ã³ã¯æåï¼ã¨[EOF]ï¼ã§ãããæ§æ解æå¨ã®å ¥åãã¼ã¯ã³ã¯åå¥ãã¼ã¯ã³ã§ããã æ§æè¦åã®æ±ºå®ã®ãããå®ç¾©ããããã¼ã¯ã³ãç¨ãã¦è¨è¿°ãããå調BNFï¼Backus Naur Formï¼ãããã¯æ¡å¼µBNFå½¢å¼ãç¨ãã¦ææ³ãä½æããã ææ³ã®è¡¨ç¾ã®ä»æ¹ã«ã¯ã大ããåãã¦ä»¥ä¸ã®ï¼ã¤ãããã ã»è¦åã®ä¸ããä¸ã¸åãã¦çæããæ¹æ³ï¼ä¸éåï¼LLæ³ï¼ ã»è¦åã®ä¸ããä¸ã¸åãã¦çæããæ¹æ³ï¼ä¸æåï¼LRæ³ï¼ ä¸éåã¯ãæ°å¼ãè«
ããã ï¼ è¨èªå¦ç ï¼ å½¢å¼è¨èªã®æ§æã¨æå³ å½¢å¼è¨èªã®æ§æã¨æå³ ï¼ï¼å½¢å¼è¨èªã®ææ³ ããã°ã©ã è¨èªã®ããã«ãå³æ ¼ãªææ³ã«ãã£ã¦çæãããè¨èªãå½¢å¼è¨èªã¨å¼ã¶ã å½¢å¼è¨èªã¯ãä¸è¬ã«ãåå¥è¦åã»æ§æè¦åã»æå³è¦åã§è¦å®ãããã åå¥è¦åã¯ãèå¥åãæ¼ç®è¨å·ãå®æ°ã¨ãã£ãè¦ç´ ï¼ãã¼ã¯ã³ï¼ã®è¡¨è¨æ³ãå®ãã æ§æè¦åã¯ãæãå¼ã®å½¢å¼ã示ããã®ã§ããã æå³è¦åã¯ãæ§æã®æå³ãè¦å®ãããã®ã§ããã ä¾ãã°ãç®è¡å¼ã«é¢ããææ³ãå®ç¾©ãã x = 2 + 10 * 3 ãã x = 32 ãå¾ããã¨ãèãããã ã¾ããåå¥è§£æã«ãã£ã¦ãããã°ã©ã ã¯è¦ç´ x, =, 2, +, 10, *, 3 ã«å解ãããã æ§æ解æã«ãããæ¼ç®åï¼ããã°ã©ãã³ã°è¨èªã§ã¯ã+, * ã¯ãã¨ããã= ãæ¼ç®åã¨å¼ã¶ï¼ ã®åªå é ä½ãã次ã®ãããªæ§ææ¨ãå¾ãã æå³è§£æã«ããã2 + 10 * 3 ã®æ¼ç®ãè¡ããããã®çµ
ã©ã³ãã³ã°
ã©ã³ãã³ã°
ã©ã³ãã³ã°
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}