13. Program Construction Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What are the 4 stages of program construction?

A
  1. Lexical analysis
  2. Syntax analysis
  3. Semantic analysis
  4. Code generation and optimisation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What happens during lexical analysis?

A
  • comments, unnecessary spaces and line breaks are removed
  • keywords, constants and identifiers are replaced by tokens (usually hex tokens)
  • these tokens allocate a machine code value to each identifier to identify them in the computer’s memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is an identifier table?

A

Identifies all of the variables/ constants in the program and their data types

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

What is a reserved word table?

A

Identifies all of the words native to the programming language being used e.g. input, output

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

What happens during syntax analysis?

A
  • tokens are checked to see if they match the spelling and grammar expected by analysing each token to determine whether they are using the correct syntax
  • if syntax errors are found, error messages are produced
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What happens during semantic analysis?

A
  • variables are checked to ensure they have been properly declared and used, and that they are the correct data type
  • operations are checked to ensure they are legal for the type of variable they are being used on
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens during code generation and optimisation?

A
  • constructs in high level languages are replaced by machine code
  • the code is optimised so that it is more efficient
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the aims of code optimisation?

A
  • achieve the required output of the program
  • increase the speed of the program
  • decrease demand on resources
  • not delay the overall compilation process
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a translator?

A

A program that converts source code (high level languages) into machine/object code.

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

What is a compiler?

A
  • takes the source code and translates it all in one go
  • once converted it can be run at any time, but the entire source code file has to be successfully compiled first
  • compilers can also optimise code

adv:
- programs run quickly as its already been completely translated
- supplied as an executable file, therefore source code cannot be easily modified

disadv:
- code is translated as a whole, so enough memory must be available to store all the code at once
- cannot spot errors
- must be recompiled every time source code is changed
- object code produced is specific to processor’s architecture

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

What is an interpreter?

A
  • translates source code one instruction at a time
  • the resulting machine code is executed immediately
  • this process is called interpretation

adv:
- instructions are executed as soon as they are translated
- requires less memory as instructions do not need to be stored for later use
- errors can be spotted quickly

disadv:
- interpreters run slower
- program has to be translated every time it is ran
- interpreters do not produce an executable file, so when being distributed the source code must be provided, which could be modified without permission
- interpreters do not optimise code

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

What is an assembler?

A

A program that converts assembly language into machine code.

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