-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lox
145 lines (109 loc) · 1.84 KB
/
main.lox
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
print "Hello World!";
var a = "global";
print a;
print "Entering Block";
{
print a;
a = a + "!";
}
print "Leaving Block";
print "Entering Block";
{
var a = "local";
print a;
}
print "Leaving Block";
print a;
var val = "if";
if (val == "if" and 23 == 2) {
print "In If.";
} else {
print "In Else.";
}
print "hi" and 3;
var a = 0;
var b = 1;
print "Printing some Fibonacci numbers";
while (a < 10000) {
print a;
var temp = a;
a = b;
b = temp + b;
}
for (var i = 0; i < 10; i = i + 1) {
print i;
}
fun hello(name) {
print "Hello " + name + "!";
}
hello("Suhas");
fun retHello() {
return "Hello World!";
}
print retHello();
fun fibonacci(n) {
if (n <= 1) {
return 1;
} else {
return fibonacci(n - 1) + fibonacci(n - 2);
}
}
for (var i = 0; i < 20; i = i + 1) {
print fibonacci(i);
}
fun makeCounter() {
var i = 0;
fun count() {
i = i + 1;
print i;
}
return count;
}
var count = makeCounter();
for (var i = 0; i < 10; i = i + 1) {
count();
}
fun walk() {
print "Walking!";
}
var move = walk;
move();
class Dog {
bark() {
print "Bark!";
}
getDogProvider() {
fun dogProvider() {
return this;
}
return dogProvider;
}
}
print Dog;
var dog = Dog();
print dog;
dog.howl = "Howl!";
print dog.howl;
dog.bark();
var dogProvider = dog.getDogProvider();
print dogProvider();
class Rectangle {
init(width, height) {
this.width = width;
this.height = height;
}
area() {
return this.width * this.height;
}
}
var rectangle = Rectangle(4, 1210);
print "Rectangle";
print rectangle.area();
class Square < Rectangle {
init(dim) {
super.init(dim, dim);
}
}
var square = Square(5);
print "Printing area of a square.";
print square.area();