Paper 1 · Computer Systems 试卷一 · 计算机系统

4.2 · Programming languages, translators and IDEs

4.2 · 编程语言、翻译器与 IDE

Languages, translators and IDEs

语言、翻译器与 IDE

The two kinds of programming language and why you would pick each, what an assembler does, how a compiler and an interpreter turn your code into machine code differently, and the tools an IDE puts in one window.

两类编程语言以及为什么会选用其中一类、汇编器的作用、编译器与解释器把代码变成机器码的不同方式,以及 IDE 把哪些工具放进了一个窗口里。

Core for all candidates 所有考生均需掌握的核心内容 Covers 4.2.1 to 4.2.5 涵盖 4.2.1 至 4.2.5 Describing the operation, not the benefits, is marked 描述工作过程而非好处才是评分要点

Explainer · 4.2.1

讲解 · 4.2.1

High-level and low-level languages

高级语言与低级语言

There are two ways to write instructions for a computer. One is written with English-like words and works on any machine. The other is written in the processor's own codes: hard for a person to read, tied to one type of chip, but tiny and fast. These are high-level and low-level languages. "High" and "low" describe how close the language is to the hardware, not how hard it is.

给计算机写指令有两种方式。一种用类似英语的词来写,并且能在任何机器上运行。另一种用处理器自己的代码来写:人很难读懂,而且绑定在某一种芯片上,但体积小、速度快。这就是高级语言和低级语言。"高"和"低"描述的是这门语言离硬件有多近,而不是它有多难。

Df

A high-level language is a programming language written with English-like keywords, so it is easy for people to read and write. It does not depend on any one type of computer, and a translator has to turn it into machine code first. Python, Java and Visual Basic are examples.

高级语言是一种用类似英语的关键字来写的编程语言,所以人容易读也容易写。它不依赖于任何一种特定的计算机,而且需要先由一个翻译器把它变成机器码。Python、Java 和 Visual Basic 都是例子。

Df

A low-level language works directly with a particular processor's own instructions. It is hard for people to read and is written for one type of hardware only. Machine code (binary instructions) and assembly language are both low-level.

低级语言直接使用某个特定处理器自己的指令。它人难以读懂,而且只为某一种硬件编写。机器码(二进制指令)和汇编语言都是低级语言。

Compared on比较项 High-level language高级语言 Low-level language低级语言
Reading and writing code读写代码 easy: keywords are close to English, so programs are quicker to write and mistakes are easier to spot 容易:关键字接近英语,所以程序写起来更快,错误也更容易被发现 hard: uses the processor's own codes or short abbreviations, not readable words 困难:使用处理器自己的代码或简短缩写,而不是可读的词
Debugging调试 easier: readable code makes a mistake easier to find and fix 更容易:可读的代码让错误更容易被找到和修正 harder: each step is low-level, so a fault is slow to track down 更难:每一步都很底层,所以一个故障要花很久才能查出来
Machine independence机器无关性 the same source code runs on different types of computer, given a translator for each 同一份源代码,只要有对应的翻译器,就能在不同类型的计算机上运行 written for one type of processor; it will not run on a different one 为某一种处理器编写;换一种处理器就跑不了
Control of the hardware对硬件的控制 no direct control: specific registers and memory addresses are hidden from the programmer 没有直接控制:具体的寄存器和内存地址对程序员是隐藏的 direct manipulation of the hardware: the programmer can use particular registers, memory addresses and hardware features 直接操控硬件:程序员可以使用特定的寄存器、内存地址和硬件特性
The finished program编译后的程序 usually larger, and can run more slowly than an equivalent low-level program 通常更大,而且可能比同等的低级语言程序运行得更慢 small and fast: little wasted space, runs quickly on that processor 小而快:几乎没有浪费的空间,在那个处理器上运行得很快

Real example. A team building a business app that must run on Windows, Mac and Linux would pick a high-level language, for its machine independence and quick development. The chip inside a washing machine, with very little memory and a need for fast, exact timing, would be programmed in a low-level language.

实际例子。一个团队要开发一款必须能在 Windows、Mac 和 Linux 上运行的商业应用,会选用高级语言,看中的是它的机器无关性和开发速度快。而洗衣机内部那块芯片,内存极少,又需要快速、精确的时序,就会用低级语言来编程。

!

Two things markers report. First, define a high-level language, do not just give a benefit: it uses English-like keywords and is independent of the hardware. Second, do not confuse the two: a low-level language is harder to read and write than a high-level one, not easier, and "high" does not mean "harder".

考官报告了两点。第一,要定义高级语言,不要只给一个好处:它使用类似英语的关键字,并且不依赖硬件。第二,不要把两者搞混:低级语言比高级语言更难读写,而不是更容易,而且"高级"不等于"更难"。

Try it yourself

动手试试

Match the language to the job

为任务选语言

Tap each job to choose high-level or low-level, then check.

点击每一项任务,选择高级或低级,然后检查答案。

Explainer · 4.2.2

讲解 · 4.2.2

Assembly language

汇编语言

Machine code is just binary, like 0001 00010010. Almost impossible to write by hand. Assembly language replaces each binary instruction with a short word you can remember, such as LDA or ADD.

机器码就是二进制,像 0001 00010010 这样。几乎不可能靠手写。汇编语言把每一条二进制指令替换成一个你能记住的短词,例如 LDA 或 ADD。

Df

Assembly language is a form of low-level language that replaces machine-code instructions with short words called mnemonics, for example LDA for "load", ADD, and STO for "store". Each mnemonic stands for one machine-code instruction.

汇编语言是低级语言的一种形式,它把机器码指令替换成叫做助记符的短词,例如 LDA 表示"加载"、ADD、STO 表示"存储"。每个助记符对应一条机器码指令。

An assembler is the translator for assembly language: it produces the matching machine code. One assembly instruction usually becomes one machine-code instruction.

汇编器是汇编语言的翻译器:它生成对应的机器码。一条汇编指令通常变成一条机器码指令。

A short assembly program to work out a shipping total:

一个计算运费总额的简短汇编程序:

Instruction指令 What this line does这一行做什么
LDA PriceLDA Price load the value of Price into the accumulator 把 Price 的值加载到累加器中
ADD PostageADD Postage add the value of Postage to whatever is in the accumulator 把 Postage 的值加到累加器里现有的值上
STO TotalSTO Total store the accumulator's value in Total 把累加器的值存到 Total 中
!

The marked word is mnemonic, not just "short word" or "abbreviation". And an assembly program is translated by an assembler, not a compiler; a compiler is for high-level languages.

评分要点是助记符这个词,而不只是"短词"或"缩写"。而且汇编程序是由汇编器翻译的,不是编译器;编译器是用于高级语言的。

Explainer · 4.2.3

讲解 · 4.2.3

Compilers and interpreters

编译器与解释器

A high-level program has to become machine code before the processor can run it. A compiler and an interpreter both do this, but in different ways.

高级语言程序在处理器能运行它之前,必须先变成机器码。编译器和解释器都做这件事,但方式不同。

Df

A compiler translates the whole program into machine code in one go, before any of it runs, and produces an executable file. That file then runs on its own, without the compiler.

编译器一次性把整个程序翻译成机器码,在其中任何一部分运行之前完成,并生成一个可执行文件。之后这个文件可以独立运行,不需要编译器。

Df

An interpreter translates and runs the program one line at a time: it translates a line, runs it, then moves to the next line. It does this every time the program is run, produces no executable file, and the program cannot run without the interpreter.

解释器把程序一次一行地翻译并运行:翻译一行、运行这一行,然后移到下一行。每次运行程序时它都这样做,不生成可执行文件,而且没有解释器程序就跑不了。

Reporting errors

报告错误

A compiler checks the whole program. If it finds errors, it outputs an error report for the whole program and does not produce an executable file, so nothing runs. An interpreter stops as soon as it reaches an error, reporting that one line; any lines before it have already run.

编译器检查整个程序。如果发现错误,它会输出针对整个程序的错误报告,并且不生成可执行文件,所以什么都不会运行。解释器则一到达错误就停下,报告出错的那一行;它之前的那些行已经运行过了。

Compiler编译器 Interpreter解释器 Assembler汇编器
Works on处理的对象 high-level language code高级语言代码 high-level language code高级语言代码 assembly language code汇编语言代码
How much at once一次翻译多少 the whole program, before it runs整个程序,在运行之前 one line, then runs that line一行,然后运行那一行 the whole program整个程序
Executable file produced?是否生成可执行文件? yes是 no否 yes是
Needed again to run the program?运行程序时还需要它吗? no否 yes, every time需要,每一次都要 no否
On an error遇到错误时 error report for the whole program; no executable针对整个程序的错误报告;不生成可执行文件 stops at that line; earlier lines have run在那一行停下;之前的行已经运行 error report for the whole program针对整个程序的错误报告
!

This statement asks for the operation, not the benefits. "A compiled program can be shared without the translator" is a benefit, not how a compiler works. Describe the mechanism: a compiler translates all the code before any of it runs; an interpreter translates one line, runs it, then the next.

这条考纲要求的是工作过程,而不是好处。"编译好的程序不需要翻译器就能分享"是一个好处,不是编译器如何工作。要描述机制:编译器在任何代码运行之前翻译全部代码;解释器翻译一行、运行这一行,再翻译下一行。

Try it yourself

动手试试

The same program, two translators

同一个程序,两种翻译器

A four-line program with a typo on line 3 (prise should be price). Step through what a compiler does, then what an interpreter does.

一个四行的程序,第 3 行有个拼写错误(prise 应该是 price)。逐步看看编译器怎么做,再看看解释器怎么做。

Explainer · 4.2.4

讲解 · 4.2.4

Choosing a compiler or an interpreter

选择编译器还是解释器

Neither one is simply "better". They suit different points in a program's life.

没有哪一个单纯地"更好"。它们适合程序生命周期中的不同阶段。

Interpreter解释器 Compiler编译器
Advantage优点 quick to test and debug while developing: a change can be run straight away, and each error is shown as it is reached, one at a time 开发时测试和调试很快:改一处就能马上运行,而且每个错误在被执行到时就显示出来,一次一个 the executable runs on its own, without the compiler, so it can be given to any user; it runs faster because it is translated only once; the source code does not need to be shared 可执行文件不需要编译器就能独立运行,所以可以交给任何用户;因为只翻译一次,所以运行更快;源代码不必分享出去
Disadvantage缺点 the program will not run without the interpreter installed; it runs more slowly because every line is translated again on each run 没有安装解释器程序就跑不了;运行更慢,因为每次运行时每一行都要重新翻译一遍 slower to develop with: after every change the whole program must be compiled again before it can be tested 开发时更慢:每改一次,整个程序都要重新编译一遍才能测试
When to use which 什么时候用哪个

An interpreter suits a program that is still being developed, because a change can be tested at once without compiling everything again. A compiler suits the finished program that will be shared and used, because the executable is fast, runs on its own, and the source code stays private.

解释器适合还在开发中的程序,因为改一处就能立刻测试,不用把整个程序再编译一遍。编译器适合将要分享和使用的成品程序,因为可执行文件快、能独立运行,而且源代码可以保持私有。

!

Asked why an interpreter suits development, do not just describe how an interpreter works. Give the reason: you see the result of each change immediately, and each error is shown one at a time as it is reached, so it can be fixed before moving on.

被问到为什么解释器适合开发时,不要只描述解释器如何工作。要给出理由:你能立刻看到每次改动的结果,而且每个错误在被执行到时一次一个地显示出来,所以可以在继续之前先把它修好。

Try it yourself

动手试试

Compiler or interpreter?

用编译器还是解释器?

Tap each situation to choose the translator that suits it best, then check.

点击每一种情况,选出最适合它的翻译器,然后检查答案。

Explainer · 4.2.5

讲解 · 4.2.5

Integrated development environments (IDEs)

集成开发环境(IDE)

Writing code in a plain text editor means switching to another program to run it, another to hunt for errors, another to look things up. An IDE puts all of those tools in one window.

在纯文本编辑器里写代码,意味着要切到另一个程序去运行它、再切到另一个去找错误、再切到另一个去查资料。IDE把所有这些工具放进了一个窗口里。

Df

An IDE (integrated development environment) is a single piece of software that brings together the tools a programmer needs to write, run and fix a program, in one place.

IDE(集成开发环境)是一个单独的软件,它把程序员编写、运行和修改程序所需的工具集中到一个地方。

Try it yourself

动手试试

Explore an IDE

探索一个 IDE

Click each tool to see what it does and how it helps.

点击每个工具,看看它做什么、怎么帮到你。

!

Asked for the functions of an IDE, some candidates give functions of an operating system instead. An IDE's functions are all about writing and testing code. Also, do not answer in a circle: "auto-completion means it auto-completes" earns nothing; say what it completes and why that helps.

被问到 IDE 的功能时,有些考生却给出了操作系统的功能。IDE 的功能全都是关于编写和测试代码的。另外,不要绕圈子回答:"自动补全就是它会自动补全"得不到分;要说清楚它补全什么、以及那为什么有帮助。

Check your understanding

检验你的理解

Which of these is an advantage of a high-level language over a low-level language?

下面哪一项是高级语言相较低级语言的优势?

Check your understanding

检验你的理解

What is an assembler used for?

汇编器是用来做什么的?

Check your understanding

检验你的理解

A compiler finds three errors in a program. What happens?

编译器在一个程序里发现了三个错误。会发生什么?

Check your understanding

检验你的理解

A programmer is still writing and testing a program, changing it often. Which translator suits this best, and why?

一个程序员还在编写和测试程序,并且经常改动它。哪种翻译器最适合这种情况,为什么?

Common mistakes

常见错误

Markers reported these patterns for 4.2.1 to 4.2.5 考官针对 4.2.1 至 4.2.5 报告了以下模式

RecurringFor compilers and interpreters, candidates give the benefits when asked for the operation. "A compiled program can run without the translator" is a benefit, not how a compiler works. Describe the mechanism: a compiler translates all the code before any of it runs and produces an executable file; an interpreter translates one line, runs it, then the next, every time the program runs.

反复出现关于编译器和解释器,被要求描述工作过程时,考生却给出了好处。"编译好的程序不需要翻译器就能运行"是一个好处,不是编译器如何工作。要描述机制:编译器在任何代码运行之前翻译全部代码,并生成一个可执行文件;解释器翻译一行、运行这一行,再翻译下一行,而且每次运行程序时都这样。

Asked why an interpreter suits development, candidates describe how it works instead. The reason: you see the result of each change at once, and each error is shown one at a time as it is reached, so it can be fixed before moving on.

被问到解释器为什么适合开发时,考生却去描述它如何工作。理由是:你能立刻看到每次改动的结果,而且每个错误在被执行到时一次一个地显示出来,所以可以在继续之前把它修好。

On languages, candidates define a high-level language by a benefit ("it is easy to read") rather than by what it is (English-like keywords, hardware independent), and confuse the two types, saying a low-level language is easier to write. Few can give a drawback of a high-level language, or a real reason to use a low-level language (direct hardware control, small fast code).

关于语言,考生用一个好处来定义高级语言("它容易读"),而不是说清楚它是什么(类似英语的关键字、不依赖硬件),并且把两类语言搞混,说低级语言更容易写。很少有人能说出高级语言的一个缺点,或者使用低级语言的一个真正理由(直接控制硬件、代码小而快)。

Asked to name a translator, candidates answer "a translator", which is not specific. Name the one that fits: compiler or interpreter for a high-level language, assembler for assembly language.

被要求说出一种翻译器时,考生回答"翻译器",这不够具体。要说出合适的那一个:高级语言用编译器或解释器,汇编语言用汇编器。

On IDEs, candidates list feature names without saying how each helps, answer in a circle ("auto-completion auto-completes"), or give operating-system functions instead of IDE ones.

关于 IDE,考生只罗列功能名称,不说每个怎么帮到人,或者绕圈子回答("自动补全就是会自动补全"),或者给出了操作系统的功能而不是 IDE 的功能。

✕

Benefit, not operation: "A compiler is better because it is faster and you can share the program."

好处而非工作过程:"编译器更好,因为它更快,而且你可以把程序分享出去。"

✓

Right: "A compiler translates the whole program to machine code before any of it runs and produces an executable file. An interpreter translates and runs one line at a time, each time the program runs, and stops at the first error."

正确:"编译器在任何代码运行之前把整个程序翻译成机器码,并生成一个可执行文件。解释器每次运行程序时一次一行地翻译并运行,并在第一个错误处停下。"

✕

Wrong tool's functions: "An IDE manages memory, files and user accounts."

答错了工具的功能:"IDE 管理内存、文件和用户账户。"

✓

Right: "An IDE provides a code editor, a debugger you can step through line by line, error diagnostics that underline mistakes as you type, auto-completion of names, and prettyprint that colours and lays out the code."

正确:"IDE 提供一个代码编辑器、一个可以逐行单步执行的调试器、在你输入时给错误画下划线的错误诊断、名称的自动补全,以及给代码上色和排版的美化打印。"

Go deeper

深入练习

Paper 1

Write the compiler vs interpreter comparison from memory

凭记忆写出编译器与解释器的对比

From memory, describe how a compiler operates and how an interpreter operates, then how each one reports errors. Check every point against the table in 4.2.3, and make sure you have described the operation, not the benefits.

凭记忆描述编译器如何工作、解释器如何工作,然后各自如何报告错误。对照 4.2.3 的表格核对每一点,并确保你描述的是工作过程,而不是好处。

Try the revision questions 做一做复习题

Revision questions

复习题

Past-paper style. Write an answer, then reveal the marking points and mark yourself.

采用历年真题风格。写下答案,然后展开评分要点给自己打分。

Question 1 · 4 marks 第 1 题 · 4 分

[4]High-level and low-level languages each have their place. Give two advantages and two disadvantages of the high-level option, compared with the low-level one.

[4]高级语言和低级语言各有各的用武之地。给出高级语言这一选择相较低级语言的两个优点和两个缺点。

Question 2 · 2 marks 第 2 题 · 2 分

[2]State what is meant by assembly language, and name the translator it needs.

[2]陈述汇编语言是什么意思,并说出它需要的翻译器。

Question 3 · 6 marks 第 3 题 · 6 分

[6]Describe the operation of a compiler and the operation of an interpreter, including how each one reports errors.

[6]描述编译器的工作过程和解释器的工作过程,包括各自如何报告错误。

Question 4 · 4 marks 第 4 题 · 4 分

[4]Explain why an interpreter is often the better choice while a program is still being written and tested, and a compiler for the finished program that will be shared.

[4]解释为什么在程序还在编写和测试时解释器往往是更好的选择,而对于将要分享的成品程序则用编译器。

Question 5 · 4 marks 第 5 题 · 4 分

[4]Describe two functions of an integrated development environment (IDE) and, for each, explain how it helps the programmer.

[4]描述集成开发环境(IDE)的两项功能,并对每一项解释它如何帮助程序员。

Flashcards

记忆卡片

Active recall for this subtopic’s key terms.

针对本子主题关键术语的主动回忆练习。

Prototype render · content grounded in the Cambridge IGCSE 0478 syllabus and real 0478 examiner-report data for 4.2 · not yet wired to live routes