(This is the older material - click here - for current specification content)

4. Features of a compiler (1)

Handling errors

No one can write perfect code in one fell swoop for a non-trivial program. People make mistakes.

And so a compiler has to handle these mistakes and let the programmer know what has gone wrong.

Each computer language has its own grammar. For example it might insist that each line is ended with a semi-colon. Like this:

PRINT FILE;

If the programmer fails to include this semi-colon, then the compiler will spot the error.

Another very common error is trying to put a quart in a pint pot. In computer terms this is trying to put a number into a variable that cannot store that number. For example a byte can only hold values up to 255 decimal (a byte only has 8 bits). A broken piece of code is shown below:

Define x As Byte
x = 10,000,000

The compiler spots that x is a byte and yet the programmer is trying to stuff ten million into it. This kind of error checking is called 'type checking'.

A compiler is able to run through the translation process, spotting mistakes in the source code. Then it reports all the errors it has found in the form of a report.

The programmer then goes back to the source code and fixes the problems. Eventually the code will run error-free and be translated into an executable file.

 

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: Compiler error reporting

 

 

Copyright © www.teach-ict.com