Source Code
Program code written by the programmer in high level code e.g C++
Assembly code
Low level code, each instruction maps to a single machine code instruction. Each machine will have its own assembly code instruction set.
Translation
Converting high level language to machine code
Why use high level languages?
It is easier to learn, understand, and debug.
Complier
translates whole program into machine code into machine code in one operation, reporting errors at the end of the process.
Interpreter
translates and executes program into machine code line by line, stops if an error is encountered and waits for program to be debugged before running again.
What is the compilation process?
Set of stages that turns source code into executable object code
What happens in lexical analysis stage?
Remove comments and white space. Allocate tokens. Produce a symbol table. Optimise code.
tokenised
happens in lexical analysis stage when the purpose of each element is identified such as variable name, arithmetic operation, value.
Use of symbol table
Used by the complier to keep track of all the elements identified in the program.
Syntax analysis
Compiler checks that the tokens are in correct order and follow rules of the programming language being used.
AST
Abstract syntax tree maps the structure of the program.
Semantic Analysis
Used to highlight logic errors, determines whether the code that has been written has meaning within the language
Types of semantic error
Data type declaration mismatch , wrong parameters called in a subroutine, using primitive variables ( reserved words as variable names.
Code generation
Seprate program which is distinct of the source code, known as object code.
Distinguishes between compliers and interpreters
Code generation. Interpreters do not produce executable file.
Code optimisation.
Happens at each stage of the compilation process, optimisers identify redundant or repeated code and remove or rearrange the code if necessary.
Libraries
store of pre-written subroutines that gives access to many specialist functions for example maths linpbrary in Java.
Linkers
resolves issue if several object code files when dealing with compilations of higher level languages by creating a singular executable file
Loaders
Copies the executable code into the RAM,
advantages of compliers
executable code cannot be reverse engineered, source code is protected, benefits commercial developers.
faster running time, executable file doesn't need to be translated, good for performance intensive games.
program doesn’t need translation, translator doesn’t need to be installed on computer
well optimisatied
disadvantages of compliers
errors are reported at the end of a compilation process which means that debugging process is slower for large programs as errors can be interlinked.
recompiling to make changes
can’t be run across different processors
LSSCO
lexical, syntax, semantic, code generation, optimisation
advantages of interpreters
line-by-line allows for interpreters allows for the developers to identify and debug errors as they occur. very useful to use in the development stage of software development.
error reports are shown in the console, debugging is quicker and easier
can be used across platforms.
disadvantages of interpreters
source code runs more slowly that compiled code as translation process repeats itself.
program requires an interpreter.
interpreter takes up memory space.
use of byte code
intermediate stage used by interpreter languages to speed up the translation process.
assemblers
translate assembly code to executable code
assembling vs translation
simpler process as it uses a one-to-one relationship between assembly code and machine code.