SLR 5 Flashcards
(46 cards)
Define library
Ready compiled and tested programs that can be run when needed
Library features
Typically grouped together into software libraries
Most programming languages have extensive libraries of pre built functions
Library pros
Quick and easy to use and hook into your own code
Pre tested, so you can be relatively sure they are already free from errors
Pre compiled so they are typically optimised to run quickly
Library cons
Adding functionality or making specific tweaks can be difficult- or impossible
Sometimes you are “black boxed” from the actual implementation
Have to trust that the developers will continue to maintain the library
Linker responsibility
Linker is responsible for putting the appropriate machine addresses in all the external call and return instructions so all modules and external library routines are linked together correctly
Static linking
All the required code from the libraries is included directly in finished machine code- this can result in large executable program files
Dynamic linking
Compiled versions of the required libraries are stored on the host computer
Operating systems links required code from library as the program is running
While this cuts down on the size of compiled machine code, if dynamic libraries change, the program may stop because it tries to call a subroutine in the wrong way
Define loader
The part of the operating system that loads the executable program file into memory, ready to be run
Loader for dynamic linking
When using dynamic linking, it will also be responsible for loading the required libraries into memory
What are the stages of compilation
Stage 1: lexical analysis
Stage 2: syntax analysis
Stage 3: code generation
Stage 4: optimisation
What happens during lexical analysis
Lexer starts by converting lexemes in the source code into a series of tokens
As the leder reads the source code, it scans the code letter by letter
When it encounters a white space, operator symbol or special symbol it decides a word (lexeme) 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 happens during syntax analysis
It receives its inputs in the form of tokens from lexical analysers
It analyses the syntactical structure of the input, checking if in correct syntax of programming language
Does this by analysing the token stream against production rules to detect any errors in the code:
- checking for errors and reporting them
- building an abstract syntax tree
Lexer can’t tell if tokens valid by syntax analyser can
If the check fails, the syntax analyser can report the failure to user letting them know exact line and location of error
The abstract syntax tree is created from the input token streams
What happens during code generation and optimisation
Machine code is generated
Code optimisation (can increase compilation time for a program) attempts to reduce the execution time of the program by:
- spotting redundant instructions and producing object code that achieves the same effect as the source code
- removing subroutines that are never called
- removing variables and constants that are never referenced
Lexical analysis summary
Comments and white space removed, remaining code turned into a series of tokens, symbol table created
Syntax analysis summary
Abstract syntax tree is built from tokens produced in previous stages, errors generated if any tokens break the rules of the language
Code generation summary
Abstract code tree converted to object code, object code is the machine code produced before final step is run
Optimisation summary
Tweaks code so it will run quickly and use as little memory as possible
What is an assembler
Translates assembly language into machine code
Takes basic commands and operations from assembly code and converts them into binary code that can be recognised by a specific type of processor
One to one translation process from assembly into machine code
Pros of assembler
Programs written in machine language can be replaced with mnemonics, which are easier to remember
Memory efficient
Speed of execution is faster
Hardware oriented
Requires fewer instructions to accomplish the same result
Cons of assembler
Lack of portability
Difficult to remember the syntax
Long programs written in such languages cannot be executed on small computers
It takes lots of time to code or write the program as it is more complex in nature
What is a compiler
Translates source code from high level languages into object code then machine code then processed by the CPU
Whole program is translated into machine code before it is translated
What is an interpreter
Translates source code from high level into machine code ready to be processed by CPU
Translated line by line as program is running
Pros of compiler
No need for translation at run time
Code is usually optimised
Speed of execution is faster
Original source code is kept secret
Cons of compiler
Designed for specific type of processor
Code needs to be recompiled when code is changed
Program will not run with syntax error