# Assignment 5 solutions

1. Do problem 12 in Chapter 5, but assume a stack instruciton set.

12) Modify the parser shown in Figure 5.9 so it generates output in this assembly language.

```		procedure expression;
var more: boolean;
begin
op = ' '; {initially, no operator }  {--added--}
repeat
if lex = '(' then begin
lex_scan;
expression;
if lex = ')' then lex_scan else error;
end else begin
value;
end;
more := lex in ['+','-','*','/'];
if more then lex_scan;
until not more;
end {expression};
```

2. Write a set of macros that allow a C programmer to write code in this horrible notation:
```assign(i,times(plus(i,1),times(j,2)));
```
```		#define assign(var,val) var = (val)
#define times(v1,v2) ((v1) * (v2))
```

3. The fictional Ultimate RISC computer has one machine instruction, move, which moves an operand from the source address to the destination address. What the programmer wants to be able to write for this instruction is:
```	MOVE src,dst
```

The result should be identical to having written this:

```	W    src
W    dst
```
Write a macro, using the macro notation presented in Chapter 6, that will produce this result.
```		MACRO MOV,src,dst
W     src
W     dst
ENDMAC
```