1.2.2 Flashcards

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

Give two advantages of using compiled code over interpreted code

A
  • Faster to execute
  • Does not require compiler to run
  • safer as can’t be reverse engineered
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Give two advantages of using interpreted code over compiled code

A
  • It is platform independent

- Runs instantly without time waiting for compilation

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

What are the stages of compilation?

A
  • Lexical analysis
  • Syntax analysis
  • Code generation
  • Optimisation
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 compared to the rules of the programming language
  • Syntax errors are identified and reported as a list
  • Symbol table is updated with more detail
  • Semantic analysis
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does a compiler do

A

Translates high level language source code into machine code which is stored in an object file. One or more object files are then combined to form the final executable code.

Same source code can be run through different compilers to generate machine code for different CPUs

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

What does an interpreter do

A

An interpreter translates source code one line at a time, once translated the machine code is executed immediately.

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

What does an assembler do

A

Converts assembly language source code into machine code. The assembler is usually designed to produce machine code for a specific CPU.

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

When is assembly language usually used

A

When the program needs to interact very closely with the details of the hardware, for example device drivers.

It is also used when code needs to be high speed and efficient

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

What happens during lexical analysis

A
  • The compiler breaks down the ASCII into its component parts called lexemes
  • Compiler scans the source code letter by letter looking for keywords (IF, WHILE)
  • Removes redundant characters such as tabs, whitespace and comments
  • lexemes are converted into binary sequences of fixed length called tokens
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What happens during code generation

A
  • Tokens are converted into machine code instructions
  • Allocates memory locations to tokens that were noted as variables
  • Works out relative addresses for jumping around within the program (IF)
  • Results stored as an object file
  • Tries to optimise the code (makes it more efficient and fast, removes redundant code)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is intermediate code

A

simplified code that is between high level & machine code

It is produced by compiler
and runs on any computer

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

Benefits of intermediate code

A
  • Allows portability between machines

- Allows sections of code to be written in different languages by different programmers

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

What is a virtual machine

A

A theoretical computer which provides an environment in which a translator is available

Uses an interpreter to run the intermediate code

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

Issue with virtual machines

A

Security, the current version of the VM may have security vulnerabilities that allow rogue code to take control of the host computer. This is why VMs are patched frequently.

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

Advantages of using an interpreter when writing code

A

Errors are reported as they occur rather than together and are easier to correct

Programs can be restarted from any point after correcting an error

Breakpoints (for debugging) can be inserted in the code to halt the program at any point at which point the values of any variables used can be displayed

It is possible to set variable values while running the program

Less memory is needed as only the object code from a single source code instruction in use is held and interpreters are usually smaller programs than compilers

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

Disadvantages of using an interpreter

A

The end user needs an interpreter

The program runs more slowly because the program has to be translated each time it is run

The end user has to be given the source code