Package: chelodina
ChelodinaChelodina is a transpiler that converts LOGO:TO triangle :length
  REPEAT 3 [ FORWARD :length RIGHT 120 ]
END

TO flower :length :count
  REPEAT 150 [
    triangle :length
    RIGHT 360 / :count
  ]
END

TO web
  REPEAT 6 [ flower 150 18 ]
END

webInto Python:importturtledeftriangle(p_length):for_inrange(3):turtle.forward(p_length)turtle.right(120.0)defflower(p_length,p_count):for_inrange(150):triangle(p_length)turtle.right(360.0/p_count)defweb():for_inrange(6):flower(150.0,18.0)web()turtle.done()Installationpip install chelodinaUsageusage: chelodina [-h] --input INPUT [--run]

arguments:
  -h, --help     show this help message and exit
  --input INPUT  Logo source file
  --run          Run the transpiled codeThere's some readyexamplesto try if you clone the repository:chelodina --input examples/example1.logoYou can also trigger the program to run in a GUI:chelodina --input examples/example1.logo --runStatusImplemented:Motion functions:FORWARD,BACK,LEFT,RIGHT,SETPOS,SETX,SETY,SETHEADING,SETH,HOMEScreen functions:DONE,CLEARSCREENControl structures:REPEATFunction calls and definitions with optional parametersBinary operationsThis is still on an early stage, I focused on making someexampleswork. Functions with similar structure are trivial to implement, but I want to focus on improving the tests first.For grammar reference look atgrammar.bnf.Known quirksValidations for a valid AST (e.g. to make sure a function parameter exists before trying to use it on a statement) are not user friendly yet. I suggest double-checking your programselsewherefirst.Only tested on Python 3.6+ so far.DevelopmentUsepipenvto install dependencies:pipenv install --devRunning testsRun tests with:pipenv run testsAutomatically run tests after detecting changes with:pipenv run tests-watchDebugThe easy way is to write tests to debug your code. Feel free to useassert Falsewhere necessary.If you need to run tests along anything that sends to or needs the standard output (a debugger like pdb or pudb), you'll need to runpytestdirectly:pytest --capture=no.There's a library to pretty-print your AST in theutilspackage. Usage example:fromchelodinaimportcompilerfromchelodina.utils.debugimportparseprintlogo_code="""to myfunctionforward 51.0left 91end"""parsed_ast=compiler.get_ast(logo_code)parseprint(parsed)And you'll see the resulting AST:Module(body=[Import(names=[alias(name='turtle',asname=None),]),FunctionDef(name='myfunction',args=arguments(args=[],vararg=None,kwonlyargs=[],kw_defaults=[],kwarg=None,defaults=[]),body=[Expr(value=Call(func=Attribute(value=Name(id='turtle',ctx=Load()),attr='forward',ctx=Load()),args=[Num(n=51.0),],keywords=[])),Expr(value=Call(func=Attribute(value=Name(id='turtle',ctx=Load()),attr='left',ctx=Load()),args=[Num(n=91.0),],keywords=[])),],decorator_list=[],returns=None),Expr(value=Call(func=Attribute(value=Name(id='turtle',ctx=Load()),attr='done',ctx=Load()),args=[],keywords=[])),])Code styleI useblackfor code formatting, please install thepre-commit hookbefore doing a PR. This will be enforced with a linter check in the future.You can run the command manually too:black .Not required, but if you installEditorConfigin your editor of choice it will make your life easier.