DB section has been updated to add some SQL code.
Explain the need for interpreters and compilers to translate high-level program code to binary (machine code instructions).
Computers only understand 10 things...
Computers can only execute machine code which is in binary. We will look at two types of translator programs, these are programs that convert program code into machine code.
Writing programs in binary can be very difficult so there are a large variety of programming languages - most are written for specific purposes. Some are shown below along with a screenshot of some Python source code.
These types of languages are known as High Level Languages.
There are lots of different types, all covering different areas. Some are shown below:
General Purpose Languages - Pascal, C, C++, Python, Java
Artificial Intelligence - PROLOG (PROgramming in LOGic), LISP
Operating Systems - C, C++, C#
App Development - Swift
There are certain features to be aware of when using High Level Languages
They are easier to write and understand than using assembly/machine code
Easier to spot and fix errors (debugging)
There are languages written for specific purposes so specific operations may be possible
High Level Languages are portable ( can run on different platforms)
They need to be translated into machine code for a system to execute them.
As has been mentioned earlier computers are digital machines – they only understand two symbols – 0 and 1. An instruction for execution may look like this:
1101 1010 1100 0000 0011 0101 0101 0011 1101 001 11110 0001
Writing a program in binary although it is possible is very difficult and time consuming to write and debug.
One step up from binary is known as assembly language.
A sample of commands in assembly language can include: mov,jmp.
Relationship between levels of languages
These commands are slightly easier to remember than machine code (but only just). Their main disadvantage is still lack of portability and can still be quite time consuming to debug.
So because of these problems, programming languages closer to the English language have been developed.
These languages, which use English-like phrases such as Print, For, If, Then and Else, are called High Level Languages.
Assembly language needs an assembler but that will not be needed for the course.
Interpreters translate then execute a single line of your programming source code at a time. This what you will use when developing Python later in the course.
They are usually used during development whilst code is still being tested and debugged.
Compilers translate the entire source code program and turn it into an executable program that can be saved and ran at any point.
This has advantages in that it will never need to be translated again so subsequently it will run faster. It also saves the program as machine code so no one else can modify or see your source code.
Translates then executes one line of source code at a time
Source code has to be translated every single time it is ran
Error feedback is given line by line
Is often used during development to give more constructive feedback
Interpreter needs to be loaded in memory to execute the program
Translates then executes all of the source code at one time.
The compiled (object) code can be saved and ran later
Error feedback is given at time of compiling
Is used at the end of the development to create an executable file.
Compiler needs to be in memory once when compiling the program