Q: Are we allowed to print negatives using the ML "~", or does it have to be with "-"? It's trivial to implement it the second way, but I'm just checking. A: Since you are building an interpreter for Forth (which presumably doesn't care what it is written in), you should adhere to Forth guidelines. So, you should print negative numbers with a "-". ------------------------------ Q: what should FORTH do if we try something like "3 6 /". Are we going to support floating point numbers? A: This project will deal with only integers. Round down. So, the above expression will result in zero being placed on top the stack (and the other two integers removed). ------------------------------ Q: In that case, when I do: "3/6" in ML, it gives an error. A: That's a bug on your part. The "/" is an ML division operator for reals, not integers. The infix division operator for integers in ML is "div". e.g., 6 div 3; ------------------------------ Q: How do I interpret a "/" operator in FORTH? DO we divide the second number by the first, or the other way round? A: "6 3 /" should lead to the number 2 being on top of the stack. "3 6 /" should lead to the number zero being on top of the stack. ------------------------------ Q: > > 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. > > > > Does it print the result, push the result, or print AND push the > > result? A: I don't know what you mean by "it". But you have to evaluate this FORTH "program" one word at a time. initially the stack is empty: <> 4 causes 4 to be pushed on the stack <4> 5 causes 5 to be pushed on the stack <4 5> + causes 4 and 5 to be popped off and pushes 9 on the stack <9> (this doesn't do any printing or output itself) . causes the topmost element to be printed and pops it off <> So the printed output is "9" and the stack is empty at the end of the day. Notice that only numbers can be pushed and popped off the stack. The rest - dot, dot-S, DROP etc. - are FORTH commands that operate on the stack and change the stack. They don't themselves belong on the stack. Maybe your question is whether "." (dot) prints the top element and then pops it off OR pops off and then prints it. As you can see, it is irrelevant. ------------------------------ Q: Does the program need to be able to skip lines? Or are empty lines considered a blank FORTH program that leads to ("","") being the result? A: An empty line is a legal FORTH program and should just lead to ("","") being the result. ------------------------------ Q: Along the same lines, is the last character of the file a newline, or just the end of the last FORTH command? A: I believe there will not be a newline character at the end of the "input.txt" file. ------------------------------ Q: Is .S on an empty stack an error? I'm assuming so, but I wasn't sure, since it wasn't trying to remove anything from the stack and that case is not stated explicitly as an error. A: .S on an empty stack is not an error. As the project spec says, only the other commands can cause an error. Running .S on an empty stack will merely not print anything. ------------------------------ Q: Also, do you suggest that we output all program results at one time, or should a program be run, the result of that program printed, and then the next program read and started? A: It really doesn't matter - your call. We will do: sml < and expect to find all the outputs in the output.txt file, one for each FORTH program. ------------------------------ Q: how many spaces will there be in between FORTH words in a given FORTH program? is it always exactly one space. A: As the project spec says, a syntactically correct FORTH program is simply a string that contains any combination of integers and FORTH words, separated by white space. white space can be tabs, spaces, in any quantities. There can be white space before, in-between, or after FORTH words. Of course, white space cannot be newlines since we are using newlines to separate FORTH programs. ------------------------------ Q: continuing on this track, how much space do we have to print between elements when using dot and dot S? A: you need only put one space. ------------------------------