1/9
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What stages does a compiler go through to convert source code to object code?
Lexical analysis
Symbol table
Syntax analysis
Semantic analysis
Code generation
What happens during lexical analysis?
- All unnecessary spaces and comments are removed
- Keywords (e.g. print), constants and identifiers are replaced with tokens representing their function in the program
What is a lexer?
builds up a symbol table for every keyword and identifier in a program
What is the symbol table?
helps to keep track of the run-time memory address for each identifier
What are the token classes?
Identifier:Any function or variable name
Keyword:As If Else EndIf Function EndFunction Return
Separator:( ) &
Operator:+ - * / % ^ DIV MOD < <= > >=
Literal:Hello world
Number: -4 0 3.4
Quote: " "
Bool: True False
Datatype: Integer Decimal String Boolean
What is syntax analysis?
The process of splitting the stream of tokens into phrases, parsing them and recording the error if they are invalid
-If the phrase is not valid, an error will be recorded
What is semantic analysis?
Checks if syntactically correct statements are logically correct and can actually work in the program
What is code generation?
- Once the program has been checked, the compiler generates the machine code
- It may do this in several 'passes' over the code because code optimisation will also take place
What is code optimisation?
Tweaking the code so it will run as efficiently as possible.
This might mean optimising the speed of execution or optimising for using as little memory as possible.
What are disadvantages of code optimisation?
- It will increase compilation time, sometimes quite
considerably
- it may sometimes produce unexpected results.