1/14
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Order of compilation stages
Lexical
Syntax
Code generation
Code optimisation
Tasks of syntax compilation stage
Constructing a parse tree
Checking that rules of grammar/language has been obeyed
Production of an error report
Reasons for optimisation of code
Minimises amount of memory used
Minimises execution time
Explain how an interpreter executes a program without producing a complete translate version of it
Examines source code one statement at a time
Checks each statement for errors
If no error is found the statement is executed
If an error is found this is reported and the interpreter halts
Interpretation is repeated for every iteration in repeated sections of code
Interpretation has to be repeated every time the program is run
Lexical analysis description
Converting a sequence of characters into a sequence of tokens
Syntax analysis description
Using parsing algorithms to interpret the meaning of a sequence of tokens
Code generation description
Converting an intermediate representation of source code into an executable form
Optimisation description
Minimising a program’s execution time and memory requirement
Purpose of syntax analysis
Checks that the code matches the grammar of the language
Syntax errors are reported
A parse tree is produced
Process of executing a program using an interpreter
The interpreter translates the source code one line at a time
If the line is syntax error free, it is executed
It is not stored in an executable format
If an error is found, the program halts with an error message
Each line must be translated every time it is run (including lines running multiple times, like loops)
Lexical analysis during program compilation
First stage of compilation
White space and comments are removed
Takes modified source code and converts it into a series of tokens
Each token is categorised and assigned type
Identifiers are stored in a table
If it finds invalid tokens, it generates an error
Acceptable data then passes to the syntax analyser
Syntax analysis during program compilation
Second stage of compilation
Takes input from the lexical analyser in the form of token streams
Uses parsing algorithms to interpret the meaning of a sequence of tokens
Source code is analysed / Checking that the rules of the grammar have been obeyed
Output from phase is a parse tree
Syntax errors are reported here
Purpose of lexical analysis during compilation of a program
Convert high-level source code
That can be sent to the parser for syntax analysis
To create a symbol(token) table
To remove unnecessary white space and comments from the code
Purpose of optimisation stage in compilation of a program
Minimising program storage
Minimising CPU time
Minimising memory use
Minimising program execution time
Process of optimisation during compilation of a program
To identify and remove redundant code // to simplify expressions // To reorder the code
So that storage size, memory use, power consumption, program execution time and CPU time is minimised