Vous êtes sur la page 1sur 16

1

(a)

(i)

Describe the purpose of a compiler.

 

[2]

 

(ii)

Explain the difference between a compiler and an interpreter.

 

[1]

 

(b)

Describe syntax analysis.

 

[2]

 

(c)

Describe the purpose of a linker.

 

[3]

2

(a)

State what is meant by the following terms:

(i)

object code

 

[1]

(ii)

source

 

[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]

(c)

When a program is written it may contain errors. Describe what is meant by each of the following types of error, giving an example of each.

(i)

Syntax error

 

[1]

 

Example

 

[1]

 

(ii)

Logic error

 

[1]

 

Example

 

[1]

3

(a)

Explain the purpose of a compiler.

 

[2]

(b)

Describe what happens during syntax analysis.

 

[4]

(c)

Instead of a compiler, an interpreter may be used during program development.

Explain how errors are handled by using an interpreter.

 

[4]

4

(a)

Languages used in computing include assembly language and machine code.

 

(i)

Describe the term assembly language.

 

[2]

 

(ii)

Describe the term machine code.

 

[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.

(i)

Describe one feature of an interpreter.

 

[2]

 

(ii)

State two features of a compiler.

 

[2]

(c)

One stage of compilation is lexical analysis.

Describe what happens during 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]

(b)

State the first two stages of compilation.

 

[2]

(c)

The third stage of compilation is code generation. Describe this stage.

 

[2]

(d)

Explain the term optimisation.

 

[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.

// program written 12 June 2013 Declare IsFound : Boolean; Declare NoOfChildren : Integer; Declare Count : Integer; Constant TaxRate = 15;

// start of main program For Count = 1 To 50

(a) During the lexical analysis stage the compiler will use a keyword table and a symbol table.

(i)

Describe what information is contained in these tables.

 

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.

(i)

Explain what is meant by 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.

(i)

Name this type of software.

 

[1]

(ii)

Explain the term source code.

 

[4]

(b) Complete the table with ticks to show at which stage, if any, events occur when a compiler is used.

 

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

       

[6]

8

Various types of translator may be used when writing and preparing a new computer program.

(a)

Explain the main purpose of a translator.

 
 

[2]

(b)

Some compilers produce intermediate code instead of executable code.

(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]

 

(iii)

State one disadvantage of using intermediate code.

 

[1]

(c)

When a compiler is used to produce executable code, code generation includes optimisation.

Describe what optimisation does.

[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]

 

(b)

-The computer cannot process the instructions -The computer needs the instructions in binary form/object/machine code (which the programmer cannot understand) -The translator creates the binary form from the HLL form.

 

(1 per -, max 2)

 

[2]

 

(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

4 (a)

(b)

(c)

(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]

(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]

(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]

 

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]

The symbol table stores:

each identifier/variable found (and its data type)

the values of all constants

the upper and lower bounds of arrays

[1]

[1]

[1]

[Mark as: 1 + 1] [MAX 2]

 

(ii)

Keywords are looked up in the keyword table

[1]

 

Keywords are converted to tokens

[1]

Identifiers/Variables are looked up in the symbol table

[1]

Identifiers/variables are converted to actual addresses

[1]

 

[MAX 2]

 

(iii)

The white space // redundant characters are removed

[1]

 

Illegal identifier names are identified

[1]

 

[MAX 1]

(b)

(i)

Optimising

 

Code will execute/run/process faster

[1]

Code requires less memory Reduce the amount of code

[1]

R. ‘more efficient’ // removes redundant code

 

(ii)

Any example where the code could be changed E.g. input of a list of number to compute the total (There would be no need to store the numbers first)

[1]

[Total: 8]

compiler / assembler7

during

compilation

errors are detected Logical

Not

generation

Optimisation

Code

Accept

[max 4]

analysis

[1]

punctuation is detected Incorrect

Syntax

the original code/code written by the programmer …often in a high level language may be in assembly language source code can be understood by people… …but cannot be executed (until translated)

analysis

are removed Comments

are created Tokens

are removed Spaces

Lexical

[1 mark per correct row, max 6]

occurs

translator



(ii)

(i)

(b)

(a)

[Max 2]

[Max 2]

[Max 2]

[1]

[1]

(iii) the program runs more slowly/has to be translated each(b)

can run on a variety of computers same intermediate code can be obtained from

makes code as efficient as possible

time it is run / need additional software

of instructions

level languages

in source code

speed

convert from source code

interpreter / virtual machine(ii)

processing

portability

increases number

errors code

improves high

…to object

different

reduces

detect

(i)

(a)

(b)

(c)

2