Languages & Environments



Download 2.16 Mb.
Page4/10
Date28.05.2018
Size2.16 Mb.
#51457
1   2   3   4   5   6   7   8   9   10

Compiler v Interpreter


Translator software usually comes in the form of either a compiler or an interpreter.

When translating using an interpreter, each line of source code will be translated to machine code one line at a time. This means that the interpreter software is present in main memory during each execution of the program and for the execution of every line. In this sense, an interpreter is not as efficient as a compiler.

The advantage of using an interpreter is that the execution will stop immediately if the interpreter translates a line of source code that results in an error. This makes an interpreter a useful tool to assist programmers as they attempt to identify and rectify errors. The interpreter cannot determine the actual error but can indicate the line that was not translated into executable machine code.

A compiler will translate the source code into what is known as object code. The compiler is held in RAM only for the time that it takes to translate the source code into object code.

Once object code has been created it is possible to run this code independently of the development environment and translator software. Using a compiler once to create object code makes run time more efficient but if the source code contains errors the programmer would need to re-compile to make use of the corrected object code.

As high-level languages depend upon translator software to convert instructions into binary, they do not depend on a specific hardware architecture. This means that a program written in a high-level language can be translated for use on systems using different processors, provided that translator software exists for the particular processor architecture. Software that can be used in this way is called 'portable' software.

High-level languages are easier to read, write and maintain than low-level languages. This is because high-level languages use terms that are similar to English. An example is the print command that is used in various high-level languages.

The following line of code from a high-level language is easy for a human to understand.



Print 'hello world'

Without a lot of background knowledge it is possible for a human to understand that this line of code would show the words ‘hello world’ on screen. This also makes high-level languages easier to maintain in the future if a programmer needs to alter code that has been created by another programmer.

Programmers can also access module libraries when they are using a high-level language. Module libraries contain sections of pre-written and pre-tested code that can be used without the need to spend additional time on creation and testing.

As well as being able to access module libraries, programmers can make use of in-built functions such as length(), which can be used to return the length of string variable.

High-level languages will also make use of data types such as String, Integer, Boolean and Real as well as data structures such as 1-D Arrays and, in some cases, records. Selection statements such as nested If Statements and Case statements as well as the use of iteration are also features of high-level languages.

There are three forms of high-level language within the course:



  • Procedural language

  • Declarative language

  • Object orientated language

Each language has its own set of characteristics and makes use of different features of high-level languages.

Procedural languages

Procedural languages are designed to allow programmers to create code that will be processed logically and in a structured order. Code is contained within procedures (also called subroutines) that carry out one main task. Procedures will be created to allow a series of steps to be followed. Data can be passed from procedure to procedure using parameters.

The following chart simplifies the idea of creating independent sections of code that can pass data from procedure to procedure within the structure of a procedural language.





The concept of passing data from procedure to procedure is called parameter passing and is examined in more technical detail within section 3, Computational constructs.



Download 2.16 Mb.

Share with your friends:
1   2   3   4   5   6   7   8   9   10




The database is protected by copyright ©ininet.org 2024
send message

    Main page