Logo3D is a modernized version of the programing language LOGO designed in 1967 by Wally Feurzeig, Seymour Papert, and Cynthia Solomon.
This is part of a project for the Programing Languages class at the Barcelona School of Informatics (FIB UPC) - Q2 2020-21
this language is programmed in python and ANTLR and is composed of various source files:
-
logo3d.py is the language's interpreter
-
logo3d.g is the language's grammar, defined in ANTLR
-
visitior.py is the language's AST visitor, which navigates the Abstract Syntax Tree
-
turtle3d.py contains the Turtle3D class, which implements LOGO's turtle
To use Logo3D you must first download the previously mentioned files and install the libraries from requirements.txt using the command:
python -m pip install -r requirements.txt
generate the parser and lexer files using:
antlr4 -Dlanguage=Python3 -no-listener logo3d.g
and finally generate the visitor parent class file using:
antlr4 -Dlanguage=Python3 -no-listener -visitor logo3d.g
Now you can run your own Logo3D programs following the usage below!
The Turtle3D class implements a 3D version of the original logo's turtle. This class creates a scene using vpython and draws a red "turtle" (a sphere), that leaves a trail behind by default when moved.
The turtle has methods:
left(deg)
,right(deg)
,up(deg)
anddown(deg)
to change horizontal and vertical direction by deg degrees.forward(dist)
andbackward(dist)
to move in said direction dist distance.show()
andhide()
to start or stop leaving a trail respectively.color(r, g, b)
to define the turtle's trail color by its RGB values.home()
to move the turtle back to its origin.
The Logo3D language is defined by the grammar in logo3d.g, the lexer (logo3dLexer.py) and parser (logo3dParser.py) generated by ANTLR-python and the visitor in visitior.py (wich inherits from logo3dVisitor.py, also generated by ANTLR-python).
It implements some very basic programming features, just like the original logo:
-
variable assignment with
:=
perimetre := 2 * 3.1416 * radi
-
reading from stdin to a variable with
>>
>> radi
-
writing to stdout from a variable or expression with
<<
<< radi << 5 * 3 - 2
-
conditionals with
IF _ THEN _ END
orIF _ THEN _ ELSE _ END
IF x == y THEN z := 1 END IF x == y THEN z := 1 ELSE z := 2 END
-
loops with
WHILE _ DO _ END
orFOR var FROM num TO num DO _ END
WHILE a > 0 DO a := a / 2 END FOR i FROM 1 TO 5 DO i := i + 1 << i END
-
procedure declaration with
PROC name_proc(args) IS _ END
PROC main(n) IS << n END
-
procedure invocation with
name_proc(args)
PROC write(n) IS << n END PROC main(n) IS write(n) END
Logo3D natuarlly implements all of Turtle3D's public procedures to control the turtle. These procedures can be called like any other Logo3D procedure:
PROC main(mida) IS FOR i FROM 1 TO 4 DO color(i/12, i/12, i/4) forward(mida) left(90) END END
a Logo3D program can be executed by using:
python3 logo3d.py program_source_code.l3d args
The main procedure will be executed by default if no other procedure and its arguments is passed by parameters