|
|
Module 1 Exercise Solutions
-
(a) |
- (v) |
(b) |
- (i) |
(c) |
- (iv) |
(d) |
- (iii) |
(e) |
- (vi) |
(f) |
- (ii) |
-
-
Scanner: (Id, "Max") (Op, ":=") (Id, "Min")
(Op, "+") (Lit, 4) (Op, *) (Lit, 3)
Parser:
Semantic analyzer:
Optimizer:
Preparation for code generation
(Lots of other possibilities)
Code Generation
PushAddr |
Max |
|
Push |
Min |
|
Load |
(StackTop, Reg1 |
Reg1 = Min |
Add |
#12, Reg1 |
Reg1 = 12*Min |
Store |
Reg1, @1(StackTop) |
Max = Reg1 |
-
A := 12 * (Ex + E1/Em)
-
(a)
(b)
-
(a) Token = Basic lexical unit
(b) Syntax analysis = Parsing
(c) Parse tree = Syntax tree
(d) Intermediate representation = Intermediate code
(e) Abstract syntax tree = Abstract structure tree
(f) Analysis Phase = Front end
-
(a) Run the X0 program (that takes X programs to M programs)
through the X0 compiler (the M program which takes X0
programs to m programs). The output is M code, but it is m code which
takes X programs to M programs. Thus, we have a program written in
M which takes X programs to M programs. This is an X compiler.
(b) Take the M program which translates L programs to N code
and run the L program which translates L programs to N code through it.
The resulting N code is a program which takes L programs to N code.
This is an L compiler for machine N.
|