計算機常用的幾種語言:PASCAL語言

計算機常用的幾種語言:PASCAL語言,第1張

計算機常用的幾種語言:PASCAL語言,第2張

PASCAL

  The computer language PASCAL was invented in 1970 by Professor Nucleus Wirth of Zurich. It was named after the French mathematician, Blaze Pascal,who invented one of the earliest known calculators--a forerunner of the modern computer. As with all computer languages PASCAL was designed to meet a particular objective. In this case the objective was to relate a language, which would be better suited to teaching programming than any existing language.

  Although PASCAL was invented in 1970, this is not to s叮that it came out of the blue and had no similarity to computer languages that already existed—PASCAL's ancestors include the programming languages ALGOL and PL I .PASCAL took much of the best material from these two languages and as a result it is a better and simple language than either.

  PASCAL, like BASIC, also is a high level language. However, before a program written in PASCAL can be run on a computer it must be trans-lasted into machine code. This is different from BASIC.It means that running a PASCAL program takes at least three operations:
(1) The program must be entered into the computer as text.
(2) It must be compiled into machine code
(3) It must then be run,i.e.the computer must begin obeying its instructions.

  The first stage usually involves the use of a pro-gram called an editor, which allows text of any sort to be entered, altered and saved for later use. The sec-and stage then uses the output from the editor and converts it to machine code. Finally this machine codes loaded into the computer and is allowed to take control. We can visualize this process as:
①program written on paper
②Editor
③program text in computer
④Compiler
⑤program in machine code form
⑥program loaded and running

  We start with a program written on paper and end with the equivalent machine code program in control of the computer's actions.

  In developing a program it is rare for it to work first time.In this case we have to discover the reason for the failure and correct it. This involves going back to the text of the program and using the editor to make the correction. The amended program must then be re-compiled and once again tested by running. This forms a cycle that may have to be repeated severalties.

  If you have used a computer with a language couch as BASIC you may be puzzled as to why PASCAL requires so many steps to get from a written program to running program. It is fairly common to find implementations of BASIC where the program is typed in, edited and run without any obvious moving from editor to compiler, catch. The reason for this is that an interpreter most often implements BASIC. An interpreter is a program that serves the same purpose as a compiler, in that it allows instructions writ-ten in a high level language to control a computer that understands only machine code, but it achieves this in a very different way.An interpreter is a program that’s in the machine at the same time as the text of over program. When you type RUN,or whatever word indicates that the computer should carry out your program, the interpreter looks at the first line of your program and makes the machine carve out actions that are implied by its meaning. You can think of this as the interpreter converting the current line of your program to machine code and running it whereas compiler converts the entire program before you can run it.

  It is obvious that for learning a language it is better to use an interpreter or some similar system. Its a sad fact that nearly all implementations of PASCAL use compilers and therefore not ideal foreigners.However, if you need a program to bedewed at full speed then use of a compiler is clearly-.he better choice. This is because an interpreter trans-.Ate the program every time it is run but a compiler4ocs it once only. Thus, for a program that uses an-interpreter, the translation time is added to the time Nat the program takes to carry out its task. Therefore, hale interpreters are easy to use, compilers produce sat programs.

  The picture that we have given so far is a little too simple to account for the way that all versions of PASCAL are implemented. The truth is that a complier is a program that translates from one computer language to another--not just to machine code.It would for example be quite possible to write a compiler to change PASCAL into BASIC.Indeed it must be an advantage because if we translated PASCAL into BASIC we could make use of the BASIC interpreter that is almost always supplied with a computer.

  What we have just proposed is a method that issued by many versions of PASCAL although instead of translating to BASIC the language that the compiler translates to is known as Plods. In other words,many PASCAL compilers do not translate PASCAL into machine code: Instead they produce another language called P Cod. A P-Code interpreter then interprets this P-Code pro-gram. This might sound like a silly way to run a program because it combines the difficulty of a compiler in the first stage with the slowness of an interpreter in the second, However, it is the method used by a number of PASCAL implementations and the reason is that it makes it easier to produce versions for different machines.If a compiler produces machine code then moving it to a new machine means virtually rewriting it. If a compiler produces P-Code then moving it to anew machine is a matter of writing a new P-Code interpreter--which is a considerably easier task!

To summarize, there are two popular ways to implement PASCAL:Compile to machine code, or compile to P-Code and then interpret it. Of course anyone version of PASCAL will only use one of these two methods but it should help you to understand the different steps that you have to go through to run your PASCAL programs and why other versions are different.

位律師廻複

生活常識_百科知識_各類知識大全»計算機常用的幾種語言:PASCAL語言

0條評論

    發表評論

    提供最優質的資源集郃

    立即查看了解詳情