Program construction #8 Flashcards
what are assemblers
Program which converts the low-level assembly programming language into machine code. done by converting the one-word assembly instructions into an opcode, e.g. converting AND to 0010. it also allocates memory to variables, often resulting in an operand.
what are interpreters
Code is converted by an interpreter before high level programming languages can be run. one line at a time, into machine code, which is then executed by the CPU.
what are compilers
used when high level programming languages are converted into machine code, ready to be executed by the CPU. There are four main stages of compilation
-lexical analysis
-syntax analysis
-semantic analysis
-code generation
What are the 4 main stages of compilation ?
- Lexical analysis
- Syntax analysis
- Semantic analysis
- Code generation
ofc i repeated this dnc
what is lexical analysis (stage of compilation)
-comments and unneeded spaces are removed
-keywords, constants and identifiers are replaced by ‘tokens’
-a symbol table is created which holds the addresses of variables, labels and subroutines
what is syntax analysis (stage of compilation)
-tokens are checked to see if they match the spelling and grammar expected, using standard language definitions, this is done by parsing each token to determine if it uses the correct syntax for the programming language.
-if syntax errors are found, error messages are produced
what is semantic analysis (stage of compilation)
-variables are checked to ensure they have been properly declared and used
-variables are checked to ensure they are of the correct data type, e.g. real values are not being assigned to integers
-operations are checked to ensure they are legal for the type of variable being used, e.g. you would not try to store the result of a division operation as an integer
what is code generation (stage of compilation)
-machine code is generated
-code optimisation may be employed to make it more efficient/faster/less recourse intense
what are examples of 6 programming errors
-syntax
-logical
-linking
-rounding
-truncation
-runtime/execution
what is a syntax error
occurs when command doesnt follow expected syntax of the language, e.g. when a keyword is incorrectly spelt
what is runtime/execution error
only occurs when program is running and is difficult to foresee before a program is compiled and run
what is logical error
causes program to output an incorrect answer, e.g. an algorithm that calculates a perrons age from their date of birth but ends up giving negative numbers.
what is a linking error
occurs when programmer calls a function within a program and the correct library has not been linked to that program
what is rounding error
when number is approximated to nearest whole number/tenth/hundredth, etc.
what is truncation error
when a number is approximated to a whole number/tenth/hundredth, etc. nearer zero.