-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresultsFixed.tex
722 lines (582 loc) · 20 KB
/
resultsFixed.tex
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
\chapter{Evaluation} \label{cap:Resultados}
\begin{displayquote}
\begin{center}
\textit{``There is no pain as long as I keep my eyes on the balance scale.''}
\end{center}
\end{displayquote}
\begin{flushright}
\textit{-- NORIAKI KUBO}
\end{flushright}
% \section{Introduction}
This chapter is dedicated to present to the reader a series of different approaches that were taken in order to test the Bleach programming language and the Tree-Walk Interpreter implemented for it from different perspectives. Regarding these perspectives, the following approaches were taken:
\begin{itemize}
\item \textbf{Test Suite:} A Test Suite is a carefully tailored collection of test cases and test scripts implemented in order to verify that a software program or a specific module of a program is behaving as expected.
\item \textbf{Implementation of famous Algorithms and Data Structures:} As a way to better demonstrate Bleach's expressiveness and prowess, this section is dedicated to present to the reader implementation of famous Algorithms and Data Structures commonly taught in an undergraduate Computer Science degree.
\item \textbf{Comparison of Bleach with ChocoPy, Cool and MiniJava:} Regarding comparison with its predecessors, this section is dedicated to compare Bleach with them in terms of language features.
\end{itemize}
\section{Bleach's Test Suite}
As mentioned above, one of the different ways to evaluate Bleach was through the creation of a test suite that verifies the correctness of the Tree-Walk Interpreter implementation. In this particular scenario, this test suite is composed of several test cases, the expected output for each of these test cases and a test script responsible for executing the test cases automatically.
The Test Suite is made of 44 test cases and a shell script that executes these tests in an automated manner. These test cases are divided into 3 groups (tests responsible for Expression nodes, tests responsible for Statement nodes and tests responsible for some of the Bleach Native Functions). All types of AST nodes previously presented in Table~\ref{tab:ASTNodes} are covered. Moreover, from these 44 test cases there are 2 of them that cover native functions from the following namespaces: \texttt{std::math} and \texttt{std::utils}.
Each test case is composed by a Bleach file (\texttt{.bch} extension) representing the Bleach program that will be executed by the interpreter, a file with the extension
\texttt{.bch.expected}, representing the expected output for that corresponding \texttt{.bch} file when it is executed and, finally, a corresponding \texttt{.bch.log} file that represents the actual output generated by the execution of such \texttt{.bch} file. In this context, it is important to highlight that each Bleach file (\texttt{.bch} extension) and its corresponding expected output (\texttt{.bch.expected} extension) were hand-crafted adopting an approach very similar to unit tests. Therefore, the focus of each test is on the runtime behavior of a single type of AST node. Finally, the difference between the \texttt{.bch.expected} and the \texttt{.bch.log} is computed. If there are no differences, then it means that the particular test case passed. Otherwise, it did not.
This process is automated by a shell script called \texttt{bleach\_test\_pipeline.sh} that automatically executes each Bleach program and compares its expected output file with the produced output file. In the end, this script provides a simple metric displaying how many of the test cases have passed from the total number and it also shows which test cases did not pass.
More detailed information about how to execute Bleach's test suite can be found at Bleach's official GitHub repository \cite{bleach_lang_git_repo}.
\section{Implementing Famous Algorithms and Data Structures in Bleach}
The main goal here is show the expressiveness and prowess of Bleach by demonstrating that it is possible to implement famous algorithms and data structures that are usually taught in an undergraduate "Introduction to Algorithms" course. These implementations, along with a few tests cases, can be found at \href{https://github.com/vmmc2/Bleach/tree/main/tests/algorithms_and_data_structures}{Famous A \& DS implementations in Bleach}. The implemented algorithms and data structures were:
\begin{itemize}
\item Binary Heap
\item Binary Search Tree
\item Binary Search
\item Breadth First Search
\item Depth First Search
\item Dijkstra's Shortest-Path Algorithm
\item Insertion Sort
\item Merge Sort
\item Queue
\item Quick Sort
\item Stack
\end{itemize}
\begin{comment}
\begin{itemize}
\item Stack
\begin{lstlisting}
class Node{
method init(value){
self.value = value;
self.next = nil;
}
method str(){
return self.value;
}
}
class Stack{
method init(){
self.root = nil;
self.length = 0;
}
method empty(){
return self.length == 0 ? true : false;
}
method size(){
return self.length;
}
method push(value){
let newNode = Node(value);
if(self.root == nil){
self.root = newNode;
}else{
newNode.next = self.root;
self.root = newNode;
}
self.length = self.length + 1;
return nil;
}
method pop(){
if(self.root == nil){
return "The stack is empty.";
}else{
let poppedValue = self.root;
self.root = self.root.next;
self.length = self.length - 1;
return poppedValue;
}
}
method str(){
let stackAsString = "";
let curr = self.root;
while(curr != nil){
stackAsString = stackAsString + (curr.value + " -> ");
curr = curr.next;
}
stackAsString = stackAsString + " nil";
return stackAsString;
}
method top(){
if(self.root == nil){
return "The stack is empty.";
}else{
return self.root;
}
}
}
\end{lstlisting}
\item Queue
\begin{lstlisting}
class Node{
method init(value){
self.value = value;
self.next = nil;
}
method str(){
return self.value;
}
}
class Queue{
method init(){
self.left = nil;
self.right = nil;
self.length = 0;
}
method empty(){
return self.length == 0 ? true : false;
}
method size(){
return self.length;
}
method front(){
if(self.left == nil){
return "The queue is empty.";
}else{
return self.left;
}
}
method back(){
if(self.right == nil){
return "The queue is empty.";
}else{
return self.right;
}
}
method push(value){
if(self.length == 0){
let newNode = Node(value);
self.left = newNode;
self.right = self.left;
}else{
let newNode = Node(value);
self.right.next = newNode;
self.right = newNode;
}
self.length = self.length + 1;
return;
}
method pop(){
if(self.length == 0){ // Queue is empty.
return "The queue is empty.";
}elif(self.length == 1){ // Queue is not empty and has only one element.
let poppedValue = self.left.value;
self.left = nil;
self.right = nil;
self.length = self.length - 1;
return poppedValue;
}else{ // Queue is not empty and has more than one element.
let poppedValue = self.left.value;
self.left = self.left.next;
self.length = self.length - 1;
return poppedValue;
}
}
method str(){
let queueAsString = "front -> ";
let curr = self.left;
while(curr != nil){
if(curr != nil and curr.next != nil){
queueAsString = queueAsString + (curr.value + " -> ");
}else{
queueAsString = queueAsString + curr.value;
}
curr = curr.next;
}
queueAsString = queueAsString + " <- back";
return queueAsString;
}
}
\end{lstlisting}
\item Insertion Sort
\begin{lstlisting}
/*
Code that implements the Insertion Sort algorithm.
Assumes it is a list where every value is of type 'num'.
*/
function insertionSort(l){
let n = l.size();
for(let i = 0; i < n; i = i + 1){
let curr = i;
while(curr > 0 and l.getAt(curr) < l.getAt(curr - 1)){
let temp = l.getAt(curr);
l.setAt(curr, l.getAt(curr - 1));
l.setAt(curr - 1, temp);
curr = curr - 1;
}
}
return;
}
\end{lstlisting}
\item Merge Sort
\begin{lstlisting}
/*
Code that implements the Merge Sort algorithm.
Assumes it is a list where every value is of type 'num'.
*/
function merge(a, b){
let n = a.size();
let m = b.size();
let i = 0;
let j = 0;
let k = 0;
let c = [];
c.fill(nil, m + n);
while(i < n or j < m){
if(j == m or (i < n and a.getAt(i) < b.getAt(j))){
c.setAt(k, a.getAt(i));
k = k + 1;
i = i + 1;
}else{
c.setAt(k, b.getAt(j));
k = k + 1;
j = j + 1;
}
}
return c;
}
function mergeSort(a){
if(a.size() <= 1){
return a;
}else{
let b = [];
let c = [];
let n = a.size();
let mid = std::math::floor(n/2 - 1);
for(let i = 0; i <= mid; i = i + 1){
b.append(a.getAt(i));
}
for(let i = mid + 1; i <= n - 1; i = i + 1){
c.append(a.getAt(i));
}
b = mergeSort(b);
c = mergeSort(c);
return merge(b, c);
}
}
\end{lstlisting}
\item Quick Sort
\begin{lstlisting}
/*
Code that implements the Quick Sort algorithm.
Assumes it is a list where every value is of type 'num'.
*/
function swap(list, a, b){
let temp = list.getAt(a);
list.setAt(a, list.getAt(b));
list.setAt(b, temp);
return;
}
function partition(list, low, high){
let pivot = list.getAt(high);
let i = low - 1;
for(let j = low; j <= high - 1; j = j + 1){
if(list.getAt(j) <= pivot){
i = i + 1;
swap(list, i, j);
}
}
swap(list, i + 1, high);
return i + 1;
}
function quickSort(list, low, high){
if(low < high){
let q = partition(list, low, high);
quickSort(list, low, q - 1);
quickSort(list, q + 1, high);
}
return;
}
\end{lstlisting}
\item Binary Search
\begin{lstlisting}
function binarySearch(list, target){
let left = 0;
let right = list.size() - 1;
while(left <= right){
let mid = std::math::floor((left + right) / 2);
if(list.getAt(mid) == target){
return mid;
}elif(list.getAt(mid) > target){
right = mid - 1;
}else{
left = mid + 1;
}
}
return -1; // Target value not present inside the list.
}
\end{lstlisting}
\item Binary Search Tree (BST)
\begin{lstlisting}
/*
Code that implements the Binary Search Tree data-structure by using a pointers approach.
*/
class TreeNode{
method init(key, value){
self.key = key;
self.value = value;
self.left = nil;
self.right = nil;
}
method str(){
return "Node Key: " + self.key + " - Node Value: " + self.value;
}
}
class BST{
method init(){
self.root = nil;
self.length = 0;
}
method insert(key, value){
if(self.root == nil){
self.root = TreeNode(key, value);
}else{
let curr = self.root;
while(true){
if(key < curr.key and curr.left == nil){
curr.left = TreeNode(key, value);
break;
}elif(key < curr.key and curr.left != nil){
curr = curr.left;
}elif(curr.key < key and curr.right == nil){
curr.right = TreeNode(key, value);
break;
}else{
curr = curr.right;
}
}
}
self.length = self.length + 1;
return;
}
method aux_delete(root, key){
if(root == nil){
return root;
}
if(key < root.key){
root.left = self.aux_delete(root.left, key);
}elif(key > root.key){
root.right = self.aux_delete(root.right, key);
}else{
// Scenario where the node to be deleted has one child or no child.
if(root.left == nil){
return root.right;
}elif(root.right == nil){
return root.left;
}
// Scenario where the node to be deleted has two children.
// In this case, the inorder sucessor of the node to be deleted is retrieved:
let temp = self.findMinimum(root.right);
// Replacing the root's key and value with its inorder successor's key and value:
root.key = temp.key;
root.value = temp.value;
// Deleting the inorder successor:
root.right = self.aux_delete(root.right, temp.key);
}
return root;
}
method delete(key){
self.root = self.aux_delete(self.root, key);
self.length = self.length - 1;
return;
}
method find(key){
let curr = self.root;
while(curr != nil and curr.key != key){
if(key < curr.key){
curr = curr.left;
}else{
curr = curr.right;
}
}
return curr == nil ? "Could not find the key inside the BST" : curr;
}
method size(){
return self.length;
}
method findMinimum(node){
let curr = node;
while(curr.left != nil){
curr = curr.left;
}
return curr;
}
method inorderTraversal(curr){
if(curr == nil){
return;
}
self.inorderTraversal(curr.left);
std::io::print(curr);
self.inorderTraversal(curr.right);
return;
}
}
\end{lstlisting}
\item Binary Heap
\begin{lstlisting}
/*
Code that implements the Binary Min Heap data-structure.
*/
class MinBinaryHeap{
method init(){
self.heap = [];
}
method empty(){
return self.size() == 0 ? true : false;
}
method size(){
return self.heap.size();
}
method top(){
if(self.size() == 0){
return "The Binary Heap is empty!";
}else{
return self.heap.getAt(0);
}
}
method pop(){
if(self.size() == 0){
return "The Binary Heap is empty!";
}else{
self.swap(0, self.size() - 1);
let minValue = self.heap.pop();
self.bubbleDown(0);
return minValue;
}
}
method push(value){
self.heap.append(value);
self.bubbleUp(self.size() - 1);
return;
}
method swap(i, j){
let temp = self.heap.getAt(i);
self.heap.setAt(i, self.heap.getAt(j));
self.heap.setAt(j, temp);
return;
}
method bubbleDown(index){
let smallest = index;
let leftChild = 2 * index + 1;
let rightChild = 2 * index + 2;
if(leftChild < self.heap.size() and self.heap.getAt(leftChild) < self.heap.getAt(smallest)){
smallest = leftChild;
}
if(rightChild < self.heap.size() and self.heap.getAt(rightChild) < self.heap.getAt(smallest)){
smallest = rightChild;
}
if(smallest != index){
self.swap(index, smallest);
self.bubbleDown(smallest);
}
return;
}
method bubbleUp(index){
let parentIndex = std::math::floor((index - 1) / 2);
if(index > 0 and self.heap.getAt(index) < self.heap.getAt(parentIndex)){
self.swap(index, parentIndex);
self.bubbleUp(parentIndex);
}
return;
}
}
\end{lstlisting}
\item Depth First Search (DFS)
\begin{lstlisting}
function dfs(source, adjacencyList, visitingOrder, visited){
visited.setAt(source, true);
visitingOrder.append(source);
for(let i = 0; i < adjacencyList.getAt(source).size(); i = i + 1){
let neighbor = adjacencyList.getAt(source).getAt(i);
if(!visited.getAt(neighbor)){
dfs(neighbor, adjacencyList, visitingOrder, visited);
}
}
return;
}
\end{lstlisting}
\item Breadth First Search (BFS)
\begin{lstlisting}
function bfs(source, adjacencyList, visited, distance){
visited.setAt(source, true);
distance.setAt(source, 0);
let queue = Queue();
queue.push(source);
while(!queue.empty()){
let currNode = queue.pop();
for(let i = 0; i < adjacencyList.getAt(currNode).size(); i = i + 1){
let neighbor = adjacencyList.getAt(currNode).getAt(i);
if(!visited.getAt(neighbor)){
visited.setAt(neighbor, true);
distance.setAt(neighbor, 1 + distance.getAt(currNode));
queue.push(neighbor);
}
}
}
return;
}
\end{lstlisting}
\item Dijkstra's Shortest Path Algorithm
\begin{lstlisting}
function dijkstraAlgorithm(source, adjacencyList, distance){
let minHeap = MinBinaryHeap(); // Modified to receive lists of 2 elements.
distance.setAt(source, 0);
minHeap.push([0, source]);
while(!minHeap.empty()){
let currNodeInfo = minHeap.pop();
let minPath = currNodeInfo.getAt(0);
let currNode = currNodeInfo.getAt(1);
for(let i = 0; i < adjacencyList.getAt(currNode).size(); i = i + 1){
let neighbour = adjacencyList.getAt(currNode).getAt(i).getAt(0);
let edge = adjacencyList.getAt(currNode).getAt(i).getAt(1);
if(distance.getAt(currNode) + edge < distance.getAt(neighbour)){
distance.setAt(neighbour, distance.getAt(currNode) + edge);
minHeap.push([distance.getAt(neighbour), neighbour]);
}
}
}
return;
}
\end{lstlisting}
\end{itemize}
\newpage
\end{comment}
\newpage
\section{Comparing Bleach with ChocoPy, Cool and MiniJava}
In this section, a comparison between Bleach, ChocoPy, Cool and MiniJava is presented in Table 5.1 in terms of the features available in these programming languages.
\begin{table}[h!]
\centering
\begin{tabular}{|p{3.2cm}|p{3cm}|p{3cm}|p{3cm}|p{3cm}|p{3cm}|}
\hline
\textbf{Feature} & \textbf{Bleach} & \textbf{ChocoPy} & \textbf{Cool} & \textbf{MiniJava} \\ % First row: header
\hline
\textbf{Type System} & Dynamically-Typed & Statically-Typed & Statically-Typed & Statically-Typed \\ % Data rows
\hline
\textbf{Built-In Types} & \texttt{bool}, \texttt{nil}, \texttt{num}, \newline \texttt{list}, \texttt{str} & \texttt{int}, \texttt{bool}, \texttt{None}, \texttt{list}, \texttt{str} & \texttt{Int}, \texttt{Bool}, \texttt{String} & \texttt{int}, \texttt{int[ ]} \texttt{boolean}, \texttt{void} \\
\hline
\textbf{Arithmetical Operators} & \texttt{+}, \texttt{-}, \texttt{*}, \texttt{/}, \texttt{\%} & \texttt{+}, \texttt{-}, \texttt{*}, \texttt{//}, \texttt{\%} & \texttt{+}, \texttt{-}, \texttt{*}, \texttt{/} & \texttt{+}, \texttt{-}, \texttt{*} \\
\hline
\textbf{Comparison Operators} & \texttt{>}, \texttt{>=}, \texttt{<}, \texttt{<=} & \texttt{>}, \texttt{>=}, \texttt{<}, \texttt{<=} & \texttt{<}, \texttt{<=} & \texttt{<} \\
\hline
\textbf{Equality Operators} & \texttt{==}, \texttt{!=} & \texttt{==}, \texttt{!=}, \texttt{is} & \texttt{=} & No support \\
\hline
\textbf{Logical Operators} & \texttt{and}, \texttt{or}, \texttt{!} & \texttt{and}, \texttt{or}, \texttt{not} & \texttt{not} & \texttt{\&\&}, \texttt{!} \\
\hline
\textbf{Assignment Operator} & \texttt{=} & \texttt{=} & \texttt{<-} & \texttt{=} \\
\hline
\textbf{Ternary Operator Support} & Yes & Yes & No & No \\
\hline
\textbf{If Statement Support} & \texttt{if}, \texttt{elif}, \texttt{else} & \texttt{if}, \texttt{elif}, \texttt{else} & \texttt{if}, \texttt{else} & \texttt{if}, \texttt{else} \\
\hline
\textbf{Loops Support} & \texttt{for}, \texttt{do-while}, \texttt{while} & \texttt{while}, \texttt{for in} (only in lists and strings) & \texttt{while} & \texttt{while} \\
\hline
\textbf{Break/Continue Statements Support} & Yes, Yes & No, No & No, No & No, No \\
\hline
\textbf{Function Declaration Support} & Yes (with the \texttt{function} keyword) & Yes (with the \texttt{def} keyword) & Yes (only method declaration within classes) & Yes (only method declaration within classes) \\
\hline
\textbf{Anonymous Function Support} & Yes (with the \texttt{lambda} keyword) & No & No & No \\
\hline
\textbf{Comments} & Single-line (\texttt{//}) and Multi-line (\texttt{/**/}) & Single-Line (\texttt{\#}) & Single-line (\texttt{---}) and Multi-line (\texttt{**}) & Single-line (\texttt{//}) and Multi-line (\texttt{/**/}) \\
\hline
\textbf{Language Paradigm} & Object-Oriented and Interpreted & Object-Oriented and Compiled & Object-Oriented and Compiled & Object-Oriented and Compiled \\
\hline
\textbf{Inheritance} & Single & Single & Single & Single \\
\hline
\end{tabular}
\caption{Comparison between Bleach, ChocoPy, Cool and MiniJava.}
\label{tab:example5x5}
\end{table}