Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Reinforcement: 05-10 Years' relevant CIE answers.

Section 3.2

Past Papers Answers:

Section 3.2: The Functions and Purposes of Translators


May/June 2000
Oct/NOV 2000
May/June 2001
Oct/NOV 2001
May/June 2002
Oct/NOV 2002

May/June 2003
1. (a) The sequence will have to be interpreted 2000 times/this will include all
stages, such as checking
Compiled version needs no further translation (2)
(b) Removes spaces/white space/tabs
Removes comments
Checked validity of reserved words
Tokenises reserved words
Tokenises operators
Checks validity of symbols/variable names
Creates the symbol table
(1 each, max 4) (4)

Oct/NOV 2003
3. (a) - Whole program not written
- so may not compile
- Testing needs to be done
- diagnostics will be more complete
- individual segments can be run
- allowing errors to be isolated
- running will be necessary after very minor changes
- continual compilation of whole code is wasteful/time consuming
(1 per -, max 5) (5)
(b) - Check on grammar of statements
- Error diagnostics are issued
- Jump destinations checked for existence
- Control constructs checked
- Check that variables have been declared
- Check for existence of library modules
(1 per -, max 3) (3)

http://sites.google.com/site/computing9691/
Page 1 of 11
Reinforcement: 05-10 Years' relevant CIE answers.
Section 3.2

May/June 2004
4. (Tokens) are analysed to check for grammatical correctness (form valid
sentences)
(Code)/reserved word checked against rules
Invalid number of brackets found
Determine priorities of arithmetic operators in an expression
Produce intermediate code
Diagnostic error messages are reported
Label checks
Flow of control checks
Declaration checks (1 per point, max 5) (5)
Oct/NOV 2004
4. Program is in modular form in machine code
The individual modules must be loaded by the loader into the computer’s memory
Loader decides where modules are to be placed
Memory addresses adjusted by loader
Use of loader to load library routines
Linker links the modules correctly
Calculates addresses of the separate modules
Allows library routines to be linked to several programs
(1 per point, max 6) (6)
May/June 2005
6. (a) -Interpreter translates line of code and then runs it
-Compiler translates entire program before run.
-Compiler creates an object code
-Interpreter retains source code.
-Compiler must be present for translation
-Interpreter must be present for run
(1 per -, max 2, must include one for each of interpreter and compiler) (2)
(b) -Creates a stream of tokens…
-each group of characters is replaced by a token
-Symbol table created…
-accessed by hashing algorithm
-which initially stores just the variable names
-Redundant characters removed…
-white spaces/tabs/comments…
-(Some) error diagnostics created…
-e.g. illegal variable names.
(1 per -, max 5) (5)
(c) -Address of variables calculated
-and stored in symbol table
-Intermediate code produced…
-which can then be turned into executable code/machine code
-Code optimized…
-which involves using rules to make code as small/efficient as possible.
(1 per -, max 2 pairs, max 4) (4)

http://sites.google.com/site/computing9691/
Page 2 of 11
Reinforcement: 05-10 Years' relevant CIE answers.
Section 3.2

9. -Some simulations are time sensitive


-and require large amounts of processing
-where processes are interrelated
-calculations can be done at same time which speeds up processing
-e.g. weather forecasting
(1 per -, max 4) (4)

Oct/NOV 2005
5. (c) -Programs may be in modular form
(i) -Calculates the address of the individual module
-Ensures jump instruction from module to module properly addressed
(ii) -Decides whereabouts to place program/modules in memory
-Adjusts memory addresses according to where placed
-Copies program from store to memory
(1 per -, max 4) [4]
May/June 2006
1. (a) - the computer only understands binary
- HLL is written in language close to human language
- translator needed to turn one into the other
(1 per -, max 2) [2]
(b) - interpreter translates one line of code and runs it
- before translating the next line
- original code is always present
- compiler translates entire code
- before allowing it to be run
- creates object code
(1 per -, max 4) [4]
(c) (i) - translator program maintains a dictionary of reserved words
- if the reserved word used is not in this dictionary then an error has been made
- message may be given which suggests one close to spelling provided
(ii) - variable names must follow the rules of the language
- translator tries the rules against the names used and reports any errors
- contents of variables must be of a specific type
- error created by the attempted use of anything else.
(1 per -, max 4) [4]

Oct/NOV 2006
4. (a) -the production of a machine code program/intermediate code which…
-will produce the results intended by the source code
-optimisation reduces the size of the object code by…
-removing any duplicate or redundant instructions…
-which improves speed of execution
(1 per -, max 3) (3)
(b) (i) -linkers join together (compiled) modules of code
-to produce an executable file
-needs to match up address references between modules
(ii) -takes a set of code from storage and copies it into memory
-needs to resolve problems with addresses
-mention of linking loader (1 per -, max 2 per section, max 4) (4)
http://sites.google.com/site/computing9691/
Page 3 of 11
Reinforcement: 05-10 Years' relevant CIE answers.
Section 3.2

May/June 2007
6. (c) - Interpreter translates one command at a time and runs it before the next is
translated.
- Used during writing because it aids debugging
- (Compiler translates whole program) into object code (before running)
- Runs faster once it has been called/may be held as a library routine.
(1 per -, max 4) [4]
(d) - Decides where to place programs and procedures
- Loads program and procedures into memory
- Adjusts memory addresses to match locations used
(1 per -, max 2) [2]

Oct/NOV 2007
7. – Characters in the variable name are tokenised
– Variable name is added to symbol table…
– during lexical analysis
– Data type added…
– scope is added/block(s) in which variable is valid
– during syntax analysis
– Variable names which do not match the rules are reported in error diagnostics
– Statements containing variables are checked for syntax
– Position in table is hashed from the name
– Variable declarations are checked/also variable use
– Address of variable calculated…
– added to symbol table…
– during code generation
(1 per –, max 6) [6]

May/June 2008
9. (a) -Reserved word is isolated...
-if not in list of reserved words (then error)
-(If reserved word identified then syntax table) checked for expected form of
statement...
-matched to statement provided and error issued if different
-Variable names checked against rules for variable names
-Check for variable declarations
(1 per -, max 4) [4]
(b) -All errors due to incorrect use of language have been corrected
-When variables are first met in code generation, an address is assigned to them
-Intermediate code is produced
-Machine code/executable code produced (from intermediate code)
-Optimisation of code carried out
(1 per -, max 4) [4]

http://sites.google.com/site/computing9691/
Page 4 of 11
Reinforcement: 05-10 Years' relevant CIE answers.
Section 3.2

Oct/NOV 2008
2. (a) (i) – Code written in a high level language
(ii) – Code in machine code/result of source code being
(compiled)/executable code/binary [2]
(b) – Compiler produces object code/object code must exist before
code is run/error diagnostics reported for entire source code
– Interpreter does not produce object code of program/only
produces m.c. of each statement/error diagnostics reported as
error is met [2]
(c) (i) – Makes the run of the program more efficient (faster)/runs
without the presence of the compiler/because no further
translation needs to be done
– Makes the software more secure/cannot be altered because source
code not present
(ii) – When writing a program/gives better diagnostics/will run
despite not being complete (Up to 2 per –, max 1 – per dotty,
max4) [4]

May/June 2009
2. (d) (i) -Used to combine already compiled procedures
-with compiled program…
-to create an executable file.
-Deals with external references.
(ii) -Copies object code into…
-(primary) memory ready for execution.
-Deals with addressing anomalies,
-particularly relocatable addressing
(1 per -, max 2 per dotty, max 4) [4]

Oct/NOV 2009. P31


6. Lexical:
-Instructions are tokenised
-Some of characters must be combined to create token for keyword
-If keyword does not exist in internal dictionary of keywords
-check for valid variable name
-against rules stated in BNF
-Error is reported
Syntax:
-Each keyword has an associated syntax
-Tokens are checked to ensure that they match the syntax for that keyword.
- e.g. Do left and right brackets match?/Does punctuation for Print keyword match
rules?/…
-error is reported (only credit once)
(1 per -, max 5) [5]

http://sites.google.com/site/computing9691/
Page 5 of 11
Reinforcement: 05-10 Years' relevant CIE answers.
Section 3.2

Oct/NOV 2009. P32


4. (a) – Instructions are either in machine code
– or they are one to one with machine code
– Using mnemonic codes for operations
– Using labels for addresses of data
– Used for controlling the computer/close to hardware
– Allows direct manipulation of memory addresses
– Contains a code for the operation to be carried out...
– and a binary representation of the value to be manipulated/address of the value
to be manipulated.
– Different forms of addressing mentioned.
– Different forms of instruction: Arithmetic/Jump/Control
(1 per –, max 5) [5]

Oct/NOV 2009. P33


6. Lexical:
-Instructions are tokenised
-Some of characters must be combined to create token for keyword
-If keyword does not exist in internal dictionary of keywords
-check for valid variable name
-against rules stated in BNF
-Error is reported
Syntax:
-Each keyword has an associated syntax
-Tokens are checked to ensure that they match the syntax for that keyword.
- e.g. Do left and right brackets match?/Does punctuation for Print keyword match
rules?/…
-error is reported (only credit once)
(1 per -, max 5) [5]

May/June 2010. P31


May/June 2010. P32
1. (a) -Interpreter translates one command and runs it before translating the next
-Compiler translates whole program before it is run
-Interpreter maintains source code throughout run
-Compiler creates the object code and drops the source code
-Interpreter must be present in memory during program run
-Compiler no longer needed once object code created/can be removed
-Compiled program will be longer than source code
-Compiled program will tend to run more quickly
-because no further translation is required
(1 per -, max 6) [6]
(b) (i) Lexical analysis and Syntax analysis [2]
(ii) -Creates a machine-code program/object code...
-which is equivalent to the high level language program
-The code which is created will not be efficient
-Optimisation is used...
-to reduce the number of commands in the object code...
-by removing redundant code/substituting one command for several
(according to set rules) (1 per -, max 3) [3]
http://sites.google.com/site/computing9691/
Page 6 of 11
Reinforcement: 05-10 Years' relevant CIE answers.
Section 3.2

May/June 2010. P33


1. (a) -The lexical analysis stage is a preparation stage of the code/making it ready for
translation
-The syntax analysis stage is a checking stage to ensure that the code is suitable
for translation
-Some error reporting is carried out in both stages
Lexical analysis:
-Redundant characters are removed
-Small groups of characters are tokenised
-Keywords are given their own tokens
-Keywords are checked for validity
-Symbol table is created
Syntax analysis:
-Checks the tokens to ensure that strings of them form valid statements by…
-seeing if the rules of the language are followed
-An example e.g. Are brackets nested and are there the same number of left and
right brackets?
-Symbol table is filled in
(1 per -, max 6) [6]

(b) -Creates a machine code program...


-which is equivalent to the high level language program
-The code which is created will not be efficient
-Optimisation is used...
-to reduce the number of commands in the object code...
-by removing redundant code/substituting one command for several (according to
set rules)
(1 per -, max 3) [3]
(c) -Copies object code into…
-(primary) memory ready for execution
-Deals with addressing anomalies…
-Particularly relocatable addresses
(1 per -, max 2) [2]

Oct/NOV 2010. P31


4. (a) -Interpreter translates one instruction and runs it before translating the next.
-Compiler translates whole program before it is executed
-Interpreter maintains source code throughout run/program execution
-Compiler creates the object code and drops the source code
-Interpreter must be present in memory during run/program execution
-Compiler removed once object code produced
-Object code larger than source code
-Compiled program runs more quickly once it is translated
-interpreter produces error diagnostics as they are met
-compiler produces a file of error diagnostics at end of compilation
-interpreter makes debugging easier
-compiler needs whole program to be syntax error free to produce object code
-interpreter can execute partial programs
-compiler needs a whole block of code to run
http://sites.google.com/site/computing9691/
Page 7 of 11
Reinforcement: 05-10 Years' relevant CIE answers.
Section 3.2

(1 per -, max 6) [6]


(b) -Puts each statement into form required by the syntax analyser
-Keywords are tokenised
-If keyword not in dictionary then error reported
-Programmer-defined names entered into symbol table//symbol table created.
-names not following rules create error message
-Removes unnecessary characters
(1 per -, max 5) [5]

Oct/NOV 2010. P32


4. (a) -Interpreter translates one instruction and runs it before translating the next.
-Compiler translates whole program before it is executed
-Interpreter maintains source code throughout run/program execution
-Compiler creates the object code and drops the source code
-Interpreter must be present in memory during run/program execution
-Compiler removed once object code produced
-Object code larger than source code
-Compiled program runs more quickly once it is translated
-interpreter produces error diagnostics as they are met
-compiler produces a file of error diagnostics at end of compilation
-interpreter makes debugging easier
-compiler needs whole program to be syntax error free to produce object code
-interpreter can execute partial programs
-compiler needs a whole block of code to run
(1 per -, max 6) [6]
(b) -Puts each statement into form required by the syntax analyser
-Keywords are tokenised
-If keyword not in dictionary then error reported
-Programmer-defined names entered into symbol table//symbol table created.
-names not following rules create error message
-Removes unnecessary characters
(1 per -, max 5) [5]

Oct/NOV 2010. P33


4. (a) ‐ Whole program may not yet be written…
‐ …so the code would not compile
‐ Testing may need to be done during the writing of the code…
‐ …tags may be provided to allow code presently complete to be tested
‐ …diagnostics will be more complete/more immediate
‐ Code can be run from any point to any point/individual segments can be run for
testing purposes…
‐ …allowing errors to be isolated
‐ Running/testing will be desirable after minor changes
‐ Repeated compilation of the code will be wasteful/time consuming
(1 per ‐ , max 4) [4]

(b) ‐ Check on grammar of statements


‐ Checks the correct pairing of brackets/decides the priorities of the arithmetic
and logical operators
‐ Error diagnostics are issued
http://sites.google.com/site/computing9691/
Page 8 of 11
Reinforcement: 05-10 Years' relevant CIE answers.
Section 3.2

‐ Jump destinations are checked for existence


‐ Checks that variables have been declared
‐ Adds information to the dictionary of variables like the data type
‐ Check for existence of library modules
(1 per ‐ , max 3) [3]

(c) ‐ Addresses of variables calculated…


‐ …and stored in symbol table
‐ Intermediate code produced…
‐ …which can then be turned into executable code
‐ Routines called from system library…
‐ …for example a square root function called/embedded in code
‐ Code optimised...
‐ …which involves using rules to make code as small/efficient as possible
(1 per ‐ , max 2 pairs of marks, max 4) [4]

May/June 2011. P31


2. (a) -One to one
-Mnemonics are used to represent operation codes
-Labels are used to represent memory addresses
-machine code is binary codes (only)
-assembly code cannot be executed // machine code can be executed
-machine code and assembly language are both low level languages (machine
specific)
(1 per -, max 2) [2]
(b) -Labels added to a symbol table
-Labels are later looked up to determine the actual address / Assembler must
allocate addresses to labels
-Mnemonic looked up in opcode table to find operation code
-Macro instructions used to stand for groups of instructions
(1 per -, max 2) [2]
11. (a) -Interpreter translates one instruction, runs it before going on to the next //
Compiler translates all the instructions before run.
-Compiler creates object code/executable file // Interpreter does not
-Interpreter makes for easier debugging
-Compiled programs will execute faster // interpreted code will execute slower
-Interpreter must be present to run the program // compiler not needed at runtime
-Interpreter will translate code in loops more than once // Compiler only once
-once compiled no further translation needed // every program execution requires
interpreter
(1 per -, max 3) [3]

May/June 2011. P32


2. (a) -One to one
-Mnemonics are used to represent operation codes
-Labels are used to represent memory addresses
-machine code is binary codes (only)
-assembly code cannot be executed // machine code can be executed

http://sites.google.com/site/computing9691/
Page 9 of 11
Reinforcement: 05-10 Years' relevant CIE answers.
Section 3.2

-machine code and assembly language are both low level languages (machine
specific) (1 per -, max 2) [2]
(b) -Labels added to a symbol table
-Labels are later looked up to determine the actual address / Assembler must
allocate addresses to labels
-Mnemonic looked up in opcode table to find operation code
-Macro instructions used to stand for groups of instructions
(1 per -, max 2) [2]
11 (a) -Interpreter translates one instruction, runs it before going on to the next //
Compiler translates all the instructions before run.
-Compiler creates object code/executable file // Interpreter does not
-Interpreter makes for easier debugging
-Compiled programs will execute faster // interpreted code will execute slower
-Interpreter must be present to run the program // compiler not needed at runtime
-Interpreter will translate code in loops more than once // Compiler only once
-once compiled no further translation needed // every program execution requires
interpreter
(1 per -, max 3) [3]

May/June 2011. P33


2. (a) (i) -Used to combine already compiled procedures…
-to produce an executable file
-Deals with external references from the main program to other (pre-
compiled) modules
(ii) -Copies object code/executable code into…
-primary memory ready for execution
-Deals with addressing anomalies/re-locatable addresses
(1 per -, max 4) [4]
(b) (i) -Address in instruction is the address of the address of the location...
-which contains the data/instruction to be used
-Allows complete change in program by changing indirect address to
point to a different subroutine // allows greater range of memory to be
addressed/by example [3]
(ii) -Address in the instruction is added to
-the contents of the IR...
-which can then be incremented to allow access to a sequence of
locations//
Allows the contents of an array to be accessed sequentially by successive instructions //
used to access a contiguous block of memory [3]
11. (a) -Interpreter translates one instruction, runs it before going on to the next //
Compiler translates all the instructions before run.
-Compiler creates object code/Interpreter does not
-Interpreter will translate code in loops more than once/Compiler only once
-Interpreter makes for easier debugging/Compiler allows faster execution
translated code
-Interpreter must be present to run the program // compiler not needed at runtime
(1 per -, max 3) [3]

http://sites.google.com/site/computing9691/
Page 10 of 11
Reinforcement: 05-10 Years' relevant CIE answers.
Section 3.2

Oct/NOV 2011. P31


Oct/NOV 2011. P32
Oct/NOV 2011. P33
May/June 2012. P31
May/June 2012. P32
May/June 2012. P33

http://sites.google.com/site/computing9691/
Page 11 of 11

You might also like