2024-11-01ãã1ã¶æéã®è¨äºä¸è¦§
ã¢ãã¤ãçæ§æ解æè¨èª MonParser (C# å½¢å¼ ãã¼ã¸ã§ã³ 0.2) MonParser (BNF å½¢å¼)ã®æ§æ解æ ãparãã¯ãã¼ãµã¼ã表ãã¯ã©ã¹ããsynãã¯æ§ææ¨ã表ãã¯ã©ã¹ã§ãã par str(string s) => par.StringRegExp(s); par st(string s) => par.String(s); par opr(â¦
ã¢ãã¤ãçæ§æ解æè¨èª MonParser - MonParser ã®æ§æ解æ(C# å½¢å¼) MonParser (C# å½¢å¼) ãã¼ã¸ã§ã³ 0.2 æ¼ç®åã使ãããã«ä»æ§ãå¤æ´ãã¾ããæ¼ç®åãå¤ç¨ããã¨ä½ãæ¸ãã¦ããããããã«ãããªãã¾ãããç°¡æ½ã«æ¸ããã¨ãã§ããã®ã§å ¨ä½ã®æ§æãææ¡ãâ¦
ã¢ãã¤ãçæ§æ解æè¨èª MonParser - MonParser ã®æ§æ解æ(C# å½¢å¼) MonParser (C# å½¢å¼) ãã¼ã¸ã§ã³ 0.1 æåã«å®ç¾©ãã MonParser 㯠BNF ã Python ç MonIter ã®å½¢å¼ã§æ¸ããã®ã§ãããã㯠BNF å½¢å¼ã¨ãããã¨ã«ãã¾ããMonParser (C# å½¢å¼)ã MonParsâ¦
ã¢ãã¤ãçæ§æ解æè¨èª MonParser - MonParser ã®æ§æ解æ(C# å½¢å¼) MonParser ã®æ§æã MonParser (C# å½¢å¼)ã§æ¸ãã¾ãã ãstr(æåå)ãã¯æ§ææ¨ã§ä½¿ãããªãæååã表ãã¾ããæ£è¦è¡¨ç¾ã使ããã¨ãã§ãã¾ãã ãop(æåå)ãã¯æ§ææ¨ã§ä½¿ãæååã表â¦
ã¢ãã¤ãçæ§æ解æè¨èª MonParser - MonParser ã®æ§æ解æ MonParser ã®æ§æã MonParser ã§æ¸ãã¾ãã def string = /".*"/; def operator = /'.*'/; def identifier = /[A-Za-z_][A-Za-z0-9_]*/; def constructor = /[A-Za-z_][A-Za-z0-9_]*/; def term =â¦
ã¢ãã¤ãçæ§æ解æè¨èª MonParser - æ§ææ¨ã®æ§æ æååããæ§ææ¨ãä½ããã¨ãã§ããããã«ãã¾ãããã®è¨èªã MonParser ã¨å¼ã¶ãã¨ã«ãã¾ããæåã®éå ã§çæãããèªç±ã¢ãã¤ã ã®åªéå (ããã表ãä¸è¬çãªè¨æ³ã¯ç¥ããªãã®ã§ããã§ã¯ããæ¸ãã¾ãâ¦
ç¹°ãè¿ãã®è¨æ³ã追å ãã¾ããã¾ããC# çã§ã¯æ°å¤ã®æ¼ç®ã追å ããã¦ããã®ã§ããã追å ãã¾ãã ãã£ãã使ããã¨ãã§ããã¨ãã¾ãã ãå¼ *ãã¯å¼ã®ç¹°ãè¿ã(ä¸åããªãå ´åãå«ã)ã表ãã¾ãã ãå¼ +ãã¯å¼ã®ç¹°ãè¿ã(ä¸åã¯å¿ è¦)ã表ãã¾ãã ãå¼1 &*â¦
æ§æ解æãã¢ãã¤ãã§è¡¨ãæ¹æ³ã«ã¤ãã¦èª¿ã¹ã¾ããããã«åéåãåã¨ããã¨åªçåç°(dioid)ã¨ãªãã®ã§åªçåç°ã§è¡¨ãæ¹æ³ã«ã¤ãã¦èª¿ã¹ã¾ããèªç±ã¢ãã¤ãã®ã¤ãã¬ã¼ã¿ã¼(6) - ã¨ã¬ãã¡ã³ãã»ãã¸ã¥ã¢ã©ã¤ã¶ã¼èª¿æ»è¨é²ã® Python ã® lark ã¢ã¸ã¥ã¼ã«ã®ä¾ã¯èªç±â¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(23)) C# æ§ææ¨ã®èª¿æ» ãèªç±ã¢ãã¤ãã®ã¤ãã¬ã¼ã¿ã¼(16) - ã¨ã¬ãã¡ã³ãã»ãã¸ã¥ã¢ã©ã¤ã¶ã¼èª¿æ»è¨é²ãã«æ¸ããæ§ææ¨ã調ã¹ãæ¹æ³ã«ã¤ãã¦ã¾ã¨ãã¾ãã C# æ§ææ¨ã®èª¿æ»ç¨ã®ã¯ã©ã¹ /// <summary> /</summary>â¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(22)) C# å½¢å¼ã®ã³ã¼ãããæ§æãªãã¸ã§ã¯ãã«å¤æãã¦å®è¡ ãRoslynãã®ãSyntax APIã㧠C# ã®æ§æ解æãè¡ãã¾ããã èªç±ã¢ãã¤ãã®ã¤ãã¬ã¼ã¿ã¼(14) - ã¨ã¬ãã¡ã³ãã»ãã¸ã¥ã¢ã©ã¤ã¶ã¼â¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(21)) MonIter ã³ã¼ããã C# ã³ã¼ãã«å¤æãã¦å®è¡ ãRoslyn for Scriptingã㧠C# ã®ã³ã¼ããå®è¡ãã¾ãããèªç±ã¢ãã¤ãã®ã¤ãã¬ã¼ã¿ã¼(13) - ã¨ã¬ãã¡ã³ãã»ãã¸ã¥ã¢ã©ã¤ã¶ã¼èª¿æ»è¨é²ãâ¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(20)) MonIter ã³ã¼ããã C# ã³ã¼ãã«å¤æ å¼æ°ã§æ¸¡ããã¼ã¸ã§ã³ MonIter ã®ã³ã¼ã def fib(x, y) = x & fib(y, x + y); fib(0, 1)ã C# ã®ã³ã¼ãã«å¤æããã«ã¯ä»¥ä¸ã®ããã«ãã¾ãã /// <summary></summary>â¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(19)) MonIter ã³ã¼ããã Python ã³ã¼ãã«å¤æ Python ã³ã¼ãã«ã¤ãã¦ã¯ãèªç±ã¢ãã¤ãã®ã¤ãã¬ã¼ã¿ã¼(9) - ã¨ã¬ãã¡ã³ãã»ãã¸ã¥ã¢ã©ã¤ã¶ã¼èª¿æ»è¨é²ããåç §ãã¦ãã ããã å¼æ°ã§æ¸¡ããâ¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(18)) MonIter ã³ã¼ãã®å®è¡ å¼æ°ã§æ¸¡ããã¼ã¸ã§ã³ MonIter ã®ã³ã¼ã(ã¹ãã¼ã¹ãæ¹è¡ãªã©ã¯ç¡è¦ããã¾ã) def fib(x, y) = x & fib(y, x + y); fib(0, 1)ãå®è¡ããã«ã¯ä»¥ä¸ã®ããã«ãã¾ãâ¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(17)) å¤æ°ã¨ãã®å¤ã®å¯¾å¿ãè¨æ¶ããããã®ã¯ã©ã¹ å¤æ°ã¨ãã®å¤ã®å¯¾å¿ãè¨æ¶ããç·å½¢ãªã¹ããä¿æããã¯ã©ã¹(Env<T>) Env<T> ã¯ç·å½¢ãªã¹ã(LinearList<EnvItem<T>>)ãä¿æãã¾ããEnv<T> 㯠IEnumerable<EnvItem<T>> ãå®è£ </envitem<t></t></envitem<t></t></t>â¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(16)) ååã¾ã§ã®èª¬æã§ã¯ãç·å½¢ãªã¹ãã®ã¯ã©ã¹ã¯ç¬ç«ãã¦ããªãã£ãã®ã§ãããã¯ã©ã¹ã®æ§æãå¤ãã¦ç¬ç«ããã¾ããã ç·å½¢ãªã¹ãã®ã¯ã©ã¹ å¤æ°ã¨ãã®å¤ã®å¯¾å¿ãè¨æ¶ããããã«(ä¸æ¹åã®)ç·â¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(15)) æéã¾ãã¯ç¡éã®èªç±ã¢ãã¤ãã®ã¯ã©ã¹(FreeMonoid<T>) FreeMonoid<T> 㯠IEnumerable<T> ãå®è£ ããã¯ã©ã¹ã¨ãã¾ããIEnumerable<T> ãå®è£ ãã㨠foreach ã§ä½¿ããã¨ãã§ãã¾ããIEnumerable<T> ã</t></t></t></t></t>â¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(14)) æ§æ解æã®ã¯ã©ã¹ C# ã®ãã¼ãµã³ã³ããã¼ã¿ Sprache (Sprache/README.md at develop · sprache/Sprache · GitHub)ã使ã£ã¦ãã¾ããVisual Studio ã®ã½ãªã¥ã¼ã·ã§ã³ã¨ã¯ã¹ããã¼ã©ã¼ã§â¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(13)) æ§æè¦ç´ ã«å¯¾å¿ããã¯ã©ã¹(Number ã¯ã©ã¹ï¼æ°å¤ã表ã) /// <summary> /// æ°å¤ã表ãã¯ã©ã¹ /// </summary> internal class Number : DomainExpression { /// <summary> /// æ°å¤ã表ãæ´æ° /// </summary> private readonlâ¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(12)) æ§æè¦ç´ ã«å¯¾å¿ããã¯ã©ã¹(Identifier ã¯ã©ã¹ï¼åå(é¢æ°å)ã表ã) /// <summary> /// åå(é¢æ°å)ã表ãã¯ã©ã¹ /// </summary> internal class Identifier : DomainExpression { /// <summary> /// ååã®æå</summary>â¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(11)) æ§æè¦ç´ ã«å¯¾å¿ããã¯ã©ã¹(ParameterName ã¯ã©ã¹ï¼ãã©ã¡ã¼ã¿ã¼åã表ã) /// <summary> /// ãã©ã¡ã¼ã¿ã¼åã表ãã¯ã©ã¹ /// </summary> internal class ParameterName : CodeGeneratable { /// <summary> /// å</summary>â¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(10)) æ§æè¦ç´ ã«å¯¾å¿ããã¯ã©ã¹(DomainOperation ã¯ã©ã¹ï¼æ°å¤ã®åé æ¼ç®ã»äºé æ¼ç®ã表ã) /// <summary> /// æ°å¤ã®åé æ¼ç®ã»äºé æ¼ç®ã表ãã¯ã©ã¹ï¼æ¼ç®åã¨ããã¤ãã®æ¼ç®æ°ã§æ§æããã¾ãã /</summary>â¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(9)) æ§æè¦ç´ ã«å¯¾å¿ããã¯ã©ã¹(DomainUnit ã¯ã©ã¹ï¼æ°å¤ã表ãç¡éèªç±ã¢ãã¤ãã®é ) /// <summary> /// æ°å¤ã表ãç¡éèªç±ã¢ãã¤ãã®é ï¼æ°å¤ã®å¼ã§æ§æããã¾ãã /// </summary> internal class DomainUniâ¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(8)) æ§æè¦ç´ ã«å¯¾å¿ããã¯ã©ã¹(DomainFunction ã¯ã©ã¹ï¼é¢æ°(å¼æ°ã¯æ°å¤)ã®å¼ã³åºã) /// <summary> /// é¢æ°(å¼æ°ã¯æ°å¤)ã®å¼ã³åºãã表ãã¯ã©ã¹ï¼é¢æ°åã»é¢æ°ã®å¼æ°(æ°å¤)ã®ãªã¹ãã§æ§æããã¾ã</summary>â¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(7)) æ§æè¦ç´ ã«å¯¾å¿ããã¯ã©ã¹(Function ã¯ã©ã¹ï¼é¢æ°(å¼æ°ã¯æ°å¤ã®å)ã®å¼ã³åºã) å®ç¾©æ¸ã¿ã®é¢æ° zipsumãtail ã¯ãã®ã¯ã©ã¹ã® Eval ã¡ã½ããã§å¦çãã¾ãã /// <summary> /// é¢æ°(å¼æ°ã¯æ°å¤ã®</summary>â¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(6)) æ§æè¦ç´ ã«å¯¾å¿ããã¯ã©ã¹(Expression ã¯ã©ã¹ï¼å¼(ç¡éèªç±ã¢ãã¤ã)) /// <summary> /// å¼(ç¡éèªç±ã¢ãã¤ã)ã表ãã¯ã©ã¹ï¼æ°å¤ã表ãé ã®ç¡éåã®ãªã¹ãã§æ§æããã¾ãã /// </summary> internal claâ¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(5)) æ§æè¦ç´ ã«å¯¾å¿ããã¯ã©ã¹(Definition ã¯ã©ã¹ï¼é¢æ°å®ç¾©) /// <summary> /// é¢æ°å®ç¾©ã表ãã¯ã©ã¹ï¼é¢æ°åã»ãã©ã¡ã¼ã¿ã¼ãªã¹ãã»é¢æ°æ¬ä½ã®å¼ã§æ§æããã¾ãã /// </summary> internal class Definitioâ¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(4)) ä»å¾ã¯æ§æã®èª¬æãèªåçã«ä½æã§ããããã«ãã¦ããã¨ãã¦ãä»ã¯ã³ã¡ã³ãã«èª¬æãæ¸ãã¦ããã¾ãã æ§æè¦ç´ ã«å¯¾å¿ããã¯ã©ã¹(ExpressionStatement ã¯ã©ã¹ï¼å¼ã®ã¹ãã¼ãã¡ã³ã) /// <summary></summary>â¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(3)) æ§æè¦ç´ ã«å¯¾å¿ããã¯ã©ã¹(Prog ã¯ã©ã¹ï¼ããã°ã©ã å ¨ä½) Prog ã¯ã©ã¹ã«æ§æè¦ç´ ãä½æããé¢æ°ãã¾ã¨ãã¾ããã説æã¯ã³ã¡ã³ããè¦ã¦ãã ãããæ§æã説æããè³æãèªåçã«ä½ãããâ¦
èªç±ã¢ãã¤ãããã°ã©ãã³ã°è¨èªã®ä½æ(MonIter ãã¼ã¸ã§ã³1.2 ä»æ§(2)) æ§æè¦ç´ ã«å¯¾å¿ããã¤ã³ã¿ã¼ãã§ã¼ã¹ Statement å¼ã®ã¹ãã¼ãã¡ã³ãã¾ãã¯é¢æ°ã®å®ç¾©ã表ãã¾ããã¡ã³ãã¼ã¯ä»¥ä¸ã®ãã®ãããã¾ãã Eval(env, prog): æ§ææ¨ãè©ä¾¡ãã¦ç¡éçèªç±ã¢ãâ¦