Chapter 10 - Programming language translators Flashcards
What type of code is needed for the CPU to understand it and execute the instructions?
» Machine code
What is the relationship between assembly code and a binary code instruction?
» One - to -one
What does the machine code instructions that a particular computer can execute depend on?
» The instruction set
What is the processor instruction set?
» Manufacturer defines a set of these instructions that processor will be able to carry out that will only work with that particular processor
» Each type of processor will have a different instruction set and different assembly code
What are 2 features of low level language?
» Specific to the instruction set of the processor
» Non-portable (Meaning it can only be run on a processor of the same type that it was written for)
What is an advantage of using low level languages?
» Can make use of specific registers
» Therfore programmers have greater control over the movement of data in and out of the processor
Why are low-level languages not portable?
» As the machine code and assembly code are designed for that specific processor
» Therefore cannot be processed on other processors
What are 2 disadvantages of using low level languages?
» Difficult to write programs in low level languages as programmers need to have a very good understanding of the hardware being used
» Do not have libraries
What are the categories of low level language?
» Assembly code
» Machine code
What is the source code?
» Programming statements that are created by a programmer
What are 2 features of assembly code?
» Type of low-level-language, which is made up of commands/mnemonics
» Each code translates into 1 machine code instruction
What are the advantages of high-level languages?
» Much easier to write/read words
» Portable
» Come with libraries
How are assembly code instructions translated into machine code?
4 marks
» Done by an assembler
» Replaces mnemonic opcodes with machine code - LDA
» Replaces numeric operands with machine code - NUM2
» Chekcs syntax and runs error diagnostics if erros is found
What does the compiler do?
» Translates whole program written in a high level language into executable machine code
» Creates object code before being executed into machine code
How does a compiler work?
» Translates high-level code into machine all at once
» Carrying out a number of checks first
» Compiled code is non-portable
» Code can be run without a translater being present
What does an interpreter do?
» Translate code from high level language into machine code line by line
What are the advantages of a compiler?
» Code can be optimised by the compilier
» Can be distributed as machine code,meaning that the source code is hiddent
What are the disavantages of a compiler?
» You have to wait until the entire program is compiled before receiving any errors - may take a large time for a large program
» Executable code is non-portable
What are the benefits of an interpreter?
» Errors will be reported as soon as they are ecountered - dont have to wait for the entire program to be compiled
» Debugging is quick and easily
What are the drawbacks of an interpreter?
» Program requires an interpreter to be run
» The interpreter takes up space in memory
What is object code?
» Halway code between high level and machine code
» Set of instruction codes that is understood by a computer at the lowest hardware level, but not ready to be executed by the CPU
What is the difference between a compiler and an interpreter in terms of the steps to turn code in machine code?
» Compiler - Source code - Object code - Machine code
» Interpreter - Source code - Machince code
What are 2 differences between a compiler and an interpreter?
» Compiler does produce object code - interpreter does not
» Compiler translates the whole source code at once, intepreter analyses the code line by kine
What is a library, and give an example?
» Sections of code already pre-programmed by other developers containg useful routines
» Such as RANDOM
What are 3 advantages of using libraries?
» Saves time
» Uses expertise of other
» Has been already tested, making debugging easier
What are 2 disadvantages of using libraries?
» May increase size of compiled file as library contains many routines that aren’t being used
» Not written by the programmer - may need to spend time familarising themsleves with it
What is the purpose of the linker?
» Links the main program to libaries by including them in the final executable code
What is the loader?
» Part of the OS which is then responsible for loading a program into main memory
What are the 4 stages of compilation?
» Lexical analysis
» Syntax analysis
» Code generation
» Code optimisation
What is a helpful mneumonic to help remember the stages of compliation
» Life Sucks G.O
What are 3 features of lexical analysis?
» All unnecessary spaces (whitespaces) and all comments are removed
» Keywords, (e.g print), constants and identifiers are replaced with tokens - represents their function in the program
» A symbol table for every keyword and identifier in the program is developed
What are some examples of tokens?
» <.identifier>,<.operator>,<.number>,<.keyword>,<.open_bracket>,<.close_bracket>
» Note the dot is needed, it is just their because of brainscape syntaxing lol
What ar 4 features of Syntax Anaylsis?
» Tokens from Lexical Analysis are checked against the rules of the language
» Errors reported with a list of diagnositics
» Detail is added to the Abstract Syntax Tree
» Passes to code generation
What are 3 features of Code generation?
» Here object code is created
» Program called linker can incorporate the code from libary with the main program
» Into a single executable file
What are 3 features of code optimisation?
» Removes redundant instructions
» Replace inefficient code with code that achieves the same result but in a more effiecient way
» Allows code to execute faster - decrease memory usage
What are 3 features of code optimisation?
» Removes redundant instructions
» Replace inefficient code with code that achieves the same result but in a more effiecient way
» Allows code to execute faster - decrease memory usage
Why is Lexical analysis needed?
» Necessary to put the code into a format which can be read/processed by the syntax analyser
Why is syntax analysis needed?
» To ensure the code is valid in as much as it meets all the structural rules of the language. Guarentees it runs
Why is Code Generation needed?
» Turn the code into a format that processor can understand
Why is code optimisation needed?
» Ensures the code runs much quicker and uses less memory