280 likes | 426 Views
COMS 4115. Programming Languages &Translators Fall 2008 Prof. Stephen Edwards Mentor – Nalini Vasudevan. [K]AML : Array Manipulation Language. Kaori Fukuoka Ankush Goel Maninder Singh Mayur Lodha. Motivation. Array is a fundamental data structure Wide range of applications
E N D
COMS 4115 Programming Languages &Translators Fall 2008 Prof. Stephen Edwards Mentor – Nalini Vasudevan
[K]AML :Array Manipulation Language Kaori Fukuoka Ankush Goel Maninder Singh Mayur Lodha
Motivation • Array is a fundamental data structure • Wide range of applications • Array manipulation an error prone part of algorithms • APL has complicated mathematical form and character set
Overview • Expressive and concise Array Manipulation language • Rich set of operations on Arrays • Treats array as a primitive data type • Consistent structure
Features • Data types • Unlimited size Arrays • Padding elements of Array • Dynamic length Arrays • Selection on demand
Features • Operators • Control flow • Userdefined functions • Output
Hello World program show(“Hello World !!!”);
Array Declaration and Padding • [ ]a = {1,2,3,4,5,6,7,8,9,10}; • [ ][2]b = { {1,2}, {3,4}, {5}, {6} }; [ ][2]b = { {1,2}, {3,4}, {5,0}, {6,0} }
Array Selection • [ ]a = {1,2,3,4,5,6,7,8,9,10}; • [ ]b = [0,3..6,8,9]a;[ ]b = {1,4,5,6,7,9,10};
for Loop [ ]b = {1,4,5,6,7,9,10}; for (i = 0; i<#[ ]b; i++) { show( [i ]b , ” :: ”); } 1 :: 4 :: 5 :: 6 :: 7 :: 9 :: 10
Conditional Statement ? (a > b) { show(“ a is greater than b”); } ! { show(“b is greater than a”); }
Set Operations : Union • [ ][2]a = { {1,2}, {3,4}, {5,6} }; • [ ][2]b = { {5,6}, {7,8}, {9}, {10} }; • [ ][2]c = %+([ ][ ]a, [ ][ ]b); [ ][2]c = { {1,2}, {3,4}, {5,6}, {7,8}, {9,0}, {10,0} };
Set Operations : Intersection • [ ][2]a = { {1,2}, {3,4}, {5,6} }; • [ ][2]b = { {5,6}, {7,8}, {9}, {10} }; • [ ][2]c = %=([ ][ ]a, [ ][ ]b); [ ][2]c = { {5,6} };
Set Operations : Difference • [ ][2]a = { {1,2}, {3,4}, {5,6} }; • [ ][2]b = { {5,6}, {7,8}, {9}, {10} }; • [ ][2]c = %-([ ][ ]a, [ ][ ]b);[ ][2]c = { {1,2}, {3,4} };
Reverse Array • [ ][2]b = { {5,6}, {7,8}, {9}, {10} }; • [ ][2]c = - [ ] [ ]b; [ ][2]c = { {10,0}, {9,0}, {7,8}, {5,6} };
Copy Array • [ ][2]a = { {1,2}, {3,4}, {5,6} }; • [ ][2]b = [0,1][ ]a; [ ][2]b = { {1,2}, {3,4} };
Size of Array • [ ][2]a = { {1,2}, {3,4}, {5,6} }; • #[ ][ ]a returns 6. • #[ ]a returns 3.
Sum Array • [ ][2]a = { {1,2}, {3,4}, {5,6} }; • +[ ][ ]a returns 21. • +[0][ ]a returns 3. • +[ ][0]a returns 12.
Concatenate Array • [ ][2]a = { {1,2}, {3,4}, {5,6} }; • [ ][2]b = { {5,6}, {7,8}, {9}, {10} }; • [ ][ ]a ++ [ ][ ]b; [ ][2]a = { {1,2}, {3,4}, {5,6}, {5,6}, {7,8}, {9,0}, {10,0} };
Array Access • [ ][2]a = { {1,2}, {3,4}, {5,6} }; • [0][0]a returns 1. • [0][1]a returns 2.
Insert into Array • [ ][2]b = { {1,2}, {3,4}, {5,6} }; • [ ][2]b <- { 7,8,9 }; [ ][ ]b = { {1,2}, {3,4}, {5,6}, {7,8}, {9,0} }
Delete from Array • [ ][2]b = { {1,2}, {3,4}, {5,6} }; • [ ][ ]b -> 1; [ ][ ]b = { {3,4}, {5,6} }
User defined Functions function add(a,b) { return a+b; }
.kaml file Lexer Tokens Parser AST Exception Handling Symbol Table Interpreter Function Table Output Architecture
Sample Program : Transpose [][]x for(i=0;i<#[]x;i++) { []temp = [i][]x; [][i]y = []temp; }
Sample Program : Stack • push(c)[]b <- {c}; • pop() []b -> #[]b;
Lessons Learned • Technical Aspects • Code Organization • Time management • Teamwork
Future Enhancements • Multi Dimensional Array • More Data Types