Code Monkey home page Code Monkey logo

py_compiler's Introduction

Python compiler for imaginary C-like language for robots ๐Ÿค–

Contributors

Matija Fabek
Mateo Martinjak 

Environment functions: they are implemented in Turtle, their implementation should function as a 'black box' to the user

Function To/from environment Description Example
getCoord FROM gets list with x,y coords x,y= getCoord();
getOrientation FROM get orientation r=getOrientation();
setPower TO sets turtle power setPower(TRUE);
setSpeed TO sets turtle speed setSpeed(2);
setSteps TO sets turtle steps setSteps(50);
setRot TO sets turtle rotation setRot(rot);

Literals

Name Real value
TRUE 1
UNDEFINED 0
FALSE -1

Variable types

Type name Holds Description Example
int integer starts with a small letter c= 2;
string string starts with a small letter c= "id";
bool integer 3val logic,starts with capital letter R= UNDEFINED;
list list starts with capital letter 'L' L1 = [1,2,3];

Examples

  1. Arithmetic
//arithmetic
c= 2*8;
d= 3-6;
e=  2;
print(c - (d + e));

//Ispisujem: 17
  1. Type manipulation
//type manipulation

idFirst= 2250;
idSecond= 5078;
shift="2";

id= (string)idFirst + (string)(idSecond + (int)shift);
a = "Your ID is ";

print(a + id);
//Ispisujem: Your ID is 22505080
  1. Logic manipulation
d= 0;
A= UNDEFINED or TRUE;//A is TRUE
B= not TRUE or d==0 and TRUE; //B is TRUE,and has priority

if (B and A)
    d=1;
print(d);

//Ispisujem: 1

4.a Simple list

Lot = [4,8];

if (4 in Lot)
    print("T");

//Ispisujem: T

4.b List conversion 'LIST -> variables'

//left side can be: env_function that returns a list, LIST or LIST_VAR

v,p = getCoord();
print(p);

L = [ 20 + 4 , 20 + 6 ];
v,p = L;
print(p);

v,p = [2,4];
print(p);

print(L[0]);

//IZ OKOLINE DOBIVENE koordinate: [2,15]
//Ispisujem: 15
//Ispisujem: 26
//Ispisujem: 4
//Ispisujem: 24
  1. Tutle example
print("program pocinje s radom");
rot = 90;
x,y= getCoord();
r=getOrientation();


setPower(TRUE);
setSpeed(2);

for (i=0; i < 8 ; i++){
    
    
    x,y= getCoord();
    r=getOrientation();

    setSteps(50);
    setRot(rot);

    if (i == 4) rot =  rot-45;
    if (i == 4) break;
}

print("program gotov s radom");

py_compiler's People

Contributors

aeoden96 avatar mfabek avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.