Skip to content

pawlo555/custom-logo-interpreter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom Logo language

Logo com.interpreter presented here is just another implementation of popular Logo language.
During work, we took inspiration from:
Lynx a modern, online version of logo with many additions as animations, multiple turtles etc.

Graphical User interface

img.png

Commands view consists of:

  • logo canvas where user can see code execution
  • history of pressed commands
  • navigation buttons
    • Commands button - go to Commands view (at picture above)
    • Procedures button - go to procedure view (at picture below)
    • Variables state - go to Variable state view
    • Load file - load ready file to programme
    • Clean button - clean environment (procedures and variables)
    • Stop button - stop current execution
  • command prompt to write commands (Enter to execute)
  • error box where errors will be displayed

img_1.png

Procedures view is very similar to Commands view - the main difference is command prompt and command history is replaced with simple editor and button executing the programme written in the editor.

img_2.png

Variable state displaying all current variables with values and all stored procedures.

Language list of commands:

Name Description Syntax
forward Move current turtle forward forward 100
fd 50+40
back Move current turtle back backward -10
bc 50-40
left Turn current turtle left left 90
lt 45
right Turn current turtle right right 90
rt 45
repeat Perform block of instruction set number of times repeat 2 [ fd 20 lt 90]
while While loop while 1 [ fd 20 rt 90]
assign Assign value to the variable assign :x 100
let Creates a variable with specific value or overwrite it let ::x 100
changeTurtle Change turtle from one to another changeturtle tt
clean Clean the canvas clean
home Set current turtle to start location (0,0) home
if If instruction - with no else if :x>10 { forward 100 left 90}
ifElse IfElse instruction - else is compulsory to specify ifElse :x>10 [fd 100] [back 100]
newTurtle creates a new turtle with specified name newturtle tt
penDown Put the pen down - turtle is drawing line when walking pd
penUp Put the pen up - turtle is not drawing while walking pu
call Call a specified procedure call square :x
procedure Creates a procedure procedure square :x { repeat 4 [ fd :x left 90]}
removeTurtle Removes turtle removeturtle tt
rename Change current turtle name rename ttt
setColor Set current turtle pen color setcolor 7
setPenSize Set current turtle pen size setpensize 5

Comments

To write commends use: # comment here #
Comments need to be open and closed and could take many lines.

Math expression:

Language enables writing mathematical expression for example:
(2+2)*2 will evaluate to 8 and 2+2*2 will evaluate to 6.
When writing operator that takes two arguments put it between them:
2 pow 7 is correct, while:
pow 2 7 will give an error.

List of mathematical expressions:

Name Value Alternative values Description
abs abs ABS Absolute value
arctan arctan ARCTAN Arcus tangent from value
cos cos COS Cosine function
int int INT Cast value to integer
ln ln LN Natural logarithm
minus - Minus sign
random random RANDOM Random number between 0 (inclusive) and specified value (casted to int and exclusive)
round round ROUND Round value to integer
remainder remainder REMAINDER, % Modulo
sin sin SIN Sinus function
sqrt sqrt SQRT Square root of value
tan tan TAN Tangent function
not not NOT, ! Logical not
power pow POW, ^ Power of two numbers 10 pow 2 is equal 100
sum + Sum of two values
product * Product of two values
division / Division of two values
different != Not equal
equals == Equal
bigger > Bigger relation
smaller < Smaller relation
bigger or equal >= => Bigger or equal relation
smaller or equal <= =< Smaller or equal relation
exp exp EXP Exponential function equals to POW with e as exponent
log log LOG Logarithm with specified base: 16 log 2 = 4
or or OR, || Logical or
and and AND, && Logical and

Variables

Variable could bea an integer, boolean or double.
Variable names as in Python are just references, they don't refer to specify type.
All possible conversions will be done automatically for example:
true will be cast to 1 or 1.0 if necessary and 0 to false or 0.0

Lists of commands

In many commands you are supposed to add at least one list of commands. These 3 ways of doing this are the same:

if 1>0 forward 100
if 1>0 { forward 100 }
if 1>0 [ forward 100 ]

You can omit brakets when writing only one command. You also can choice between {} and []

Variables name

In order to refer to variable name x you have to add at least one : before variable name. Numbers of : refers to scope. Basically each : refers to one scope starting from : referring to the current scope.
Language supports variables shadowing and using expressions like: ::x could be useful in some situation.
Let examine this code:

let :x 100
repeat 1 {
    let :x 50
    forward ::x
    back :x
}

In this situation turtle will move 100 forward and then 50 back.
It's work a bit different with assign command.

let :x 100
repeat 1 {
    let :x -10
    repeat 1 {
        assign :x 50 // this will affect x from first repeat
        assign ::x 50 // to change global x
        let ::x 25 // will change x from first repeat
        let :x 1
        assign :x 50 // now this will affect x from second repeat
        assign :::x 100 // now this will set global x to initial value
    }
}

The difference is that let counts all scopes but assign counts only those containing selected variable.
So where changing value of variable from outer scope it is better to use assign.
Scopes are counting like in assign also in others commands.

Procedures

There are two commands that are connected with procedures: call and procedure. First is used to call procedure. Second to create it. Example:

procedure square :x {
    repeat 4 {
        forward :x
        left 90
    }
}
call square 100 

Opening application

Download target/LogoTranslator-1.0.jar and exec by command: java -jar LogoTranslator-1.0.jar

This work with java version "17.0.1"

Other option is install Maven project.