program construction Flashcards
what is a translator ?
a translator changes (translates) a program written in one language into another language (usually machine code)
what are the three types of translators?
assembler
interpreter
compiler
describe an assembler
an assembler converts low level assembly language into machine code
describe an interpreter
an interpreter converts high-level language one line at a time into machine code and executes it
describe a compiler
a compiler converts high-level language into machine code for execution at a later time.
the entire program is converted at once
describe an interpreters : execution method execution speed complexity error reporting repetition
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
describe a compilers : execution method execution speed complexity error reporting repetition
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
describe and give an example of a syntax error
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"(
describe and give an example of a execution (runtime) error
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] )
describe and give an example of a logical error
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)
describe and give an example of a linking error
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)
describe and give an example of a rounding error
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)
describe and give an example of a truncation error
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)