I didn't really seriously started coding until college, but I do remember fondly some classes I had in elementary school that taught us Logo.
At the moment it can turn Logo code like this:
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 web
Into Python like this:
import turtle def triangle(p_length): for _ in range(3): turtle.forward(p_length) turtle.right(120.0) def flower(p_length, p_count): for _ in range(150): triangle(p_length) turtle.right(360.0 / p_count) def web(): for _ in range(6): flower(150.0, 18.0) web() turtle.done()
Or compile the python code directly with
chelodina --input file --run to look at the result:
You will find more details about its usage on Github.
Things I didn't enjoy:
PLY behaves more like a framework than a library, I disliked some assumptions that it makes.
t_in the lexer and
p_in the parser.
For a future project, I would probably look into a more pythonic library like Lark. It's harder to develop when the library is not being explicit, as you're always second-guessing if it was a problem with your code or you just broke another magic rule you didn't know about.
This is the current BNF grammar. I have only focused on making the examples work so it still has ways to go for a complete implementation.
program : statements statements : statements statement | statement statement : expression | funcdef | repeat expression : NAME terms | NAME terms : terms PLUS terms | terms MINUS terms | terms MULT terms | terms DIV terms | terms NUMBER | terms PARAM | NUMBER | PARAM funcdef : TO NAME terms statements END | TO NAME statements END repeat : REPEAT NUMBER LBRACKET expression RBRACKET
I plan to work on it sparingly –with UCBLogo as the target implementation– since it's been a fun project.