Translators Flashcards
What is a translator?
A system which converts high level code to machine code.
What is an assembler?
An assembler converts assembly code (low level code) directly into the binary machine code (there is usually a 1-1 relation between assembly and machine code).
What is a compiler?
A compiler converts high level source code into a new executable document for the OS/processor it is being ran on).
What is an interpreter?
An interpreter converts high level source code into machine code one line at a time (often checking the whole program for errors first).
Compilers vs interpreters?
A compiler does not need to recompile every time the code runs, the compiled file runs faster, doesn’t require the compiler software and is more secure when distributing programs as you do not need the source code. Interpreters however can often run on lots of different platforms if they have appropriate interpreters (e.g. Java) and are useful for developing as the you don’t have to recompile each time.
What is bytecode?
It is an intermediate code used by languages like Java, code is compiled into a separate high level code which is then interpreted allows platform independence and code to run faster.
Compare compilers and interpreters.
For a compiler:
Code can be saved and not re-complied each time,
Executes faster,
Can be distributed without compiling software,
And code cannot be read.
For interpreters:
Code does not have to be completely re-complied when errors are found,
Can have platform independence,
Useful for development.
What are the three stages of compilation?
Lexical analysis, syntax analysis and code generation.
What does lexical analysis do?
Removes whitespace and comments, may detect some errors* and all code is converted into tokens and identifiers in code add variables to a symbol table, this is then passed to the syntax analyser.
What does the syntax analysis do?
This is the stage that tries to catch errors, it uses the tokens to check that the code follows the language rules using something similar to a syntax diagram or Backus-Naur form, also checks for semantic errors like using an undeclared variable.
What happens in the code generation stage?
This is where the high-level code is turned into machine code, certain code optimisation will also occur at this stage.
What is a library?
When a certain code function has been written already so the programmers simply use the pre-made functions.
What is a linker?
Links the program and libraries together during compilation by giving the information the loader will need.
What is a loader?
Manages the loading of libraries (dll’s) into memory at run-time.
Compare linkers and loaders.
One required the machine of the person running the program has the required libraries installed, however the alternative could be storing the same libraries multiple times across different programs.