Please enable JavaScript.
Coggle requires JavaScript to display documents.
Unit 8- Program Construction, Translation and Execution Errors - Coggle…
Unit 8- Program Construction
Translators
Computers can only run binary machine code, programs written in other languages require conversion
The term translators covers software that converts code from form to form, these are compilers, interpreters and assemblers
Assemblers
Assembly language is almost in a form that the CPU can understand, but it needs some slight alterations to be understood
Assemblers converts assembly code into an understandable form
Converts instructions into opcode and operands
Opcode mean Operation Code, it's a single instruction that the CPU executes
In machine language it's a hex or binary code like h6, in assembly an opcode is something like MOV or ADD
Operands are manipulated by the opcode.
Compilers
Translates source code into machine code
Creates executable files for later use
The four main stages
Lexical Analysis
Syntax Analysis
Semantic Analysis
Code generation
Optimisation possibly employed to improve run speed
Machine code generated
Variables checked
Make sure they're used properly and declared
Checked they're the correct data type
Operations checked to ensure they're allowed with the type of variable
Tokens checked to see if they're grammatically correct, each token checked to determine if correct syntax is used for the language
If errors are found then messages are sent
Removes unneeded space and comments
Keywords replaced with 'tokens'
Symbol table created to hold addresses of variables
Advantages
Faster than interpreted program as it has checked everywhere for errors
File can be saved and run as many times without need for recompiling
Checks all code, not just what's being run
Can't be listed or altered so ownership is protected
Compilers can be more complex to code than interpreters
Interpreters
Analyses statement by statement whilst being executed whilst interpreting and carrying out instructions
Advantages
Use less storage
Less complex hence they're cheaper
Only checks code being used, untested code may have errors
Translation and Execution Errors
Syntax
Occurs when command doesn't follow syntax of the language
Runtime/execution
Only occurs program is running and is difficult to forsee
Logical
Causes an incorrect answer although the program runs fine, you made the mistake
Linking
Occurs when a function is called but the correct library isn't linked
Rounding
When a number is approximated to the nearest whole
Truncation
When a number is approximated to a whole near 0, eg 4.9 to 4 (error of -0,9)