5.1 Languages & Translators Flashcards
Why do programmers use high-level languages?
High-level programming languages use code written in a way that is similar to a natural human language, such as English, making it easier to understand and use the language.
Using high-level languages leads to fewer errors and allows for more powerful and complex commands compared to low-level languages.
However, a high-level language must be translated into machine code (binary) before it can be run, as high-level languages cannot be executed directly by the CPU.
Low-Level Languages
Low-level languages do not closely resemble a natural human language, making it harder for humans to understand and write in.
Low-level languages are used when a program must be executed quickly or when programmers need to write code that interacts directly with the hardware, such as device drivers.
What are the two types of Low-Level Languages
. Machine code
. Assembly Language
Machine Code
This is the pure binary code that computers can directly process and execute.
It is extremely tedious and difficult for humans to understand and write machine code.
However, machine code can be used when a programmer needs to perform a very specific command that can’t be done in a high-level language.
Machine code will be executed faster than high-level programs because it is already in a format the CPU can execute and does not need to be translated.
Assembly Language
Assembly language uses specialised command mnemonics to perform actions. See the Assembly Language section in the programming tab for a list of mnemonics such as INP, OUT and HLT.
Assembly language is preferred by many programmers over machine code because it is easier to understand and spot errors.
It is faster to execute than high-level languages and, like machine code, can be used to directly control the CPU.
What is a translator
A translator changes (translates) a program written in one language into another language (usually machine code).
What are the two types of translator
. Interpreter
. Compiler
Interpreter
An interpreter converts high-level language one line at a time into machine code and executes it.
Compiler
A compiler converts high-level language into machine code for execution at a later time. The entire program is converted at once.
Interpreters vs Compilers : Execution Method
An interpreter translates source code (high level code) into machine code one line at a time.
A compiler translates all the source code (high level code) into machine code in one go.
A compiler produces an executable file that will run on other machines without the compiler needing to be installed.
Interpreters vs Compilers : Execution Speed
An interpreter is slower than a compiler because the code must be reinterpreted each time the program is run.
Compilers can produce much more efficient code than interpreters making the compiled programs run faster.
Interpreters vs Compilers : Complexity
Interpreters are smaller, simpler programs.
Compilers tend to be large complex programs.
Interpreters vs Compilers : Error Reporting
In error reporting, the interpreter would encounter the errors and report it to the user immediately and stops the program from running.
The compiler would analyze the entire program, taking note of where errors have occurred and record them in an error file.
Interpreters vs Compilers : Repetition
Interpreted programs can be edited and run without translating the whole program.
Interpreters must reinterpret the program every time it is run.
Compilation requires analysis and the generation of the code only once, whereas interpreters must re-interpret each time.
However, compiled programs have to be re-compiled after any changes have been made.