1.2.2 Application Generation - Stages of compilation Flashcards
What is a lexicon
A lexicon is a general term meaning a collection of terms related to a specific subject.
In computer language this is the use of ‘=’, ‘if’ or other command words/keywords. These terms are lexemes.
What does the compiler break source code down into?
The compiler breaks down the ASCII characters that the source code is made up of into component parts called ‘lexemes’.
What is a lexeme?
A lexeme is the smallest unit of language, it cannot be broken down further without losing meaning.
What are the stages of compilation?
Lexical analysis - the splitting down of the ASCII code into lexemes
Draft token table - lexemes are converted into tokens, both these and notes on what each token does is stored in a token table.
Syntax analysis - the checking of whether the tokens make sense in the grammar of the language and if tokens are the expected data type.
Code generation - the conversion of source code via the output of lexical and syntactic analysis into machine code.
What are some characters or combinations of characters ignored by lexical analysis?
Comments, tabs and whitespace are removed from the source code during lexical analysis.
What is a token?
A token is a fixed length binary number - lexemes are converted into tokens as the CPU works more efficiently when data chunks are standard sizes.
Where are all the tokens created stored?
After lexical analysis - the whole source code will have been converted by the compiler into a token table in memory.
As the compiler finds lexemes during lexical analysis, what does it do?
As the compiler finds lexemes it converts them into tokens and notes what each token does.
What do token tables store?
Tokens and notes on what each token does alongside them.
What is syntactic analysis?
Syntactic analysis includes syntax analysis and semantic analysis. This is where the compiler checks that the code makes sense.
What is syntax analysis (parsing)?
During syntax analysis, the compiler checks that the arrangement of the tokens make sense in the grammar of the language.
What is semantic analysis?
During semantic analysis, the compiler checks that the tokens are the expected data types.
What happens if an error is detected during syntactic analysis (parsing)?
During syntactic analysis, if an error is detected it is added to the ‘compiler report’. Once the compiler has finished analysing the code, the complete report is returned to the programmer.
What is code generation?
Code generation is the final stage of compilation. It converts source code via the output of lexical and syntactic analysis into machine code. The result is stored as an object file.
What is the result of code generation stored as?
The result of code generation is stored as an object file.