1.2.2 - Applications generation Flashcards

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

Translators: Describe and explain an Assembler.

A

Assembly code is a low level language with each instruction is assembly code being almost always equivalent to one machine code instruction. The machine code instruction set is completely dependent on the hardware and therefore each type of processor will have a different instruction set and different assembly code.

Before an assembly code program can be executed it must be translated into machine code or an intermediate language called bytecode. The is done by the assembler.

The assembler programtakes each assembly code instruction and converts it to the 0s and 1s of the corresponding machine code.

The input to the assembler is called the source code and the output is called the object code.

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

Translators: What is a compiler?

A

A program that translates high level language into machine code.
The source code which is written by the programmer is inputted into a compiler as data.
The compiler scans through the code several times and performs checks to produce the object code.
Different hardware platforms require different compilers since the object code will be hardware specific.

The object code can then be ran without the need of a compiler on its own. (Executable machine code)

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

Translators: What is an interpreter?

A

Once the programmer runs the written code, the interpreter looks at each line of the source code, analyses it and, if contains no syntax errors, translates it into machine code and runs it.

a = 1 // no output
b = 1 // no output
print(‘hello world!’) // produces Hello world output
e = a - n //Stops program due to error ‘n’ is not indentified.

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

How can a language achieve platform independence?

A

By using both a compiler and an interpreter.
Code is orignally compiled into Bytecode, either once and for all (Java) or automatically after each change detected in the source code (Python).
Platform independence is achieved by the language having a virtual machine (EG java virtual machine) that can understand all bytecode and translate the bytecode into the relevant machine code by detecting what hardware is being used.

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

Advantages of compilers

A

The object code can be saved on a disk and run whenever required without the need to recompile. However if an error is discovered in the program, the whole program has to recompile.

The object code executes faster than the interpreted code.

The object code distrubuted by the compiler can be executed without having the compiler present.

The object code is more secure as it cannot be read without a great deal of reverse engineering.

Appropriate to be used when a program is ran regularly. Appropriate when object code is sold externally and the company dont want the source code to be available.

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

Advantages of interpreter

A

Platform independence - source code can be ran on any machine which has the appropriate interpreter available.

Useful for program development as there is no lengthy recompilation each time an error is discovered.

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

Disadvantages of an interpreter

A

program may run slower than a compiled program, because each statement has to be translated into machine code.

EG. if a loop of 10 statements is performed 20 times, all 10 statements will be interpreted 20 times.

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

Stages of compilation: State all three stages of compilation.

A

Lexical analysis
Syntax analysis
Code generatipn and optimisation

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

Stages of compilation: Describe Lexical analysis.

A

Lexical analysis performs the following functions:

  1. Superflous spaces are removed.
  2. All comments will be removed from the program.
  3. Some simple error checking is performed:
    • An illegal identifier would be flagged as an error (such as ten% or X&Y instead of X&&Y)
    • Lexical analyser will detect an attempt to assign an illegal value to a constant.
    • It will NOT detect misspelt words or undeclared variables!
  4. All keywords, constants or indentifiers used in source code and replaced with tokens/unique symbols. For example identifiers will be converted into a pointer to an address in the symbol table.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Stages of compilation: Describe syntax and semantic analysis.

A

Syntax analysis is the process of determining whether the sequence of input characters form a valid sentence in the language.
In order to do this, the language has to be expressed as a set of rules, using for example syntax diagrams or bakes-Naur forms.

The semantics of the program will also be checked in this stage. (Ots possible to right a perfectly correct syntax but it still not work)
EG. The use of an undeclared variable or assigning a real value to an integer variable.

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

Stages of compilation: Describe Code generation and optimisation.

A

Final phase.
Code optimisation techniques attempt to reduce the execution time of the object code program by, for example, spotting redundant instructions and producing object code that achieves the same net effect of that specified by the source program, bu tn ot by the same means.

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

Disadvantage of code optimisation

A

Increase compilation time sometimes quite considerably

May sometimes produce unexpected results.

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