Code Translation Flashcards
What is code translation?
In simple terms, it is the process of translating source code to object code.
Special Programs for Translation
Four examples of programs used for translation include:
- Compiler
- Interpreter
- Assembler
- Linker
Platform Independent
This means source code is portable, and writes the code as one simple text file. Then uses a compiler that targets a specific platform (source code and byte code).
Platform Dependent
Compiler outputs assembly code or object code that will only run on the platform for which it was compiled (compile a game in c++, and run it on PC, Xbox etc). Examples include assembly code and machine code, or object code.
Compiler v Interpreter
Compiler translates the whole code (returns a file of errors) and adds it to an executable, whilst interpreter runs line-by-line.
With compilers, translations and executions phases are separate, while for interpreters, they are interlaced.
Compiler Advantages
Compilation process is faster than interpreter.
Compiled code runs much faster.
Checks for syntax AND semantic errors, but interpreters can only check for syntax errors.
Interpreter Advantages
Syntax errors are easily identifiable.
Useful for rapid prototyping.
Debugging tools are easier to use.
Java’s Exception with Compiler and Interpreter
Java uses best of both worlds, compiling the java with the java development kit (javac in terminal), and then running it with the interpreter, the java virtual machine (java in terminal).
Interpreter Creation
At the origin of every interpreter there will be a compiler. Essentially, a compiled language will be needed to write the code for the interpreter.
Single Pass Compiler
Moves through source code line-by-line and generates object code along the way.
Multi-pass Compiler
Reads the entire source file into an internal data structure, and analyses and augments the data structure in multiple stages.
Linking
There can be many source files, which compiled turns into object files, so it is the linker’s job to put all these together into one final executable program image.
Static Linking
Static linking copies all the libraries used in our code into the final executable file.
Dynamic Linking
Dynamic linking is the process of loading the external shared libraries into the program and then binds those shared libraries dynamically to the program.
Lexical Component
List of all keywords allowed in language (import, public, else, while, for).