Flashcards
Programming language translators
Cards in this deck (26)
- 1The function of a programming language translatorConverts source code to object code, while detecting errors in the source code
- 2Source codeCode written in a high-level language
Acts as a halfway house between natural language and machine code - 3Object codeA program converted to machine code, but without any library code
- 4Types of translator1. Compiler
2. Interpreter
3. Assembler
4. Bytecode/intermediary code - 5CompilerTranslates an entire high-level program into object code
- 6Advantages of a compilerOutput code is fully built with no dependencies (following linking with libraries)
The program can run without the compiler present
It's difficult to reverse-engineer the code, making it more secure - 7Disadvantages of a compilerThe entire program must be compiled in order to run
A separate program must be compiled for each platform - 8InterpreterTranslates source code to machine code line-by-line at runtime
- 9Advantages of an interpreterPortable - the same code can be run on multiple platforms
Faster to test as code is translated at runtime - 10Disadvantages of an interpreterPrograms often run slower as statements have to be retranslated each time they are encountered
Less secure as source code may be provided rather than object code
The interpreter must be present for the code to run - 11AssemblerTranslates assembly language into machine code
Often simpler than other translators as assembly language is mnemonic - each line corresponds to an instruction - 12Bytecode/intermediary codeSome languages use hybrids of compilation and interpretation
This can be done using an intermediary code such as bytecode
Programs are compiled into bytecode, then run from an interpreter - 13Advantages of bytecodePlatform independence - bytecode can be run on any machine
Secure layer - the interpreter can act as a guard against any malicious programs
Difficult to reverse-engineer bytecode as it is closer to machine code than natural language - 14Disadvantages of bytecodeRequires the interpreter to be present on the computer
- 15Stages of compilation1. Lexical analysis
2. Syntax analysis
3. Code generation
4. Optimisation - 16Lexical analysis1. Comments and whitespace are removed from the program
2. High-level code is converted into a series of tokens using reserved words that can be picked out by the computer
3. A symbol table is created and used to keep track of variables and subroutines - 17Symbol tableContains an entry for every keyword and identifier in the program
Commonly implemented as a hash table to improve access speed
Typically shows
1. The identifier or keyword
2. The kind of item represented (variable, array, etc.)
3. The type of item represented - referring to data types
4. The run-time address of the item or its value if constant
5. A pointer to accessing information - 18Syntax analysisParses through tokens and performs the following:
1. Checks the code for syntax errors
2. Compiles a list of errors for the user where the code does not follow the language rules
3. Creates an abstract syntax tree
4. Carries out semantic analysis - 19Semantic analysisCompiler checks for logic errors e.g.
1. Type mismatch
2. Undeclared variables
3. Multiple declarations of the same variable in the same scope
4. Accessing the array with an out-of-bounds integer literal - 20Code generationObject code is generated from the abstract syntax tree
- 21Code optimisationAttempts are made to reduce the execution time of object code
May involve:
1. Removing redundant instructions
2. Replacing groups of instructions with more efficient ones that perform the same function - 22LinkersObject code only consists of the code the developer has written - any libraries or separately compiled subroutines used are not included
It is the job of the linker to collect these other subroutines and link them up with the object code - 23LoadersNot all libraries are pre-compiled - some are only linked to the program at runtime
It is the job of the loader to find these libraries when the program requires them - 24Use of librariesLibraries are ready-compiled objects or subroutines that can be loaded and run when required
Most compiled languages (and some interpreted languages) have their own libraries of pre-written functions which can be imported and used in a program - 25Advantages of librariesOften well-tested and have few errors
They save the programmer time as they do not have to write code already written to perform common tasks
Can be used many times, reducing the risk of error - 26Disadvantages of librariesThere may be a lack of documentation
Information
- Description
- A level OCR A level Computer Science (Topic 2 - Systems Software) Flashcards on Programming language translators, created by James Norman on 26/01/2020.
- Created by
- James Norman
- Views
- 1
- Rating