用户工具

站点工具


01-基础学习:课程:编译原理:作业:1

第一章 引论

Exercise 1.1.1 : What is the difference between a compiler and an interpreter?

解释器是一条一条的解释执行源语言。比如php,postscritp,javascript就是典型的解释性语言。
编译器是把源代码整个编译成目标代码,执行时不在需要编译器,直接在支持目标代码的平台上运行,这样执行效率比解释执行快很多。比如C语言代码被编译成二进制代码(exe程序),在windows平台上执行。
编译器: 解释器:

Exercise 1.1.2 : What are the advantages of
(a) a compiler over an interpreter
(b) an interpreter over a compiler?

(a).编译器产生的机器语言目标程序通常比解释器快很多
(b).解释器的错误诊断效果通常比编译器好,因为它逐个语句地执行源程序

Exercise 1.1.3 : What advantages are there to a language-processing system in which the compiler produces assembly language rather than machine language?

因为汇编语言易于输出和调试,之后,生成的汇编程序由称之为汇编器的程序进行处理,并生成可重定位的机器代码。
这样就减轻了编译器设计的工作量,将部分工作转到汇编器上,是的设计更专注与编译器本身,尽量减少超出其本身所容纳的内容的范围。

Exercise 1.1.4 : A compiler that translates a high-level language into another high-level language is called a source-to-source translator. What advantages are there to using C as a target language for a compiler?

就好比为什么编译器要产生汇编语言而是不是机器语言一样,C语言更简单更常用更加容易理解,同样方便调试和输出。另外,C语言可移植性强。

Exercise 1.1.5 : Describe some of the tasks that an assembler needs to perform.

汇编器就类似与编译器,只是它的源语言不是高级语言而是汇编语言。同样,它需要一个预处理器进行预处理,如聚合文件,展开宏等。写成的机器语言也要类似与连接器和加载器的程序,完成类似的工作。

Exercise 1 .6 . 1 : For the block-structured C code of Fig. 1. 13(a) , indicate the values assigned to w, x, y, and z .

int w,x,y,z;
int i=4;int j=5;
{
	int j=7;
	i=6;
	w=i+j;
}
x=i+j;
{
	int i=8;
	y=i+j;
}
z=i+j;

w=13,x=9,y=13,z=9

Exercise 1.6.4 : What is printed by the fo llowing C code?

#define a (x+1)
int x = 2;
void b() { x = a; printf ( " %d\n" , x) ; }
void c() { int x = 1; printf ( " %d\n " , a); }
void main () { b(); c() ; }

3
2

01-基础学习/课程/编译原理/作业/1.txt · 最后更改: 2020/04/07 06:34 由 annhe