AS13 Flashcards
1
Q
Compiler
A
- Converts high level language into machine code.
- A stand alone executable file is produced and the original source code is hidden.
2
Q
Source Code
A
- Source code is compiled for a particular processor e.g. code compiled for Windows 10 wont run on Mac OS X.
3
Q
Compiling Phases
A
- Lexical analysis
- Syntax analysis
- Generating machine code
- Optimization
4
Q
Lexical Analysis
A
- First phase of compilation.
- Converts high-level code into a sequence of tokens.
- Converts code symbol by symbol.
- A symbol table is created to record the link between the token and its original meaning. Whitespace is not used here.
- Tokens are language or user defined.
- The output is the sequence of tokens is sent to the parser for syntax analysis.
- Invalid symbols are reported to the programmer via error diagnostics.
5
Q
Regular Expression
A
- What an acceptable pattern for a particular type of symbol is.
6
Q
Syntax Analysis
A
- Ensures that the tokens are in an acceptable sequence.
- A syntax error occurs when tokens passed to the compiler do not match any rule stored in the compiler.
- When the program has no syntax errors, the compiler constructs an abstract syntax tree that can be checked and passed on to the next phase of compiling. This is an unambiguous data structure used to represent the arrangement of symbols in the program.
7
Q
Semantic Analysis
A
- Tries to derive meaning from the code.
- Type checking ensures that data will be processed correctly in accordance with its type rules.
8
Q
Machine Code Generation
A
- The compiler can now say that no syntax errors exist.
- Code is now converted into machine code.
- Converts elements of abstract syntax tree into machine code, allocates registers to minimise memory access, optimises machine code.
- Pre-existing blocks of code are used to convert familiar abstract tree structures into machine code blocks. This is done repeatedly until all subtrees converted.
9
Q
General Purpose Registers
A
- Store values while the program runs.
- Must continually be allocated and deallocated.
10
Q
Optimisation
A
- High level languages impose barriers to development of efficient code. Compilers fix this.
- Jumps/Branches carry a speed penalty, compilers code by copying and pasting procedures inline with the program.
- Registers are allocated/deallocated.
- Dead code (code with no outcome effect) is eliminated.
- Compilers can extend the CPU’s functionality if it is aware it can do so. Only possible on particular CPUs.