3 3. Page 5 (a) Four phases of a compiler, in alphabetical order, are: intermediate code generation lexical analysis mac
Posted: Mon May 09, 2022 6:19 am
3 3. Page 5 (a) Four phases of a compiler, in alphabetical order, are: intermediate code generation lexical analysis machine code generation syntax analysis State the input and output of each phase. (Hint: Considering that a compiler translates program source code into machine code, the input to the first phase will be program source code and the output from the last phase will be machine code.) (8 marks) (b) Here is some intermediate code generated by a compiler for part of a program written in Java: labell: rl = v10 < 100 if (rl = 0) jmp label2 r2 = v10 * 3 13 = r2+1 vl0 =r3 jmp labeli label2: Suggest what the original Java source code might have been. (6 marks) (c) Consider the following Java source code, where x is a local variable of type int and f() is a function that takes an int and returns an int: if(x=2) { x = f(0); } else { x = 1; } Translate the Java source code into intermediate code. You may wish to use comments to make the meaning of your intermediate code instructions clear. (6 marks)