program construction Flashcards

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

what is a translator ?

A

a translator changes (translates) a program written in one language into another language (usually machine code)

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

what are the three types of translators?

A

assembler
interpreter
compiler

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

describe an assembler

A

an assembler converts low level assembly language into machine code

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

describe an interpreter

A

an interpreter converts high-level language one line at a time into machine code and executes it

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

describe a compiler

A

a compiler converts high-level language into machine code for execution at a later time.
the entire program is converted at once

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
describe an interpreters :
execution method
execution speed 
complexity
error reporting 
repetition
A

execution method :
translates source code (high level code) into machine code , one line at a time

execution speed:
slower than a compiler as the code must be reinterpreted each time the program is run

complexity :
smaller , simpler programs

error reporting :
reports to the user immediately when errors are encountered and stops the program from running

repetition:
can be edited and run without translating the whole program
must reinterpret program every time it is run

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
describe a compilers :
execution method
execution speed 
complexity
error reporting 
repetition
A

execution method :
translates all the source code (high level code) into machine code in one go
produces an executable file that will run on other machines without the compiler needing to be installed

execution speed:
produce more efficient code than interpreters making the compiled programs run faster

complexity :
tend to be large complex programs

error reporting :
would analyse the entire program taking note of where errors have occurred and record them in an error file

repetition:
requires analysis and the generation of code only once
compiled programs have to be recompiled after any changes have been made

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

describe and give an example of a syntax error

A

A syntax error is a mistake in the grammar or spelling of the program
A syntax error will prevent the program from being compiled

Examples:
Incorrect Spelling:
pront ("hello")
Incorrect punctuation:
print ("hello"(
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

describe and give an example of a execution (runtime) error

A

an execution error is when the program unexpectedly stops as a result of an operation during execution

Examples:
Dividing by zero:
400/0

Reading too far in a file:
#there are 50 lines in the file
line=file.readlines( )
print (line [100] )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

describe and give an example of a logical error

A

a logical error is a mistake made by the programmer - the program still works but displays the wrong output

Examples:
incorrect calculations:
total = num1 - num2
print (total)

incorrect variable printed:
age= 16
name = “steve”
print (“nice to meet you” , age)

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

describe and give an example of a linking error

A

a linking error occurs when a compiler can’t find a sub procedure (e.g. the random library in python) that has been used

the programmer might have declared it incorrectly or forgotten to link(import) it.

Examples:
spelling an import command incorrectly:
import ramdon
number =random.randint(1,10)

requesting a function without linking:
number = random.randint(1,10)

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

describe and give an example of a rounding error

A

a rounding error is when the program rounds a real number to a fixed number of decimal places

this results in losing some value as the number becomes less accurate

examples:
rounding up:
80.87= 80.9 (inaccurate by 0.03)

rounding down:
63.4 = 63 (inaccurate by 0.4)

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

describe and give an example of a truncation error

A

a truncation error is when the program truncates a real number to a fixed number of decimal places

this results in losing some value as the number becomes less accurate

Examples:
truncation to 2 decimal places:
92.13787 = 92.13 (inaccurate by 0.00787)
truncation to 1 decimal place:
25.199876= 25.1 (inaccurate by 0.099876)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly