The combined computer provides both sets of instructions, i.e. one can switch between stack- and accumulator-based computation. In addition, it offers two further instructions that move data from stack to accumulator and vice versa:
'action' STACKTOACCU 'action' ACCUTOSTACKSTACKTOACCU pops the top element from the stack and stores it in the accumulator. ACCUTOSTACK pushes the current value of the accumulator onto the stack.
Since the specification for the stack computer covers all cases, we can simply copy these rules. Hence, we already have a correct code generator for the combined computer.
Because the rules for the accumulator-based computer are also correct, we copy them as well.
We add a rule that computes stack values in the accumulator:
'rule' StackCode(X): AccuCode(X) ACCUTOSTACKand a rule that computes accumulator values using the stack:
'rule' AccuCode(X): StackCode(X) STACKTOACCU