Program Construction Flashcards

1
Q

What happens when an overflow error occurs?

A

We change (flip) all the values to the right of the most significant bit (MSB) to it’s opposite.

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

What are the 3 types of translators and what do they do?

A

Compilers- translates the whole program into machine code.
Interpreters- translate the program line by line into machine code
Assemblers- Translates assembly language into machine code using mnemonics.

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

What is the purpose of a translator?

A

To convert source code (higher level languages) to object code (aka machine code).

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

What are the advantages and disadvantages of using compilers?

A

Advantages
- It’s very fast as all source code is executed at once
- It produces an executable file that doesn’t need to be compiled each time when run.
- Library files are packages with the executable code.

Disadvantages
- Error messages are only displayed after the code has been compiled, making it difficult to debug individual lines of code.
- It’s therefore more difficult to debug

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

What are the advantages and disadvantages of using interpreters?

A

Advantages
- It’s easy to identify bugs as code is translated instruction by instruction.
- Code can be run on any machine with the interpreter
-If a single error is found, you can fix it and continue to compile (no need to recompile the whole program)

Disadvantages
- An executable file is not produced meaning it needs to be interpreted each time the program is run.
- It can be slower to compile
- The library files must be present for the program to be run (Separately)

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

What programming languages use compilers?

A

Java and C++

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

What programming languages use interpreters?

A

JavaScript, Python and Ruby

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

What are the 4 stages of the compilation process? (With what they do)

A
  • Lexical Analysis- spaces, functions → tokens, table
  • Syntax Analysis- grammar, rules
  • Semantic Analysis- Unused variables, data types
  • Code Generation- optimisation
    Lexy Sang Semi Calm???
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What happens in Lexical Analysis?

A

1) Unnecessary Spaces and comments are removed
2) Constants, keywords (e.ge print) and identifiers (names for variables/ functions) are replaces with ‘tokens’ that represent their function
3) A table is creates to store these tokens

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

What happens in Syntax Analysis?

A

1) Checks the grammar and spelling of the tokens in the table
2) They are also checked against the rules to determine if they are the correct syntax.
3) If the syntax, spelling or grammar is incorrect an error message is produced

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

What happens in Semantic Analysis?

A

1) Variables are checked to ensure they are declared and used
2) They are check to see if they have the correct data type (e.g. Strings, Integers, and real).

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

What happens in Code Generation?

A

1) Code is optimised to make generating machine code more efficient by removing redundant instructions and replacing inefficient code.

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

What are the 6 types of syntax errors?

A
  • Runtime Execution Error
  • Linking Error
  • Logical Error
  • Rounding Error
  • Syntax Error
  • Truncation Error
    Rabbits like licking really sweat Treats
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the description of a Runtime Execution Error and example?

A

The program stops due to an invalid operation during execution. For example trying to divide by 0 or attempting to read past the end of a file.

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

What is the description of a Linking Error and example?

A

The compiler can’t find a sub-procedure as the programmer has not declared it properly. E.g. A procedure (code) carrying out mathematical calculations but the maths library has not been called.

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

What is the description of a Logical Error and example?

A

A mistake in the program where the programs runs but an incorrect output is produced.
E.g. F=m+a (wrong mathematical symbols) or the wrong variable name.

17
Q

What is the description of a Rounding Error and example?

A

When a program incorrectly round a number to the wrong decimal place. E.g. 3.125 becoming 3.12

18
Q

What is the description of a Syntax Error and example?

A

When the code written does not fit the rules of the program. E.g. Typing print(Hello World”) or iupt(“What’s your name”)

19
Q

What is the description of a Truncation Error and example?

A

When a number is approximated to a whole number number incorrectly. E.g. 3.9 truncated to 34- an error of -0.9

20
Q

What is a software library?

A

A suite of programming code such as sub-routines and classes.

21
Q

What is a subroutine?

A

A model of code that preforms different tasks- it is used many times throughout the code by being called upon.

22
Q

What are the advantages of using library’s in program construction? (4)

A
  • Saves the programmer time as functions inside the library can be auto-completed or used.
  • Subroutines in library have already been tested meaning they are reliable
  • Subroutines were written by experts meaning they’ll be efficient.
  • Consistency between programs as programmers will know what the library does.