Compilers, interpreters and assemblers - Describe the principal stages involved in the compilation process:
· lexical analysis
· symbol table construction
· syntax analysis
· semantic analysis
· code generation
· optimisation
This video discusses why computers need compilers, interpreters and assemblers
This video discusses how the principles stages of the compilation process works
These are all language translators. They enable software written in a computer language to be executed in machine code.
Compiler - A program that translates a high level language program into machine code or some other low level language. It produces a program that can be executed by itself. Programs such as Paint.exe are executable programs.
Interpreter - A program that checks, translates by calling routines and then executes a program line by line.
A compiled program will almost always run faster than an interpreted program. Once compiled into an 'exe' it does not need to be recompiled.
High Level Languages look like this:
C= A + B
Assembler - An assembler is a program that translated assembly language programs into machine code.
Machine code looks like this:
01101010100011111001010101010000010111100011000110
Assembly language looks like this:
MOV AL, 0
ADD AL, [1000]
ADD AL, [1001]
MOV [1002], AL
There are many principal stages involved in the compilation process: lexical analysis, symbol table construction, syntax analysis, semantic analysis, code generation and optimisation.
Comments and unneeded spaces are removed
Keywords, constants and identifiers are replaced by 'tokens'
A symbol table is created which holds the addresses of variables, labels and subroutines
Tokens are checked to see if they match the spelling and grammar expected, using standard language definitions. This is done by parsing each token to determine if it uses the correct syntax for the programming language.
If syntax errors are found, error messages are produced
Variables are checked to ensure that they have been properly declared and used
Variables are checked to ensure they are of the correct data type, e.g. real values are not being assigned to integers
Operations are checked to ensure that they are legal for the type of variable being used e.g. you would not try to store the result of a division operation as an integer
Machine code is generated
Code optimisation may be employed to make it more efficient / faster / less resource intense