Stages of compilation (lexical analysis, syntax analysis, code generation and optimisation)
1.2.2 Applications Generation
Practise exam questionsApplications Generation — Note 5 of 6
Candidates need to understand that there are a number of stages involved in compilation. Candidates need to understand how lexical analysis works and how the code is converted into tokens with the removal of unnecessary elements (e.g. comments and whitespace). Candidates need to understand how syntax errors are identified and reported at the end of the syntax analysis. Candidates need to understand how the abstract syntax tree will be fed into the next stage of code generation, and that the object code is then created. Candidates need to understand why optimisation is important and how the results of lexical analysis feeds into syntax analysis, and how the tokens are checked to ensure they meet during (and after) code generation.
A compiler translates source code in several stages. Each stage takes the output of the previous one, gradually turning human-readable code into efficient machine code and reporting errors along the way.
Exam tipCommon mistake
The smallest meaningful unit of code, e.g. while, count, <=, 10.
A table of the identifiers (variables, subroutines) in the program with information such as data type, scope and memory address.
Source: total = total + price // add price
Tokens: <identifier: total> <operator: => <identifier: total>
<operator: +> <identifier: price>
Comment and whitespace removed; 'total' and 'price'
are added to the symbol table.Ready to test yourself?
Practise 1.2.2 questions