Save := A; A := B; B := Save;(a) Show the input to a lexical analyzer generator
(b) Show the output from the generated lexical analyzer
(c) Show the input to a parser generator
(d) Show the output from the resulting parser
y := z + 1 - x + 5
is a statement.
(a) | Assigns a variable to register 5 | (i) | Lexical Analysis |
(b) | Identifies loop as a label | (ii) | Syntax Analysis |
(c) | Changes A + 4 * 3 to A + 12 | (iii) | Semantic Analysis |
(d) | Finds a variable that has not been declared | (iv) | Optimization |
(e) | Changes A := A + 12 to Add #12, A | (v) | Preparatioin for Code Generation |
(f) | Creates a parse tree | (vi) | Code Generation |
(a) Language L is new to machine M. Language L has no compiler.
There is, however, a compiler for language Y
on machine M. One can create a
compiler for L in two steps:
Step 1: Using language
Y, write a compiler that translates (compiles) a small subset L0 of
language L
to the assembly language of machine M.
Step 2: Using the subset
L0, write a compiler that translates all of L to the machine
language of M.
Show how to use these programs to create a compiler that is written in the assemmbly language of M and compiles L programs to the assembly language of M.
(b) Machine N is brand new. There are no compilers for any
languages. However, there is a compiler for language
L(written in L0 ,
a subset of L) on machine M. A compiler for L can be created for
machine N in two steps:
Step 1: Change the code
generator of the compiler on M so that it puts out code for machine N rather
than M.
Step 2: Run the whole new
compiler through the old compiler. That is, compile the soure for
the compiler with
the new code generator and compile it using the L compiler as a program
on M putting out M assembly
language. Then we have a (cross) compiler on M, written in M that
converts L programs to N's assembly
language.
Show how to use these two steps to create a compiler for L written in the assembly language of N that translates to the assembly language of N, i.e., a compiler for L on machine N.
Send questions and comment to: Karen Lemone