ã¯ããã« è¿å¹´ãçµã¿è¾¼ã¿ç°å¢ã§ãã¹ã¯ãªããè¨èªã¸ã®é¢å¿ãé«ã¾ã£ã¦ãã¾ããããããã£ãè¨èªå¦çç³»ãæ¸ãéã«å¿ è¦ã¨ãªã£ã¦ããã®ãåå¥è§£æãæ§æ解æã§ã ããã§ã¯ç°¡åãªå帰ä¸éåã®ãã¼ãµãä¾ã«ãå®éã«å®è£ ãã¦ã¿ãªããæ§æ解æã«ã¤ãã¦å¦ãã§ããã¾ããã å帰ä¸éåã®æ§æ解æå¨ã¯åç´ã«å®è£ ããã¨ã¹ã¿ãã¯ã®æ¶è²»ãæ¿ãããã¨ãã¹ã¿ãã¯é åã®æ¯æ¸ã®äºæ¸¬ãé£ãããã¨ãªã©ã§ãã¾ãå®ç¨çãªãã®ã«ã¯ãªããªãã®ã§ãããæ§é ãç°¡åãªã®ã§æ§æ解æã®ä»çµã¿ãç解ããã®ã«ã¯åãã¦ãã¾ã ï¼ãå帰éä¸ãã§ããå帰ä¸éãã§ãã©ã£ã¡ã§ãããã§ãããrecursive descentãã®è¨³ããªï¼ BNF å¼ã®æ§é ã®å®ç¾©ã¨ãã¦ï¼¢ï¼®ï¼¦çãªè¡¨è¨ãç¨ãã¦ãã¾ãããå¥ã«ï¼¢ï¼®ï¼¦ãç¥ããªãã¦ãåé¡ããã¾ãã 空æååï¼Îµï¼ã¯çç¥ãã¦ããã¾ã ä¸é¨ã«ã¯æ£è¦è¡¨ç¾çãªè¡¨è¨ãç¨ãã¦ãã¾ã * 㯠0å以ä¸ã®ç¹°ãè¿ãã+ 㯠1å以ä¸ã®ç¹°ãè¿ãã表ãã¦ã
ããã¾ã§ã¯è² ã®æ°ãæå®ããæ¹æ³ãããã¾ããã§ãã åé æ¼ç®åããµãã¼ããããã¨ã§è² ã®æ°ã使ããããã«ãã¦ã¿ã¾ããã ä»çµã¿ åé æ¼ç®åã使ããããã«ãããã¼ãµãå¦çãã¹ãå¼ã¯å¿ ã次ã®ãããªå½¢å¼ã«ãªã£ã¦ãã¾ã å®çµå¼ ::= é¨åå¼_comma é¨åå¼_comma ::= é¨åå¼_add_sub é¨åå¼_comma_ é¨åå¼_comma_ ::= æ¼ç®å_comma é¨åå¼_add_sub é¨åå¼_comma_ æ¼ç®å_comma ::= ï¼ é¨åå¼_add_sub ::= é¨åå¼_mul_div_mod é¨åå¼_add_sub_ é¨åå¼_add_sub_ ::= æ¼ç®å_add_sub é¨åå¼_mul_div_mod é¨åå¼_add_sub æ¼ç®å_add_sub ::= ï¼ ããã㯠â é¨åå¼_mul_div_mod ::= é¨åå¼_unary é¨åå¼_mul_div_mod_ é¨åå¼
å®ã¯ã«ã³ãï¼ï¼ï¼ãæ¼ç®åã§ã ãã®ã«ã³ãæ¼ç®åã使ããããã«ãã¦ã¿ã¾ããã ä»çµã¿ ã«ã³ãæ¼ç®åã使ããããã«ãããã¼ãµãå¦çãã¹ãå¼ã¯å¿ ã次ã®ãããªå½¢å¼ã«ãªã£ã¦ãã¾ã å®çµå¼ ::= é¨åå¼_comma é¨åå¼_comma ::= é¨åå¼_add_sub é¨åå¼_comma_ é¨åå¼_comma_ ::= æ¼ç®å_comma é¨åå¼_add_sub é¨åå¼_comma_ æ¼ç®å_comma ::= ï¼ é¨åå¼_add_sub ::= é¨åå¼_mul_div_mod é¨åå¼_add_sub_ é¨åå¼_add_sub_ ::= æ¼ç®å_add_sub é¨åå¼_mul_div_mod é¨åå¼_add_sub æ¼ç®å_add_sub ::= ï¼ ããã㯠â é¨åå¼_mul_div_mod ::= å®æ°å¼ é¨åå¼_mul_div_mod_ é¨åå¼_mul_div_mod_ ::= æ¼ç®å_mul
ã¾ãã¯åç´ã«æ°å¤ã®è¶³ãç®ãå¼ãç®ãã§ããããã«ãã¦ã¿ã¾ããã ä»çµã¿ ãã¼ãµãå¦çãã¹ãå¼ã¯ãã¶ã次ã®ãããªå½¢å¼ã«ãªã£ã¦ããã§ããã å®çµå¼ ::= é¨åå¼ é¨åå¼ ::= æ°å¤ æ¼ç®å é¨åå¼ æ¼ç®å ::= ï¼ ããã㯠â æ°å¤ã ::= 16é²æ° ããã㯠8é²æ° ããã㯠10é²æ° 16é²æ° ::= 0x[0-9a-fA-F]+ 8é²æ° ::= 0[0-7]* 10é²æ° ::= [1-9][0-9]*ãé¨åå¼ãã®ã¨ããã«æ³¨ç®ãã¦ãã ãã ãé¨åå¼ãã®å®ç¾©ã«ãé¨åå¼ãèªèº«ãå«ã¾ãã¦ãã¾ãã ã¤ã¾ãå®ç¾©ãå帰çã«ãªã£ã¦ããããã§ã ããã¦ãã®å®ç¾©ãä¸ããä¸ã¸ã¨é çªã«éããªãã解æããã®ã§ããã®ææ³ããå帰ä¸éåãã¨å¼ãã§ãã¾ã ãã®ããã«å®ç¾©ãåºã¾ãã°å¾ã¯ç¹ã«ä½ãèããã«ããããã®ã¾ã¾ C++ ã®ã³ã¼ãã¨ãã¦å®è£ ããã°ããã ãã§ã ã¾ããã¼ãµã«æå®ãããã®ã¯ãå®çµå¼ãã®æååã§ããã
æ¼ç®åã®åªå é ä½ã¨ãããã®ãç解ããã¨ããã§ãä»åº¦ã¯æ¬å¼§ã使ããããã«ãã¦ã¿ã¾ããã ä»çµã¿ æ¬å¼§ã使ããããã«ãããã¼ãµãå¦çãã¹ãå¼ã¯å¿ ã次ã®ãããªå½¢å¼ã«ãªã£ã¦ãã¾ã å®çµå¼ ::= é¨åå¼_add_sub é¨åå¼_add_sub ::= é¨åå¼_mul_div_mod é¨åå¼_add_sub_ é¨åå¼_add_sub_ ::= æ¼ç®å_add_sub é¨åå¼_mul_div_mod é¨åå¼_add_sub_ æ¼ç®å_add_sub_ ::= ï¼ ããã㯠â é¨åå¼_mul_div_mod ::= å®æ°å¼ é¨åå¼_mul_div_mod_ é¨åå¼_mul_div_mod_ ::= æ¼ç®å_mul_div_mod å®æ°å¼ é¨åå¼_mul_div_mod_ æ¼ç®å_mul_div_mod ::= ï¼ ãããã¯ ï¼ ãããã¯ãï¼ å®æ°å¼ ::= æ°å¤ ããã㯠( é¨åå¼_add_sub
ããã¾ã§ã®å ¥åæååä¸ã«æ¹è¡ã使ããã¨ã¯ã§ãã¾ããããã³ã¡ã³ããæ¸ããã¨ã¯ã§ãã¾ããã§ãã ããã§å ¥åæååä¸ã« C/C++ 風ã®ã³ã¡ã³ãããã£ãã¨ãã¯ãã®é¨åãç¡è¦ãããã¨ãã§ããããã«ãã¦ã¿ã¾ããã ä»çµã¿ ã³ã¡ã³ãã¯å¼ã®è©ä¾¡ã«ã¯é¢ä¿ãªãã®ã§æ§æ解æå¨ã®ç«å ´ããããã¨ç©ºç½ã¨åãã§ã 空ç½ãèªã¿é£ã°ãé¢æ°ã¯ skipspace ã§ãããããããã³ã¡ã³ã対å¿ã«æ¹é ãã¦ã¿ã¾ããã ããã ãã§å ¨ä½ãã³ã¡ã³ã対å¿ã«ãªãã¾ã ç°¡åã§ãã ã§ã¯å®è£ ãã¦ã¿ã¾ããã å®è£ bool string_calc::skipspace(){ char comment = 0; while( !eof()){ char c1 = at( 0, SEEK_CUR ); char c2 = at( 1, SEEK_CUR ); char c = 0; if( comment == '/' ){ c = getch()
ããã¾ã§ã¯è§£æã¨è©ä¾¡ãä¸åº¦ã«è¡ã£ã¦ãã¾ããããæ®éã¯è§£æå¦çã¨è©ä¾¡ï¼å®è¡ã®å¦çãåããããã«ãã¾ã 解æå¦çã¯å ¥åæååãææ³ã«åã£ã¦ãããã©ããããã§ãã¯ããªããåºç¾ããæ¼ç®åãæ°å¤ãªã©ã®ææ³è¦ç´ ãè©ä¾¡ã®é çªã«ä¸¦ã¹ããªã¹ããä½ããã¨ãä»äºã«ãã¾ã ãã®ææ³è¦ç´ ãç¹ãããªã¹ãã¯èªç¶ã«ããªã¼æ§é ã¨ãªããã¨ããããããæ§ææ¨ã¨è¨ãã¾ã 解æå¦çã¯æååãå ¥åã¨ããæ§ææ¨ãåºåã¨ãã¾ã è©ä¾¡ï¼å®è¡å¦çã¯æ§ææ¨ãå ¥åã¨ãã¾ã è©ä¾¡ï¼å®è¡å¦çã®ä»äºã¯æ§ææ¨ã辿ã£ã¦çµæãå¾ããã¨ã§ã æ§ææ¨ã¯ãã®æ§é èªä½ã«ãã£ã¦ãæ¼ç®åã®åªå é ä½ãæ¼ç®åã®å³çµåæ§ã»å·¦çµåæ§ã¨ãã£ãåé¡ã¯èªæã«è§£æ±ºããã¦ããã®ã§ãåç´ã«å é ããé çªã«è¾¿ã£ã¦è¡ãã ãã§çµæãå¾ããããããªä»çµã¿ã«ãªã£ã¦ãã¾ã ä»çµã¿ æ§ææ¨ã¯ããªã¼æ§é ã§ã ããªã¼æ§é ã®åãã¼ãã¯æã¨èã«åããã¾ã èã®ãã¼ãã§ã¯ãå¤ããå¿ è¦ã§ã æã®ãã¼ãã§ã¯ãæ¼ç®åã
ããã¾ã§ã®ã¨ã©ã¼ã¡ãã»ã¼ã¸ã§ã¯èµ·ããã¨ã©ã¼ãä½ãã¨ãããã¨ã¯å¤ãã¾ãããããããã©ãã§èµ·ããã®ãã¨ãããã¨ã¯å¤ãã¾ããã§ãã ããã§ã¨ã©ã¼ã¡ãã»ã¼ã¸ã«è¡çªå·ãå ãã¦ã©ãã§çºçããã¨ã©ã¼ãªã®ããå¤ãããã«ãã¦ã¿ã¾ããã ä»çµã¿ 解æå¨ã§æ¹è¡ãæ°ãã¾ã æ¹è¡æåã¯å¿ ã空ç½ãªã®ã§ skipspace ã«æãå ãã¾ã ãã¼ãã®ã¡ã³ãã«ã¯è¡çªå·ã追å ãã¾ããã ãã¼ãã®å®è£ class node { size_t m_lineno; . . . public: size_t get_lineno() const { return m_lineno; } . . . void clear(){ m_lineno = ( size_t )-1; m_operator.clear(); m_operands.clear(); m_value.clear(); } void assign( size_t l
ããã¾ã§ã¯ä½¿ããæ°å¤ã¯æ´æ°ã ãã§å®æ°ãæå®ããæ¹æ³ãããã¾ããã§ãã å®æ°ã使ããããã«ãã¦ã¿ã¾ããã ä»çµã¿ å®æ°ã使ããããã«ãããã¼ãµãå¦çãã¹ãå¼ã¯å¿ ã次ã®ãããªå½¢å¼ã«ãªã£ã¦ãã¾ã å®çµå¼ ::= é¨åå¼_comma é¨åå¼_comma ::= é¨åå¼_add_sub é¨åå¼_comma_ é¨åå¼_comma_ ::= æ¼ç®å_comma é¨åå¼_add_sub é¨åå¼_comma_ æ¼ç®å_comma ::= ï¼ é¨åå¼_add_sub ::= é¨åå¼_mul_div_mod é¨åå¼_add_sub_ é¨åå¼_add_sub_ ::= æ¼ç®å_add_sub é¨åå¼_mul_div_mod é¨åå¼_add_sub æ¼ç®å_add_sub ::= ï¼ ããã㯠â é¨åå¼_mul_div_mod ::= é¨åå¼_unary é¨åå¼_mul_div_mod_ é¨åå¼_mul_div_
ã¯ããã« C++20 ã®åã®åºç¤ç¥èã¨ãã¦ã以å C++ ã®åå解決 ã§ãç´¹ä»ãã ADL (Argument-dependent name lookup) ã«é¢é£ãã話é¡ãå°ãç´¹ä»ãã¦ã¿ã¾ã â è足 ããã§ãååãæ¢ãããªã©ã¨è¨ã£ã¦ããã®ã¯ãã¹ã¦ã³ã³ãã¤ã«æã®è©±ã§ã ã³ã³ãã¤ã©å é¨ã®è©±ã§ã å®è¡æã«é¢æ°ãæ¢ããããªã³ã¼ããçæãããããã§ã¯ããã¾ãã ADL ã¨é¢æ°ãã³ãã¬ã¼ã æ¨æºã«æ¬¡ã®ãããªè¨è¿°ããããé常ã®é¢æ°ãã³ãã¬ã¼ãå¼ã³åºãã«ã¯ ADL ã¯é©ç¨ããããããã³ãã¬ã¼ãå¼æ°ãæ示çã«æå®ããå ´åã¯ä»ã®åè£ã®ååãè¦ãã¦ããªã㨠ADL ã¯é©ç¨ãããªãï¼å¼ã³åºããã¨ãã¦ãã Unqualified name ããã³ãã¬ã¼ãé¢æ°ã ã¨èªèãããªãï¼ãã¨è¨ã£ã¦ãã¾ã N1905 14 Templates 14.8 Function template specializations 14.
ã¯ããã« C++20 ã®åã®åºç¤ç¥èã¨ãã¦ã以å C++ ã®åå解決 ã§ãç´¹ä»ãã ADL (Argument-dependent name lookup) ã«é¢é£ãã話é¡ãå°ãç´¹ä»ãã¦ã¿ã¾ã â è足ããã§ãååãæ¢ãããªã©ã¨è¨ã£ã¦ããã®ã¯ãã¹ã¦ã³ã³ãã¤ã«æã®è©±ã§ã ã³ã³ãã¤ã©å é¨ã®è©±ã§ã å®â¦
åå 0 é¤ç®ã®å®è¡æã¨ã©ã¼ã®å¦çããã¼ãã®ã¯ã©ã¹ã«ããã¾ãã ãã¼ãã®ã¯ã©ã¹ãªã®ã«å®è¡æã®ã¨ã©ã¼å¦çã¾ã§æã£ã¦ããã®ã¯ç¾ãããªãã§ãã ããã¯ãã¼ãã®ã¯ã©ã¹ã«è©ä¾¡å¨ã®æ©è½ã¾ã§æããã¦ãã¾ã£ã¦ããã®ãåå ã§ãã æ§ææ¨ã¨è©ä¾¡å¨ã¨ã¯åãã¦ãã¾ãã¾ããã ããã¦ã¤ãã§ãªã®ã§è§£æå¨ãåãã¦ãã¾ãã¾ããã ä»çµã¿ 解æå¨ã¯ãä¸èº«èªä½ã¯ä»ã¾ã§ã® string_calc ã¯ã©ã¹ã¨åããªã®ã§ãããã¨ã©ã¼å¦çãåé¢ããããã«ã³ã¼ã«ããã¯ç¨ã®ã¤ã³ã¿ã¼ãã§ã¤ã¹ãæã¤ããã«ãã¾ã ããã¦ã¨ã©ã¼æã«ã¡ã³ãé¢æ°ãå¼ã³åºãã¦ããã¨ããããã®ã¤ã³ã¿ã¼ãã§ã¤ã¹ã®ã¡ã½ãããå¼ã³åºãããã«ç½®ãæãã¾ã è©ä¾¡å¨ã¯ãè©ä¾¡ã®ä»çµã¿èªä½ã¯åããªã®ã§ããã¼ãã«ãã£ãè©ä¾¡ã«é¢é£ããæ©è½ããã®ã¾ã¾è©ä¾¡å¨ã«ç§»ãã¦ãã¾ãã°ããã ãã§ã ãã¼ãã®å®è£ class node { std::string m_operator; std::list<
åå¥è§£æã¯ããã¹ãä¸ã®æååã®å¤æãã«ã¦ã³ããæ½åºãªã©ãã¾ãã¾ãªç®çã«ä½¿ããããã®å¿ç¨é åã¯ãã³ã³ãã¤ã©ãã³ã³ãã¼ã¿ã®ä½æãçé ã«ãèªç¶è¨èªå¦çãç°¡åãªæ´å½¢ã¾ã§å¹ åºãã ãã®ãã¡ãã³ã³ãã¤ã©ã«ãããã¬ãã·ã«ã«ã¢ãã©ã¤ã¶ã®ä½ç½®ã¥ããã以ä¸ã«èª¬æããã ããã°ã©ã ãä¸éè¨èªãããã¯æ©æ¢°èªã«å¤æããã³ã³ãã¤ã©ã¯ãä¸è¬çã«ã½ã¼ã¹ãå ¥åãæ§ææ¨ãåºåããæ§æ解æé¨(1)ã¨ããã®æ§ææ¨ãå ¥åãä¸éè¨èªã³ã¼ãã¾ãã¯æ©æ¢°èªãåºåããã³ã¼ãçæé¨(2)ãããªãã ã³ã³ãã¤ã© âæ§æ解æé¨(1) âãâåå¥è§£æå¨(1.1)ãâãã½ã¼ã¹ã âãâå¼åºãââ âãâãããâããã¼ã¯ã³åã âãâãããââ âãâæ§æ解æå¨(1.2) âãããããâ âãããæ§ææ¨ã âãããããâ âã³ã¼ãçæé¨(2)ãããâãä¸éè¨èªã³ã¼ãã¾ãã¯æ©æ¢°èªã ãã®ãã¡(1)ã®ååã¯ãã½ã¼ã¹ãå ¥åããã¼ã¯ã³ï¼èªå½ç´ ï¼åãåºåããåå¥
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}