Program Construction Flashcards

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

What is an assembler

A

A simple translation program

Converts low level assembly language into machine code (binary)

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

What is a compiler

A

Convert high level language (source code) into machine code (object code)

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

What is an interpreter

A

Runs a high level language program without converting it into a binary executable

Takes a line of the high level program (source code), translates it and runs it, then runs the next line etc.

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

Advantages of an assembler

A

Just as efficient as machine code

No extra unnecessary lines of code generated

Can be used for programs which require maximum efficiency/performance

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

Advantages of a compiler

A

Although compilation may take mins, it produces an executable that will be fast to run over and over again

Executable program can be given to the end user without them needing to have a compiler

Very difficult for the end user to edit the code as it is in binary format

Shows a list of errors in the program which must be corrected before compilation (can also be disadvantage)

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

Disadvantages of compiler

A

Compiling can be slow and tedious when developing a program (as each time program needs to be ran it has to be recompiled)

A compiler targets a particular platform and cpu instruction set e.g. programs compiled for android ARM processors won’t work on Intel x86 chips etc.

Commonly used for a number of languages e.g. python, javascript

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

Advantages of an interpreter

A

No delay in waiting for compilation, program can begin to run immediately (ideal for program development)

Should run on any computer as long as there is an interpreter available for the language

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

Disadvantages of an interpreter

A

Program will run much more slowly as each line of code needs to be translated each time before it can run

Needs an interpreter to run it

End user has access to source code (can be stolen)

Only finds errors when it gets to a line with an error in, so program could have errors thst are never discovered until experienced by the end user

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

What is the ideal solution for compiler and interpreter

A

Assuming both exist for the language

Use an interpreter during development phase

When fully worked and tested, compile it for distribution to end-user

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

What is intermediate code

A

Similar to machine code but not processor specific

Potentially allows code to be created to run on multiple architectures

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

Advantage of intermediate code

A

Code runs very quickly as the conversion from intermediate code is much more straightforward than from high-level language

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

What are the stages of compilation (compiler)

A

Source code -> lexical analysis -> syntax analysis -> semantic analysis -> code generation -> optimisation -> object code (machine code)

Lexical analysis - code generation stored in symbol table

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

What does lexical analysis entale

A

Removes all comments and spaces + unnecessary characters

Tokenisation - converts source code into tokens which refer to entries in the symbol table

Add entries to the symbol table for variables, procedure names etc.

Does some basic error checking (e.g. flag up error if variable name was too long)

By the end of Lexical Analysis the source code program has been turned into a set of tokens which relate to entries in symbol table.

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

What are the two tables for lexical analysis

A

Reserved word table

User identifier table

Look at examples

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

What does the syntax analysis stage entale

A

Checks that the structure of the program is correct, that it follows grammar rules of the language

does this using a meta language

at this stage a list of syntax errors could be produced and compilation may stop

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

What does the semantic analysis stage entale

A

Checks for various types of error such as

Checks that all variables have been declared

Checks that real values are not being assigned to integers, strings assinged to booleans etc.

Checks there is no illegal mixed mode arithmetic (e.g. multiplying a string variable by an integer variable)

17
Q

What does the code generation and optimisation stage entale

A

Generates machine code

Each line of high level language usually become many lines of machine code

Sometimes routines try to improve efficiency by making the program smaller or making it run quicker

18
Q

What is a translation error

A

Error spotted by the compiler which are either:

Syntax errors

Semantic errors

19
Q

What is an execution error

A

Errors thst occur when the program is running and that cause the program to crash (run-time error)

E.g. a variable being divided by 0 or reading a record past the end of a file

Errors that the compiler itself cannot spot as the code is correct. Occurs due to particular circumstances

20
Q

Why does a compiled program take more time to debug than an interpreted one

A

Errors are reported after compilation is finished

One error may cause many other spurious errors

Recompiling after fixing an error adds time to the process

21
Q

Define linking error

A

Calling a standard function where the correct library has not been linked to the program

22
Q

What are the main objectives 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