Program Construction Flashcards

1
Q

Translators

A

Compilers
- Converts whole code into exe file
- file can then be run on any computer without the translator
- Can take a long time to compile source code as the translator will often have to
convert the instructions into various sets of machine code as different CPUs will understand instructions with different machine code from one another.

Interpreters
- Converts source code into machine code 1 line at a time
- This means that program runs very slowly
- used at testing/development stage
- programmers can quickly identify errors and fix them
- translator must be present on computer for program to run

Assembler
- used for assembly language (not high level languages)
- converts mnemonic assembly language instructions into machine code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Low Level Code

A

Machine Code (Low Level Code)
- CPU only understand machine code
- Consists of 1’s and 0’s

Assembly Language (Low Level Code)
- small set of commands which represent certain pieces of machine code
- commands are known as Mnemonics

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Machine Code: Object Code VS Executable Code

A
  • What it will do first is simply translate the code that we have written into machine code – this is known as object code.
  • If our program also makes use of libraries of code, a translator will need the help of something called a linker to link the additional library code to our object code. Only once the linker has done this, executable code will be produced and the CPU will be able to correctly run the program.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Lexical Analysis

A

Lexical Analysis
- Comments (e.g. #comments in Python) and whitespace are removed from the
source code.

  • The high level code is then converted into “tokens”, split up

Using the tokens, a symbol table would be produced containing all of the programs key words and identifiers (variable names) and their relative data types and (in the
case of variables) memory locations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Syntax Analysis

A

Syntax Analysis
- checking the structure of the code. This is called syntax analysis.
- Every programming language has a particular grammar. During syntax
analysis, the compiler checks that the way the tokens are arranged makes sense in the grammar of the language.
- Once the structure of the code is checked, the second stage is to check whether the tokens themselves make sense. This is semantic analysis. For example, if one token is expected to be a number and is instead a string or a Boolean, the compiler notices this error during semantic analysis.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Code Generation and Optimisation

A

Code Generation and Optimisation
- converts source code via the output of lexical and syntactic analysis into machine
code. The result is stored as an object file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Static and Dynamic Linkers

A

Static Linkers
- link and load the various library code to the program’s main code to produce the program’s executable file.
- Sometimes, if lots of libraries have been used, this will result in large programs which may take a long time to compile. To get around this, there are also dynamic linkers.

Dynamic Linkers
- link up library code at runtime. The library code will not be compiled together with the program. Instead the main program code will run and when it requires library code, it will use it on the fly. This reduces the size of a program.
- The issue is it a library that is required, is missing. Every had a ‘your system is missing the following DLL files’ message? This is when a windows program is trying to access a Dynamic Linked Library at run-time, which is missing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Summary

A

The three compilation stages are lexical, syntactic and code generation.

A lexicon for a computer language includes all the keywords and reserved symbols
it understands.

Lexical analysis breaks down source code into its component parts and stores them
as token types in a token table.

Syntactic analysis checks that the source code follows the grammar rules of the
language and to analyse the relationships between tokens.

Code generation produces machine code and stores it as an object file.

Code generation allocates memory locations to variables and constants.

Code generation works out relative addresses and adjusts the machine code to suit.

Code optimisation adjusts the machine code to reduce the use of memory or to
speed it up.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly