Presentation is loading. Please wait.

Presentation is loading. Please wait.

By Andrew Horn And Ryan Kluck

Similar presentations


Presentation on theme: "By Andrew Horn And Ryan Kluck"— Presentation transcript:

1 By Andrew Horn And Ryan Kluck
Stacky By Andrew Horn And Ryan Kluck

2 Language Features The basic data structure that this language utilizes is a stack Each function gets its own stack All variables are assigned memory locations All operations and functions can only be evaluated by being pushed onto the stack

3 Types of Arguments Integers Function calls Memory calls Operator calls
Condition calls

4 Things you can push Numbers Functions
Function declarations (lambda expressions) Operators (including conditionals) push(1,2,3); push(:swap); push(func::{return 0}); push(1,2,+); push(1,2,<);

5 Return Statements func:swap:2{ } func:main:{ return(0,1); push(2,5);
A return statement pushes the returned values back onto the stack the returning function was called from in the order specified in the return statement The code on the right pushes 2 and 5 onto the stack, then calls swap which returns [5,2] which is concatenated onto the end of the stack in main func:swap:2{ return(0,1); } func:main:{ push(2,5); push(:swap);

6 Basic Syntax func:copy:1{ } func:main:{ return(0,0); push(1);
The example on the right is a properly formatted program that push 1 onto the stack in main, and then pushes the copy function onto the stack Copy pops 1 parameter off the main stack and returns that element and a copy of that element. Both the original element and the copy are pushed onto the main stack func:copy:1{ return(0,0); } func:main:{ push(1); push(:copy);

7 Access To The Stack A called function may access any number of values from the stack Any values passed to a function will be popped from the stack

8 Memory func:swap:2{ } func:main:{ return(0,1); push(:swap,>[0]);
Memory locations can be assigned to hold any argument as variable The code on the right pushes swap onto the stack, and then pops it off and stores it in memory. Then it pushes 1,2,3, and 4 onto the stack It then pops 4 off the stack and stores it in memory location 1, and pulls swap in from memory location 0 func:swap:2{ return(0,1); } func:main:{ push(:swap,>[0]); push(1,2,3,4,>[1],<[0]);

9 Functions func:swap:2{ } func:two:{ return(0,1); push(2); return(0);
A function is declared by func:<functionName>:<numb er of parameters>{} If number of parameters is not present this value is 0 by default The number of parameters is how many parameters are popped off of the stack when the function is pushed onto the stack func:swap:2{ return(0,1); } func:two:{ push(2); return(0);

10 Functions Continued If a function is pushed onto a stack without enough parameters for the function to run, it will remain on stack until it can run, is popped off, or the main function terminates func:swap:2{ return(0,1); } func:main:{ push(1); push(:swap); push(2);

11 If Statements func:main:{ push(2,1); if(1 0 >){ push(:swap); }
An if statement peeks at the values in the stack without popping them If statements are post fix The code on the right tests if location the second element in the stack is greater than the top element and if so swaps them func:main:{ push(2,1); if(1 0 >){ push(:swap); }

12 While Loops func:pop:1{} func:main:{
While loops test if a stack location is 0 and iterate until this happens The code on the right pops values off the stack with each iteration, until the top value is 0 func:pop:1{} func:main:{ push(0,2,3,4); while(0){ push(:pop); }

13 While Loops Continued While loops can also use conditionals
The code on the right tests if the top two elements on the stack are equal, and if not keeps popping elements off until this condition is met func:pop:1{} func:main:{ push(1,2,2,3,4); while(0 1 !=){ push(:pop); }

14

15 Potential Future Improvements
Strings (should be implemented as a list of characters on the stack) Lazy evaluation Overloading SQL


Download ppt "By Andrew Horn And Ryan Kluck"

Similar presentations


Ads by Google