Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This question is about code generation. (a) What data structure is used as input to code generators? What feature of it makes the implementation of

image text in transcribed

This question is about code generation. (a) What data structure is used as input to code generators? What feature of it makes the implementation of code generators simple and efficient? [5 marks] (b) Some compilers have a semantic analysis phase after lexing and parsing but before code generation. What is the purpose of this phase, and why is semantic analysis not done in the parsing stage? What about languages that don't have semantic analysis at all (e.g. Python or JavaScript)? [5 marks] (C) Explain the difference between type checking and type inference. (10 marks] (d) Many compilers don't generate machine code directly after lexing, parsing and semantic analysis. Instead they first generate machine-independent code, which is later, possibly after optimisation, used to generate code for the target architecture. Explain the characteristics of machine-independent code, and the advantages of using them as an intermediate layer in compilation. [10 marks] (e) Describe a scheme for the translation of function definitions and function calls into low-level code (e.g., RISC-V or stack machine code) based on a stack, as discussed in the lectures and the third task of the coursework. Assume that in the source language function calls are of the form f(e1, en) where ei, en are expressions, function definitions are of the form f(x1, ... xn) = BLOCK where BLOCK itself is an expression, and any expression evaluates to a 32- bit (i.e. 4-byte) integer. We also assume that code generation for other kinds of expressions is readily available, e.g., one can use genExp (BLOCK) and genExp(e1) directly. If you use uncommon instructions, please explain their semantics briefly. If you use activation records in your explanation, describe the layout of your activation records. Note that your answer comprises two parts: code generation for function definitions, and code generation for function calls

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions