-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
81 lines (65 loc) · 2.68 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
1. General description
miLatte is an imperative programming language based on Latte (https://www.mimuw.edu.pl/~ben/Zajecia/Mrj2011/Latte/).
The following features has been added:
- multidimensional arrays
- arguments passed by reference
- function as parameter
- lambda functions
- static type validator
- break and continue
2. Detailed description
The syntax is very similar to that of Java. Below is a more detailed description of the key features.
a) Arrays - arrays can be mutidimensional and are declared like in Java:
int a[4][5][6];
There is no declaration with assignment so the assignment must be a separate statement e.g.
a[0][0][0] = 42;
Arrays are passed by value (like in Java).
b) Function arguments - variables are passed by reference so that they can be changed inside
the function. Arrays and lambdas are passed by value.
c) Function environment - when a function is called a new environment is created.
The environment contains all the functions withtin a scope. The variables are not
in the scope, except for the variables passed as argument (by reference):
int a;
void testEnv() {
int a = 4; //no error because the function environment does not inherit variables
}
void testEnv2(int b) {
b = 4; //no error because the function environment does not inherit variables
}
testEnv2(a); //now the variable a equals 4
void testEnv3() {
testEnv(); //function in scope so no error
}
d) Printing - the build-in functions void print(...) supports strings, bool, ints
and array cells e.g.:
boolean flag = true;
print(flag); //prints "true"
int a[10];
a[5] = 42;
print(a[5]); //prints "42"
string msg = "Hello World!";
prints(msg); //prints "Hello World!"
e) Lambdas and functions as params - lambdas have the following syntax
int(string, int) x;
x = int (string a, int b) => {print(a); return b;};
int functionAsParamTest(int(string,int) param1) {
return param1("WOW",4); //prints "WOW" and returns 4
}
f) Break and continue - they work in a standard way:
while(true) {
break; //the loop won't loop infinitely
}
int i = 0;
while (i < 4) {
i++;
continue;
print("This part of while loop is never executed and thus never printed"); //continue makes skip this part
}
g) Static types validator - validates types before executing the program
3. The contents of this directory.
There are two directories:
a) good - with good (working) examples
b) bad - with bad (not-working) examples to show how error handling works
4. Running - running is standard:
a) make
b) ./Interpreter program