《英文文献及翻译:计算机程序(9页).doc》由会员分享,可在线阅读,更多相关《英文文献及翻译:计算机程序(9页).doc(10页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、-英文文献及翻译:计算机程序-第 10 页姓名:刘峻霖班级:通信143班学号:2014101108Computer Language and ProgrammingI. Introduction Programming languages, in computer science, are the artificial languages used to write a sequence of instructions (a computer program) that can be run by a computer. Similar to natural languages, such a
2、s English, programming languages have a vocabulary, grammar, and syntax. However, natural languages are not suited for programming computers because they are ambiguous, meaning that their vocabulary and grammatical structure may be interpreted in multiple ways. The languages used to program computer
3、s must have simple logical structures, and the rules for their grammar, spelling, and punctuation must be precise. Programming languages vary greatly in their sophistication and in their degree of versatility. Some programming languages are written to address a particular kind of computing problem o
4、r for use on a particular model of computer system. For instance, programming languages such as FORTRAN and COBOL were written to solve certain general types of programming problemsFORTRAN for scientific applications, and COBOL for business applications. Although these languages were designed to add
5、ress specific categories of computer problems, they are highly portable, meaning that they may be used to program many types of computers. Other languages, such as machine languages, are designed to be used by one specific model of computer system, or even by one specific computer in certain researc
6、h applications. The most commonly used programming languages are highly portable and can be used to effectively solve diverse types of computing problems. Languages like C, PASCAL and BASIC fall into this category.II. Language Types Programming languages can be classified as either low-level languag
7、es or high-level languages. Low-level programming languages, or machine languages, are the most basic type of programming languages and can be understood directly by a computer. Machine languages differ depending on the manufacturer and model of computer. High-level languages are programming languag
8、es that must first be translated into a machine language before they can be understood and processed by a computer. Examples of high-level languages are C, C+, PASCAL, and FORTRAN. Assembly languages are intermediate languages that are very close to machine languages and do not have the level of lin
9、guistic sophistication exhibited by other high-level languages, but must still be translated into machine language.1. Machine Languages In machine languages, instructions are written as sequences of 1s and 0s, called bits, that a computer can understand directly. An instruction in machine language g
10、enerally tells the computer four things: (1) where to find one or two numbers or simple pieces of data in the main computer memory (Random Access Memory, or RAM), (2) a simple operation to perform, such as adding the two numbers together, (3) where in the main memory to put the result of this simple
11、 operation, and (4) where to find the next instruction to perform. While all executable programs are eventually read by the computer in machine language, they are not all programmed in machine language. It is extremely difficult to program directly in machine language because the instructions are se
12、quences of 1s and 0s. A typical instruction in a machine language might read 10010 1100 1011 and mean add the contents of storage register A to the contents of storage register B.2. High-Level Languages High-level languages are relatively sophisticated sets of statements utilizing words and syntax f
13、rom human language. They are more similar to normal human languages than assembly or machine languages and are therefore easier to use for writing complicated programs. These programming languages allow larger and more complicated programs to be developed faster. However, high-level languages must b
14、e translated into machine language by another program called a compiler before a computer can understand them. For this reason, programs written in a high-level language may take longer to execute and use up more memory than programs written in an assembly language.3. Assembly Languages Computer pro
15、grammers use assembly languages to make machine-language programs easier to write. In an assembly language, each statement corresponds roughly to one machine language instruction. An assembly language statement is composed with the aid of easy to remember commands. The command to add the contents of
16、 the storage register A to the contents of storage register B might be written ADD B, A in a typical assembly language statement. Assembly languages share certain features with machine languages. For instance, it is possible to manipulate specific bits in both assembly and machine languages. Program
17、mers use assembly languages when it is important to minimize the time it takes to run a program, because the translation from assembly language to machine language is relatively simple. Assembly languages are also used when some part of the computer has to be controlled directly, such as individual
18、dots on a monitor or the flow of individual characters to a printer.III. Classification of High-Level Languages High-level languages are commonly classified as procedure-oriented, functional, object-oriented, or logic languages. The most common high-level languages today are procedure-oriented langu
19、ages. In these languages, one or more related blocks of statements that perform some complete function are grouped together into a program module, or procedure, and given a name such as “procedure A.” If the same sequence of operations is needed elsewhere in the program, a simple statement can be us
20、ed to refer back to the procedure. In essence, a procedure is just a mini- program. A large program can be constructed by grouping together procedures that perform different tasks. Procedural languages allow programs to be shorter and easier for the computer to read, but they require the programmer
21、to design each procedure to be general enough to be used in different situations. Functional languages treat procedures like mathematical functions and allow them to be processed like any other data in a program. This allows a much higher and more rigorous level of program construction. Functional l
22、anguages also allow variablessymbols for data that can be specified and changed by the user as the program is runningto be given values only once. This simplifies programming by reducing the need to be concerned with the exact order of statement execution, since a variable does not have to be redecl
23、ared , or restated, each time it is used in a program statement. Many of the ideas from functional languages have become key parts of many modern procedural languages. Object-oriented languages are outgrowths of functional languages. In object-oriented languages, the code used to write the program a
24、nd the data processed by the program are grouped together into units called objects. Objects are further grouped into classes, which define the attributes objects must have. A simple example of a class is the class Book. Objects within this class might be Novel and Short Story. Objects also have cer
25、tain functions associated with them, called methods. The computer accesses an object through the use of one of the objects methods. The method performs some action to the data in the object and returns this value to the computer. Classes of objects can also be further grouped into hierarchies, in wh
26、ich objects of one class can inherit methods from another class. The structure provided in object-oriented languages makes them very useful for complicated programming tasks. Logic languages use logic as their mathematical base. A logic program consists of sets of facts and if-then rules, which spec
27、ify how one set of facts may be deduced from others, for example: If the statement X is true, then the statement Y is false. In the execution of such a program, an input statement can be logically deduced from other statements in the program. Many artificial intelligence programs are written in such
28、 languages. IV. Language Structure and ComponentsProgramming languages use specific types of statements, or instructions, to provide functional structure to the program. A statement in a program is a basic sentence that expresses a simple ideaits purpose is to give the computer a basic instruction.
29、Statements define the types of data allowed, how data are to be manipulated, and the ways that procedures and functions work. Programmers use statements to manipulate common components of programming languages, such as variables and macros (mini-programs within a program). Statements known as data d
30、eclarations give names and properties to elements of a program called variables. Variables can be assigned different values within the program. The properties variables can have are called types, and they include such things as what possible values might be saved in the variables, how much numerical
31、 accuracy is to be used in the values, and how one variable may represent a collection of simpler values in an organized fashion, such as a table or array. In many programming languages, a key data type is a pointer. Variables that are pointers do not themselves have values; instead, they have infor
32、mation that the computer can use to locate some other variablethat is, they point to another variable. An expression is a piece of a statement that describes a series of computations to be performed on some of the programs variables, such as X+Y/Z, in which the variables are X, Y, and Z and the comp
33、utations are addition and division. An assignment statement assigns a variable a value derived from some expression, while conditional statements specify expressions to be tested and then used to select which other statements should be executed next. Procedure and function statements define certain
34、blocks of code as procedures or functions that can then be returned to later in the program. These statements also define the kinds of variables and parameters the programmer can choose and the type of value that the code will return when an expression accesses the procedure or function. Many progra
35、mming languages also permit mini translation programs called macros. Macros translate segments of code that have been written in a language structure defined by the programmer into statements that the programming language understands.V. History Programming languages date back almost to the invention
36、 of the digital computer in the 1940s. The first assembly languages emerged in the late 1950s with the introduction of commercial computers. The first procedural languages were developed in the late 1950s to early 1960s: FORTRAN, created by John Backus, and then COBOL, created by Grace Hopper The fi
37、rst functional language was LISP, written by John McCarthy4 in the late 1950s. Although heavily updated, all three languages are still widely used today. In the late 1960s, the first object-oriented languages, such as SIMULA, emerged. Logic languages became well known in the mid 1970s with the intro
38、duction of PROLOG6, a language used to program artificial intelligence software. During the 1970s, procedural languages continued to develop with ALGOL, BASIC, PASCAL, C, and A d a SMALLTALK was a highly influential object-oriented language that led to the merging of object- oriented and procedural
39、languages in C+ and more recently in JAVA10. Although pure logic languages have declined in popularity, variations have become vitally important in the form of relational languages for modern databases, such as SQL.计算机程序一、引言计算机程序是指导计算机执行某个功能或功能组合的一套指令。要使指令得到执行,计算机必须执行程序,也就是说,计算机要读取程序,然后按准确的顺序实施程序中编码
40、的步骤,直至程序结束。一个程序可多次执行,而且每次用户输给计算机的选项和数据不同,就有可能得到不同的结果。程序可分为两大类:应用程序和操作系统。应用程序直接为用户执行某项功能,如字处理或玩游戏。操作系统管理计算机和与之相连的各种资源和设备,如随机访问存储器、硬盘驱动器、监视器、键盘、打印机和调制解调器,以便使其他程序可以使用它们。操作系统的例子包括:DOS、Windows 95、OS/2和UNIX。二、程序开发软件设计者通过特殊的应用程序来开发新程序,这些应用程序常被称作实用程序或开发程序。程序员使用称作文本编辑器的另一种程序,来以称作编程语言的特殊标记编写新程序。使用文本编辑器,程序员创建一
41、个文本文件,这个文本文件是一个有序指令表,也称为程序源文件。构成程序源文件的单个指令被称为源代码。在这个时候,一种特殊的应用程序将源代码翻译成机器语言或目标代码操作系统将认作真程序并能够执行的一种格式。将源代码翻译成目标代码的应用程序有3种:编译器、解释器和汇编程序。这3种应用程序在不同类型的编程语言上执行不同的操作,但是它们都起到将编程语言翻译成机器语言的相同目的。编译器将使用FORTRAN、C和Pascal等高级编程语言编写的文本文件一次性从源代码翻译成目标代码。这不同于BASIC等解释执行的语言所采取的方式,在解释执行的语言中程序是随着每条指令的执行而逐个语句地翻译成目标代码的。解释执行
42、的语言的优点是,它们可以立即开始执行程序,而不需要等到所有的源代码都得到编译。对程序的更改也可以相当快地作出,而无需等到重新编译整个程序。解释执行的语言的缺点是,它们执行起来慢,因为每次运行程序,都必须对整个程序一次一条指令地翻译。另一方面,编译执行的语言只编译一次,因此计算机执行起来要比解释执行的语言快得多。由于这个原因,编译执行的语言更常使用,而且在专业和科学领域几乎总是得到采用。另一种翻译器是汇编程序,它被用于以汇编语言编写的程序或程序组成部分。汇编语言也是一种编程语言,但它比其他类型的高级语言更接近于机器语言。在汇编语言中,一条语句通常可以翻译成机器语言的一条指令。今天,汇编语言很少用
43、来编写整个程序,而是最经常地采用于程序员需要直接控制计算机某个方面功能的场合。程序经常被编写作一套较小的程序段,每段代表整个应用程序的某个方面。各段独立编译之后,一种被称为连接程序的程序将所有编译好的程序段组合成一个可以执行的完整程序。程序很少有第一次能够正确运行的,所以一种被称为调试程序的程序常被用来帮助查找被称为程序错误的问题。调试程序通常在运行的程序中检测到一个事件,并向程序员指出事件在程序代码中的起源。最近出现的编程系统,如Java,采取多种方法相结合的方式创建和执行程序。编译器取来Java源程序,并将其翻译成中间形式。这样的中间程序随后通过因特网传送给计算机,而这些计算机里的解释程序
44、接下来将中间程序作为应用程序来执行。三、程序元素大多数程序只是由少数几种步骤构成,这些步骤在整个程序中在不同的上下文和以不同的组合方式多次重复。最常见的步骤执行某种计算,然后按照程序员指定的顺序,进入程序的下一个步骤。程序经常需要多次重复不长的一系列步骤,例如,浏览游戏得分表,从中找出最高得分。这种重复的代码序列称为循环。计算机所具有的使其如此有用的能力之一,就是它们能够作出条件判定,并根据正在处理的数据的值执行不同的指令。if-then-else(如果则否则)语句通过测试某个数据段,然后根据结果从两个指令序列中选出一个,来执行这个功能。这些选择对象中的指令之一可能是一个goto语句,用以指引
45、计算机从程序的另一个部分选择下一条指令。例如,一个程序可能比较两个数,并依据比较的结果而分支到程序的另一个部分:If x is greater than ythengoto instruction #10else continue程序经常不止一次地使用特定的一系列步骤。这样的一系列步骤可以组合成一个子例程,而子例程根据需要可在主程序的不同部分进行调用或访问。每次调用一个子例程,计算机都会记住它自己在该调用发生时处在程序的那个位置,以便在运行完该子例程后还能够回到那里。在每次调用之前,程序可以指定子例程使用不同的数据,从而做到一个通用性很强的代码段只编写一次,而被以多种方式使用。大多数程序使用几
46、种不同的子例程。其中最常用的是函数、过程、库程序、系统程序以及设备驱动程序。函数是一种短子例程,用来计算某个值,如角的计算,而该值计算机仅用一条基本指令无法计算。过程执行的是复杂一些的功能,如给一组名称排序。库程序是为许多不同的程序使用而编写的子例程。系统程序和库程序相似,但实际上用于操作系统。它们为应用程序提供某种服务,如打印一行文字。设备驱动程序是一种系统程序,它们加到操作系统中,以使计算机能够与扫描仪、调制解调器或打印机等新设备进行通信。设备驱动程序常常具有可以直接作为应用程序执行的特征。这样就使用户得以直接控制该设备。这一点很有用,例如,在彩色打印机更换墨盒后,需要重新调整以达到最佳打
47、印质量的情况下。四、程序功能现代计算机通常将程序存储在计算机可以随机访问的某种形式的磁性存储介质上,如固定放在计算机中的硬盘或者便携式的软盘。这些磁盘上被称为目录的额外信息,指明盘上各种程序的名称、它们写入盘中的时间以及它们在磁盘介质上的开始位置。当用户命令计算机执行一个特定应用程序时,操作系统就浏览这些目录,找到程序,并将一个副本读入随机存储器。操作系统然后命令中央处理器在程序的起始位置开始执行指令。程序起始位置的指令为计算机处理信息作好准备,其方法是在随机存储器中找到闲置内存位置来容纳工作数据,从盘中取回用户指出的标准方式选项和默认值的副本,并在监视器上绘制初始显示。应用程序通过调用系统程
48、序而对用户输入的任何信息都要求一个副本。操作系统将如此输入的任何数据转换成标准的内部形式。应用程序然后使用该信息决定下一步干什么例如,执行某项期望的处理功能如重新定义一页文本的格式,或者从盘上的另一个文件获取某些额外信息。两种情况无论是哪一种,都要调用其他系统程序,以事实上完成结果的显示或对盘上文件的访问。运行结束或接到退出的提示时,应用程序进行进一步的系统调用,以确保所有需要保存的数据已写回磁盘。然后,应用程序向操作系统进行最后一次系统调用,指明它已运行结束。操作系统接下来释放随机存储器和该应用程序使用的任何设备,并等待用户的命令,以开始运行另一个程序。五、历史人们用程序的形式存储一系列指令
49、已经有几个世纪了。18世纪的音乐盒和19世纪末与20世纪初的自动钢琴,就可以播放音乐程序。这些程序以一系列金属针或纸孔的形式存储,每一行(针或孔)表示何时演奏一个音符,而针或孔则表明此时演奏什么音符。19世纪初,随着法国发明家约瑟夫玛丽雅卡尔的由穿孔卡片控制的织机的发明,对物理设备更精巧的控制变得常见了。在编织特定图案的过程中,织机的各个部分得进行机械定位。为了使这个过程自动化,雅卡尔使用一张纸质卡片代表织机的一个定位,用卡片上的孔来指示该执行织机的哪个操作。整条花毯的编织可被编码到一叠这样的卡片上,同样的一叠卡片每次使用都会编出相同的花毯图案。在开发和使用的程序中,有的由24,000多张卡片构成。世界上第一台可编程的机器是由英国数学家和发明家查尔斯巴比奇设计的,但从未完全制造成。这台叫做分析机的机器,使用和雅卡尔的织机类似的穿孔卡片来选择每个