6 stages of high level code completion
Slides in this set (8)
-
Stages of complation for high level code
- First off there are 6 stages to Compilation
- 1. Lexical Analysis
- 2. Symbol Table Construction
- 3. Syntax Analysis
- 4. Semantic Analysis
- 5. Code Generation
- 6. Optimisation
-
- �Comments and unneeded spaces are removed.
- �Keywords, constants and identifiers are replaced by ‘tokens’.
- �Examples of keywords that would be replaced:
- �if
- �while
- �for
-
- �A symbol table is created to hold variable addresses, labels and subroutines.
- Examples
-
- Tokens are checked to see of they match the rules (or syntax) for the language used.
- Examples:
- �does every open bracket have a close bracket?
- �Does an if command end with a colon?
- �If syntax errors are found, error messages are produced.
-
- Variables are checked to see if they are properly declared and used.
- Variables are checked to ensure they are of the correct data type.
- Operators are checked to ensure they are legal.
- Examples:
- �5/3 can not be stored as an integer
- �"cabbage"+3 can not be evaluated
-
- If any of these steps detects a problem, a syntax error is produced.
- A syntax error is an error that prevents the code compiling – it is caused by something in the code that is not valid for that programming language
- Examples:
- �Missing semicolon
- �Mismatched brackets or quotes
- �An invalid operator (=> instead of >=)
- �Comma used instead of dot
- Task: During which stage of compilation would each of the above syntax errors be identified
-
- �Provided there have been no syntax errors produced, the machine code is now generated
- �Complex algorithms are used to create machine code instructions that perform the same task as the high level code.
-
- �The generated code is scanned for repetitions or known inefficiencies that can be replaced with loops or more efficient code
- �This step is a big factor in the quality and expense of a compiler. A good compiler will produce better, more efficient machine code than a poor one.
Information
- Description
- these are the 6 high level code stages for completion
- Created by
- Ethan Long
- Views
- 3
- Rating