SLR 15 - programming languages and translators Flashcards
What is the difference between how programs that have been compiled and programs that have been interpreted can run?
Compiled programs can be run without requirement for any other software to be present. This is not the case with interpreters
How do interpreters work?
- They have procedures that can be used to translate each kind of program instruction
- They check for errors as they translate rather than before
- A program with errors with be partially translated until the error is reached
How is bytecode executed?
- With a virtual machine which can execute bytecode of different processors
- Each different processor instruction set will have its own virtual machine
Why do we need translators?
A program needs to be in machine code to be executed, so translators are needed to convert HLL and Assembly language into machine code (binary)
What are the 3 types of translator?
- assembler
- interpreter
- compiler
What does an assembler do?
It converts assembly language into machine code
Why is assembly language translation quick and easy?
- an assembly language instruction has a one to one relationship with machine code
- this means translation is quick
Why do different assembler need to exist for each different type of processor instruction set?
They are platform specific
What do compilers do?
They translate programs written in high-level languages into machine code
How do compilers work?
- They take the HLL as their source code
- They check it for any errors
- Then translate the whole program at once
- If there is an error the source code then it will not be translated
Why are compilers deemed platform specific?
They produce machine code
What do interpreters do?
- they translate HLL into machine code LINE BY LINE
Why do interpreters offer poor protection for their source code?
- during translation, the program source code and the interpreter must be present
- it makes the original code difficult to extract
Advantages of interpreters?
- useful when writing programs
- no need for lengthy, time consuming recompilation every time an error is found
- makes it much easier to partially test and debug programs
Advantages of compilers?
- Generated object code is kept on a disk, it can be run when needed without needing to recompile it
- once created, object code executes much faster then interpreted code
- the object code is relatively secure, it is hard to read it and work out what the source code would have been (protected from extraction)
What do compilers sometimes produce before machine code? Example?
intermediate language e.g., bytecode. its a half-way standard language which can then be translate to computer specific machine code
Why do compilers produce intermediate language?
it allows for platform independence
What is the advantage of intermediate language?
It allows the interpreter to translate the source code just once, while still being able to execute the translated code with a variety of different processors
What is source code?
The name given to the input to a translator e.g., assembly language for an assembler and HHL for compilers and interpreters
What is object code?
The translators output and is produced from source code
Define a quick time-line of computer languages:
- limited speed and memory of computers meant programmers coded in LLL (machine code), which directly manipulated the processor (often difficult and prone to errors)
- Assembly code
- Then HHL developed (one to many relationship) where instructions could be communicated to the computer processor
What are the characteristics of a LLL?
- they are specific to the type of processor they are written for
- they directly affect the computer processor
What are the two types of low level language?
- machine code
- assembly code
What are the disadvantages of Machine code?
- it uses only binary but its very long and difficult for humans to understand
- Machine code programs are prone to errors
- Very difficult to debug