I had to go by the same description when writing the testset, and had the same type of questions as you have. So I took the description as literally as possible, making sure the input was correct (as should be with any testset), and clarifying the interpretation choices in the examples.
Since the input consists of a code section and a data section, the following conclusions can be made:
- The code section consists of a program, and a program is defined as a list of instructions, and an instruction is defined as being one from the list given. So to be valid, the code section should not contain instructions not defined by the list. In other words, a parser should not fail when parsing the code section. This answers your question 2, and part of question 4.
- The data section consists of a list of integers. This answers your question 3, and part of question 4.
There is some vagueness in the description about the concepts 'integer' and 'variable'. For 'integer' I took the 'normal' interpretation as being a 32-bit signed number, but took care that the input would not cause arithmetic overflow/underflow when the program was executed correctly (NB: division by zero is not arthimetic overflow). This answers your question 1.
Nothing is said in the description about declaring and initialising variables, so I made what I think is the most sensible choise: a variable doesn't exist before it's assigned a value, an attempt to read a variable before it is initialised, causes and error. I illustrated that in the 4th and 5th sample case. You should note that only the interpreter can decide wether a variable is initialised or not, not the parser because the parser doesn't know the flow of events.
There are two ways a program can end:
- Normally: an implicit or explicit jump to an address outside the range of the list of instructions. In that case the program should print a list of all output generated by WRITE instructions. By implicit I mean the jump to the next instruction after successfully executing an instruction or not taking a conditional jump.
- Abnormally: 'something wrong happens'. It should then only print the word 'ABORTED', as in the second sample case. As what that 'something wrong' consists of, the problemsetter leaves us in the dark, so we're left with common sense. I think your list in question 4, apart for the first two items, sums it up quite nicely.
About your question 5: I think the last sentence of the description answers that and the 3rd sample case illustrates it.
There is one issue I didn't cover in the samples: not all instructions are atomic.
In most instructions this makes no difference for the flow of events, but for the conditional jumps it does. So let me add the following I/O to illustrate my choices:
Code: Select all
An equally valid choice would have led to printing 'ABORTED' in this case, but I chose the former.
I hope this clarifies matters, if not please say so.