1.2.2.6 Stages of Compilation
No description yet. This curated deck is ready for daily study.
Card preview (6)
What are the 4 stages of compilation?
1) Lexical analysis 2) Syntax analysis 3) Code generation 4) Code optimisation
What happens in the lexical analysis stage?
• The Lexer starts by converting lexemes from the source code into a series of tokens • Scanned spaces, symbols are taken as indicators that word is complete • It then checks if the lexeme is valid using a predefined set of rules that allow every lexeme to be identified as a valid token
What can be considered a token?
Keywords, constants, identifiers, strings, numbers, operators and punctuation symbols
What happens in the syntax analysis stage?
• Receives its inputs in the form of tokens from lexical analysers. • Analyses the syntactical structure of the input, checking if it is in the correct syntax of the programming language it has been written in. • It does this by analysing the token stream against production rules to detect any errors in the code
What does the syntax analysis accomplish?
• Checking for errors and reporting them. • Building an abstract syntax tree (parse tree)
What does code optimisation do?
• Spotting redundant instructions and producing object code that achieves the same effect as the source program but not necessarily by the same means. • Removing subroutines that are never called. • Removing variables and constants that are never referenced.