Compilers


Martin McBride, 2017-05-17
Tags none
Categories none

High level languages are designed to be easier for humans to read, write and understand. This makes it faster to develop programs, especially complex programs. It also tends to result in fewer bugs in the code, and it is generally quicker to find them when they do occur.

Another advantage of higher level languages is that the programs you write can run on different types of computers, with little or no change. We say that the languages are portable - the programs can be moved from one computer to another. This compares with assembly language programs which usually need to be completely rewritten to run on a different type of CPU.

We call these higher level languages 3rd generation because they are more advanced than assembly language. A 3rd generation language needs to be translated before a CPU can execute the code. There are 2 different ways of translating code - we can use a compiler (as described in this section) or we can use an interpreter.

Example of high level code

Here is some code, written in C, that calculates the nth Fibonacci number:

int fibonacci(int n)
{
   int first = 0, second = 1, next, i;

   for (i = 0 ; i < n ; i++ )
   {
      if ( i <= 1 )
         next = i;
      else
      {
         next = first + second;
         first = second;
         second = next;
      }
   }

   return next;
}

Don't worry if you don't know how to program in C. The important things to notice are that the language is written in terms that humans can understand - for loops, if statements, variables (rather than branch instructions, registers and memory locations that you find in assembly language).

Compilers

Copyright (c) Axlesoft Ltd 2020