2.2 (APPLICATIONS) Flashcards
What is a translator?
Translators convert source code from a high-level language to a low-level language
There are three main types of translators:
Interpreters
Compilers
Assemblers
What is an interpreter?
Interpret source code line-by-line and executes it on the fly
Easier to debug, allows incremental testing, and is generally faster to start execution
Slower execution time overall and requires the interpreter to be present during the execution
If an error is found there is no need to recompile the whole code
What is a compiler
Translates the entire source code into machine code at once and then executes it
Faster execution time, no need for the compiler during execution
Longer initial compilation time and can be more challenging to debug
can be run many times without needing to be recompiled
What is an assembler?
Assemblers translate assembly language into machine code
Unlike interpreters and compilers that work with high-level languages, assemblers deal with low-level languages
Give the order of abstraction in programing languages? (High to low, 5)
High level interpreted-Javascript, python
High level compiled- C, C++
Assembly- assembly language
Machine- Hex representaion of binary code
Binary- Binary
compare the development paradigms f compilers and interpreters
Interpreted languages allow determining variable types at runtime, which makes development faster
e.g. ‘'’var x = 5’’‘(Interpreter will calculate x to be a number at runtime)
Compiled languages enforce stricter type-checking at compile time, which requires additional work across the project
e.g. ‘'’String var name = ‘Michael’;’’’ (Compiler will demand that name has a datatype before compiling)
State the stages of compilation (4)
Lexical analysis
Syntax analysis
Code generation
Optimisation
What happens during lexical analysis?
Lexical ‘tokens’ are identified
Tokens represent small meaningful units in the languge
e.g. Keywords: ‘var’, ‘function’, ‘while’
Identifiers: variable names,function names
Operators : ‘+’, ‘-‘
Seperators: ‘:’, ‘;’
Unnescesary elements like comments and whitespace are removed
A token table is produced
What happens during syntax analysis?
Makes sure the tokens adhere to the syntax rules of the language
If the code passes the syntax analysis, the compiler can create an Abstract Syntax
Tree (AST)
An AST is a graph-based representation of the code being compiled
An AST is an efficient way to represent the code for the next step
What happens during code generation?
Takes the AST to generate object code that can be executed
What happens during optimisation?
This step modifies the code to make it more efficient without changing its functionality
This is important to attempt because it reduces the memory required to run the code, which leads to faster execution
A common optimisation action is removing duplicate code
If an ‘add’ function is written twice in the source code, a sophisticated compiler will notice this and include it only once in the object code
What is a library?
A code library is a collection of pre-written code, classes, procedures,scripts, configurations, and more. They are packaged together to allow developers to perform common tasks without having to write code from scratch.
What are the benefits of libraries?
Efficiency: Saves time and effort, as you don’t need to write everything from scratch
Reliability: Often tested and optimized, reducing the chance of errors
Reusability: The same library can be used in different parts of the project or in different projects
Community Support: Popular libraries often have strong community support and documentation
What are the drawbacks of libraries?
Dependency Issues: Relying on a third-party library can lead to problems if the
library is discontinued or not maintained
Compatibility: There might be compatibility issues with different versions of the
library or the system you are working on
Overhead: Using a large library for a small task can add unnecessary complexity and
size to the application
What does a linker do?
These combine different code files and libraries into a single executable.
They resolve references between files, ensuring everything points where it should