Академический Документы
Профессиональный Документы
Культура Документы
...................................................................................................................................
...................................................................................................................................
...................................................................................................................................
...............................................................................................................................[2]
...................................................................................................................................
...............................................................................................................................[1]
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
......................................................................................................................................[2]
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
......................................................................................................................................[3]
2 (a) State what is meant by the following terms:
........................................................................................................................................[1]
........................................................................................................................................[1]
(b) Explain why a translator program is necessary when a program written in a high level
language is to be run on a computer.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]
........................................................................................................................................[1]
Example .............................................................................................................................
........................................................................................................................................[1]
........................................................................................................................................[1]
Example .............................................................................................................................
........................................................................................................................................[1]
3 (a) Explain the purpose of a compiler.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[4]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[4]
4 (a) Languages used in computing include assembly language and machine code.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(iii) State three of the tasks performed by an assembler when producing machine code.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [3]
(b) Either an interpreter or a compiler may be used with a high-level language program.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(c) One stage of compilation is lexical analysis.
(The quality of written communication will be assessed in your answer to this question.)
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [8]
5 (a) High level language programs may be translated using an interpreter or a compiler.
Explain the terms interpreter and compiler.
Interpreter ........................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
Compiler ...........................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
......................................................................................................................................[6]
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
......................................................................................................................................[2]
(c) The third stage of compilation is code generation. Describe this stage.
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
......................................................................................................................................[2]
..........................................................................................................................................
..........................................................................................................................................
..........................................................................................................................................
......................................................................................................................................[2]
6 The following are the first few lines of a source code program written in high-level language
XYZ which is about to be translated by the language compiler.
(a) During the lexical analysis stage the compiler will use a keyword table and a symbol
table.
Keyword table
Symbol table
[2]
(ii) Explain how the table contents are used to translate the source code.
[2]
(iii) Describe one other task done at the lexical analysis stage which does not involve
the use of the keyword table or symbol table.
[1]
(b) The final stage of compilation is code optimisation.
[2]
(ii) Give one practical example of code which would benefit from optimising.
[1]
7 (a) Software is used to convert source code into object code.
...........................................................................................................................................
...................................................................................................................................... [1]
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...................................................................................................................................... [4]
(b) Complete the table with ticks to show at which stage, if any, events occur when a compiler is
used.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(i) Explain why intermediate code may be more useful than executable code.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(ii) State what additional software is needed to run the intermediate code.
...........................................................................................................................................
..................................................................................................................................... [1]
...........................................................................................................................................
..................................................................................................................................... [1]
(c) When a compiler is used to produce executable code, code generation includes optimisation.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
1 (a) (i)
• Convert from source code/high level language/language used by humans…
• …into object code/low level/intermediate code/machine code/binary
[2]
(a) (ii)
• Compiler translates whole program & interpreter translates & runs 1 line at a time
• Interpreter stops when it finds an error, a compiler doesn’t
• Error diagnostics
• Compiler produces intermediate/executable file/code and interpreter does not
[1]
(b)
• Statements are checked…
• …against the rules of the language
• Errors are reported/listed/diagnostics may be given
[2]
(c)
• It allows files/modules/libraries…
• …that have been compiled…
• …to be combined wth a compiled program…
• …& converted into an executable file
• Completing address links
[3]
2 (a) (i) The instructions in a form that the computer can use/machine
code/binary/executable form [1]
(ii) The program written by the programmer/in a HLL (or higher level than machine
code) (NOT: The high level language itself) [1]
(c) (i) -Does not follow the rules of the language/Grammar error/Accept
spelling error, bit only if specify ‘to a key word’
-e.g. PLINT instead of PRINT [2]
-An error in the design of the code/does not follow the algorithm
(Not just ‘logically incorrect’)
-e.g. A jump to the wrong statement [2]
3 (a) • convert from source code / high level language / language used by humans…
• to object code / low level / executable code / intermediate code / machine code
• identifies errors
[max 2]
(b) • accepts output from lexical analysis
• statements are checked..
• against the rules of the language
• errors are reported…
• as a list at the end of compilation
• diagnostics may be given
• some reported errors may be spurious
• if no errors, code is passed to the code generator
[max 4]
(c) • interpreter stops at first error
• an error message is produced
• error would be corrected (by programmer)
• program can restart from any point
• this is repeated…
• …until all errors are removed…
• …when program will run
[max 4]
4 (a) (ii) binary notation
set of all instructions available
to the architecture/which depend on the hardware design of the
processor
instructions operate on bytes of data
[2]
(iii) reserves storage for instructions and data
replaces mnemonic opcodes by machine codes
replaces symbolic addresses by numeric addresses
creates symbol table to match labels to addresses
checks syntax/offers diagnostics for errors
[3]
(b) (i) translates one line/statement…
…then allows it to be run before translation of next line
reports one error at a time…
…and stops
[2]
(ii) translates the whole program as a unit
creates an executable program/intermediate program
may report a number of errors at the same time
optimisation
[2]
(c) source program is used as the input
tokens are created from individual symbols and from…
…the reserved words in the program
a token is a fixed length string of binary digits
variable names are loaded into a look-up table / symbol table
redundant characters (eg spaces) are removed
comments are removed
error diagnostics are given
prepares code for syntax analysis
[8]
5 (a) Interpreter
• Translates & runs one instruction at a time
• Reports errors as they are detected
• Stops when an error is found
• Useful for program development
• Programs run slowly/programs translated each time they are run
• Allows program to restart from any point
• User can step through program
• Interpreter needs to be present in memory in order to run a program.
Compiler
• Translates whole program as a unit
• May report a number of errors together
• Many errors may be spurious
• Useful for program distribution (to retain copyright/prevent changes)
• Executable program runs quickly
• Produces object code/executable program/translation done once
• Compiler does not need to be present once code is translated.
(Max 4 per type)
[max 6]
(b)
• Lexical analysis (1)
• Syntax analysis (1)
[max 2]
(c) Any two points from:
• Produces a machine code program…
• … which is equivalent to the source program
• Several machine code instructions for each high level language instruction.
[max 2]
(d) Any two points from:
• Code is improved…
• … redundant code is removed …
• … to make the program run as fast as possible (runs efficiently)
• … to make the program use as little memory as possible
• Compiler decides whether to optimise for size or speed.
[max 2]
6 (a) (i) The keyword table contains:
all the language keywords/reserved words + with a matching token [1]
[Total: 8]
7 (a) (i) translator [1] Accept compiler / assembler
(b)
Lexical Syntax Code Not during
analysis analysis generation compilation
Optimisation occurs
Logical errors are detected
Tokens are created
Spaces are removed
Comments are removed
Incorrect punctuation is detected