Python ã®ææ³ã ãã Ruby ã£ã½ããã¦ã¿ããã©ããªããå®é¨ãã
ããã«ã¡ããããã³ãããã°ã©ãã¼ moriyoshi ã§ãã
Python ãçççã«å«ããªäººããããèã話ã¨ãã¦ãã¤ã³ãã³ãã§ãããã¯æ§é ã表ããã£ã¦ã®ãããã¾ããããããä¸èº«ã¯ãã®ã¾ã¾ã§ææ³ã ã Ruby ã£ã½ããããã©ããªããã§ããããããPython ã¯ãã¼ã¯ãã¤ã¶ããã¼ãµãç°¡åã«æ¸ãæããããã®ã§ã試ãã¦ã¿ã¾ãããã
ä¾ãã°æ¬¡ã®ãããªããã°ã©ã ã¯
class Boo(object): def foo(hoge): try: for i in hoge: with i: if i.fuga: while True: j = i.fuga() if not j: break print j + 2 except HogeException: pass else: pass finally: pass
ãããªé¢¨ã«ãªã£ã¦ãã¾ãããã§ããããæãã§ããã
class Boo(object) def foo(hoge) try for i in hoge with i if i.fuga while True j = i.fuga() if not j break end print j + 2 end end end end except HogeException else finally end end end
追è¨: ãããã¯gistã«ãã¾ãè²¼ããªãã£ãã®ã§ç´æ¥è²¼ããã¨æãã¾ãããããããã¾ããããªãã®ã§ pastebin.com ã«è²¼ãã¾ãã
Python ã®ææ³ã¯ BNF ã©ã¤ã¯ãªè¨æ³ã§æ¸ããã Grammar/Grammar ã¨ãããã¡ã¤ã«ã«æ¸ããã¦ãã¦ãã¾ãã¯ããã pgen ã¨ãããã¼ãµã¸ã§ãã¬ã¼ã¿ã§ C ã® LL ãã¼ãµã®ã³ã¼ãã«å¤æãããããã§ããããã®ãã¼ãµã®ã³ã¼ãã¨ããã®ã¯ Grammar ã«ãããã¼ãåããã®ã¾ã¾æ§ææ¨ã¨ãªããããªããã° CST (concrete syntax tree) ãçæãããããªãã®ã«ãªã£ã¦ã¾ãã¦ãããã人å㧠Python/ast.c 㧠AST ã«å¤æããæå¾ã« Python/compile.c ã§ãã¤ãã³ã¼ãã«å¤æãããã£ã¦ã¾ããããªæ§é ã«ãªã£ã¦ããã®ãã¡ãã¡ããã¨æ¹å¤ (æ¹æª) ãã¦ãããã§ãã¯ãã
pbtrans.py ã¨ãã Python ãããã®è¨èªã¸ã®ãã©ã³ã¹ã¬ã¼ã¿ãããã®ã§ããã£ãã移è¡ãããã¨ãã人ãã¾ã£ããå¿é ããã¾ãããããã£ãã§ããï¼
ããåç»ã§ã¯å¾åã«ã¤ã³ãã³ãããã¦ã¾ããã©ã»ãã¨ã¯å¿ è¦ãªãã§ãï¼ã»ãã¨ã§ãï¼