Chapter 10 - Programming language translators Flashcards

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

What type of code is needed for the CPU to understand it and execute the instructions?

A

» Machine code

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

What is the relationship between assembly code and a binary code instruction?

A

» One - to -one

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

What does the machine code instructions that a particular computer can execute depend on?

A

» The instruction set

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

What is the processor instruction set?

A

» Manufacturer defines a set of these instructions that processor will be able to carry out that will only work with that particular processor
» Each type of processor will have a different instruction set and different assembly code

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

What are 2 features of low level language?

A

» Specific to the instruction set of the processor
» Non-portable (Meaning it can only be run on a processor of the same type that it was written for)

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

What is an advantage of using low level languages?

A

» Can make use of specific registers
» Therfore programmers have greater control over the movement of data in and out of the processor

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

Why are low-level languages not portable?

A

» As the machine code and assembly code are designed for that specific processor
» Therefore cannot be processed on other processors

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

What are 2 disadvantages of using low level languages?

A

» Difficult to write programs in low level languages as programmers need to have a very good understanding of the hardware being used
» Do not have libraries

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

What are the categories of low level language?

A

» Assembly code
» Machine code

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

What is the source code?

A

» Programming statements that are created by a programmer

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

What are 2 features of assembly code?

A

» Type of low-level-language, which is made up of commands/mnemonics
» Each code translates into 1 machine code instruction

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

What are the advantages of high-level languages?

A

» Much easier to write/read words
» Portable
» Come with libraries

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

How are assembly code instructions translated into machine code?

4 marks

A

» Done by an assembler
» Replaces mnemonic opcodes with machine code - LDA
» Replaces numeric operands with machine code - NUM2
» Chekcs syntax and runs error diagnostics if erros is found

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

What does the compiler do?

A

» Translates whole program written in a high level language into executable machine code
» Creates object code before being executed into machine code

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

How does a compiler work?

A

» Translates high-level code into machine all at once
» Carrying out a number of checks first
» Compiled code is non-portable
» Code can be run without a translater being present

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

What does an interpreter do?

A

» Translate code from high level language into machine code line by line

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

What are the advantages of a compiler?

A

» Code can be optimised by the compilier
» Can be distributed as machine code,meaning that the source code is hiddent

18
Q

What are the disavantages of a compiler?

A

» You have to wait until the entire program is compiled before receiving any errors - may take a large time for a large program
» Executable code is non-portable

19
Q

What are the benefits of an interpreter?

A

» Errors will be reported as soon as they are ecountered - dont have to wait for the entire program to be compiled
» Debugging is quick and easily

20
Q

What are the drawbacks of an interpreter?

A

» Program requires an interpreter to be run
» The interpreter takes up space in memory

21
Q

What is object code?

A

» Halway code between high level and machine code
» Set of instruction codes that is understood by a computer at the lowest hardware level, but not ready to be executed by the CPU

22
Q

What is the difference between a compiler and an interpreter in terms of the steps to turn code in machine code?

A

» Compiler - Source code - Object code - Machine code
» Interpreter - Source code - Machince code

23
Q

What are 2 differences between a compiler and an interpreter?

A

» Compiler does produce object code - interpreter does not
» Compiler translates the whole source code at once, intepreter analyses the code line by kine

24
Q

What is a library, and give an example?

A

» Sections of code already pre-programmed by other developers containg useful routines
» Such as RANDOM

25
Q

What are 3 advantages of using libraries?

A

» Saves time
» Uses expertise of other
» Has been already tested, making debugging easier

26
Q

What are 2 disadvantages of using libraries?

A

» May increase size of compiled file as library contains many routines that aren’t being used
» Not written by the programmer - may need to spend time familarising themsleves with it

27
Q

What is the purpose of the linker?

A

» Links the main program to libaries by including them in the final executable code

28
Q

What is the loader?

A

» Part of the OS which is then responsible for loading a program into main memory

29
Q

What are the 4 stages of compilation?

A

» Lexical analysis
» Syntax analysis
» Code generation
» Code optimisation

30
Q

What is a helpful mneumonic to help remember the stages of compliation

A

» Life Sucks G.O

31
Q

What are 3 features of lexical analysis?

A

» All unnecessary spaces (whitespaces) and all comments are removed
» Keywords, (e.g print), constants and identifiers are replaced with tokens - represents their function in the program
» A symbol table for every keyword and identifier in the program is developed

32
Q

What are some examples of tokens?

A

» <.identifier>,<.operator>,<.number>,<.keyword>,<.open_bracket>,<.close_bracket>
» Note the dot is needed, it is just their because of brainscape syntaxing lol

33
Q

What ar 4 features of Syntax Anaylsis?

A

» Tokens from Lexical Analysis are checked against the rules of the language
» Errors reported with a list of diagnositics
» Detail is added to the Abstract Syntax Tree
» Passes to code generation

34
Q

What are 3 features of Code generation?

A

» Here object code is created
» Program called linker can incorporate the code from libary with the main program
» Into a single executable file

35
Q

What are 3 features of code optimisation?

A

» Removes redundant instructions
» Replace inefficient code with code that achieves the same result but in a more effiecient way
» Allows code to execute faster - decrease memory usage

36
Q

What are 3 features of code optimisation?

A

» Removes redundant instructions
» Replace inefficient code with code that achieves the same result but in a more effiecient way
» Allows code to execute faster - decrease memory usage

37
Q

Why is Lexical analysis needed?

A

» Necessary to put the code into a format which can be read/processed by the syntax analyser

38
Q

Why is syntax analysis needed?

A

» To ensure the code is valid in as much as it meets all the structural rules of the language. Guarentees it runs

39
Q

Why is Code Generation needed?

A

» Turn the code into a format that processor can understand

40
Q

Why is code optimisation needed?

A

» Ensures the code runs much quicker and uses less memory