23 7 91All it does is to push the three above numbers onto the stack. 91 is on top and 23 is at the bottom (last in, first out).
23 7 91 .The only difference between this and the previous is the "dot" (.) at the end of it. The "dot" pops (removes) the top element off the stack and prints it. After this, only two numbers are remaining (23 and 7) on the stack. 7 is on the top.
23 7 91 .SThis causes as output "23 7 91". dot-S prints the entire stack (topmost element is printed rightmost) but doesn't remove anything.
23 7 91 . . .We can also do arithmetic operations on the stack. "+" takes the top two elements off the stack, adds them, and pushes the result back. Similarly for "-", "*", and "/". So,
4 5 + .causes "9" to be printed and leaves the stack empty.
4 5 - .causes "-1" to be printed and leaves the stack empty.
77 DUP .Scauses "77 77" to be printed (and the stack now contains these two integers). Similarly, SWAP swaps the topmost two elements on the stack.
8 7 SWAP .Sprints "7 8". DROP drops the topmost element from the stack (unlike "dot", it doesn't print anything). OVER causes a copy of the second element on the stack to leapfrog over the first. So,
8 9 OVER .Scauses "8 9 8" to be printed (and remain on the stack). Finally, ROT takes the third element from the stack and moves it to the top.
7 8 9 ROT .Sprints "8 9 7" (and this also remains on the stack). As more examples,
11 22 33 SWAP DUPcauses "11 33 22 22" to be on the stack (doesn't print anything). Similarly,
11 22 33 ROT DROPcauses "22 33" to be on the stack (doesn't print anything). For your assignment, you only have to support the above commands (words). Furthermore, you can assume that only integers can be pushed onto the stack. A syntactically correct FORTH program is simply a string that contains any combination of integers and FORTH words, separated by white space. When printing using "dot" or "dot-S" you can assume that all printings are on the same line, with spaces in between the elements printed.
11 22 33 ROT DROP .the output is
("33","22")(yes you have to print those brackets and quotes). For the input
11 1 3 4 + 5 7 DROP . .Sthe output is
("5 11 1 7","11 1 7")If something illegal is attempted, your interpreter should print
(illegal,illegal)This can happen, for instance, when dot/DUP/DROP is attempted on an empty stack, the arithmetic operations/SWAP/OVER are attempted on a stack that contains less than two elements, or when ROT is attempted on a stack that contains less than three elements.
3 2 . .produces
("2 3","")
You may not use any imperative features of ML (remember the language does have some impurities). For example, you may not use statement blocks beginning and ending with ( and );. You may use let's however as they do not run contrary to the spirit of functional programming. Absolutely no iteration is permitted (use recursion).
Your program must contain at least one curry-able function and you must make use of some curried form of it in your solution.
Adopt an iterative development approach. E.g., prepare your interpreter to first handle simple pushing and popping off stack, and then proeed to add the more complex FORTH words.
Your program will be submitted
electronically through the
Web-CAT
Curator for automatic grading. 80% of the score comes
from correct implementation and execution; 20% of the score comes from
(functional) programming style,
sound design, and good coding principles (comments,
readability). The system will begin accepting submissions on 10/22.
You will have unlimited submissions and we will grade the
final submission only. Remember we do not accept late assignments or
projects, unless you have already arranged something with us. Therefore,
please stay abreast of the deadline and plan your schedule accordingly.