Compiler Construction/Spring 2022 Homework 1
1 Compiler Architecture
Question 1.1 (3 points). Compilers typically separate the frontend (lexing, parsing, semantic analysis, IR generation) and the backend (code generation) to enable reuse and composition. Find a real-world example, where one frontend targets multiple backends. Find a real-world example, where multiple frontends target the same backend.
Question 1.2 (3 points). Many compilers have multiple optimizers, at different stages in the pipeline. Why is that useful? Find a real-world example of optimization at different stages.
Copyright By PowCoder代写 加微信 powcoder
Question 1.3 (3 points). Many compilers use two main intermediate representations – usually trees and some intermediate language. Some compilers go further and introduce more levels of IR. Why is that useful? Find a real-world example of an extra IR (in addition to trees and some intermediate language).
Question 1.4 (3 points). Some compilers translate a high-level language to another high-level lan- guage rather than assembly, virtual machine code, or machine code. What specific language is a com- mon target for such compilers and why?
2 Compiler Phases
These questions are based on Figure 1.7 on page 7 of the Dragon Book. Your task is to determine the output of each of the compiler phases for the following source code statement:
celsius = (fahrenheit – 32) * (5/9).
Question 2.1 (3 points). What sequence of tokens does the lexical analyzer output?
Question 2.2 (3 points). What abstract syntax tree does the syntax analyzer output?
Question 2.3 (3 points). What is the abstract syntax tree after the semantic analyzer modifies it?
Question 2.4 (3 points). What sequence of three-address instructions does the IR generator output?
Question 2.5 (3 points). What sequence of three-address instructions does the optimizer output?
Question 2.6 (3 points). What sequence of machine instructions does the code generator output? Use the same assembly language as the Dragon Book or improvise your own.
Adapted from CSCI-GA.2130-001 assignments by and . Page 1 of 1
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com