🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Lesson 3 - Computer Programming Languages and Language Translators.docx

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

# Lesson 3: Computer Programming Languages and Language Translators ## Programming Language - This is a program with a special role, i.e. it enables us to come up with other programs. - Has instructions that enable us to write programs or modify an existing program. - C, C++, JAVA, PHP, JSP, C#, J...

# Lesson 3: Computer Programming Languages and Language Translators ## Programming Language - This is a program with a special role, i.e. it enables us to come up with other programs. - Has instructions that enable us to write programs or modify an existing program. - C, C++, JAVA, PHP, JSP, C#, JAVASCRIPT etc. ## Features of language - **Grammar:** SYNTAX - **Vocabulary** - **Interpretation/ meaning:** SEMANTICS ## Different Programming Languages - There are many different languages that can be used to program a computer and they are categorized as follows: - **Machine language**- The most basic language that consists of strings of 1's and 0's and stored as binary numbers. - **Assembly /Low-level language** - Symbolic representation of machine code. - **High-level languages** ## Machine Language **Advantages** - The very lowest possible level at which you can program a computer - The assembly language program must be converted to machine language for the machine to understand it. **Disadvantages** - It is very easy to make a mistake, and very hard to find it once you realize the mistake has been made. - Because each machine has its own instruction set, a program written for one machine cannot be ported to another machine. ## Assembly/Low-level language **Advantages** - After machine language, we have assembly languages. **Disadvantages** - The assembly language program must be converted to machine language for the machine to understand it. ## High-Level Languages **Advantages** - Usually, a computer program is written in a high-level language, whose instruction set is more compatible with the human languages e.g. English and the human thought process. - A single instruction in a high-level language will translate to several instructions in machine language. - This greatly simplifies the task of writing complete, correct programs. - The rules for programming in a particular high-level language are much the same for all computers **Disadvantages** - None mentioned ## Language Translators - Any program written in a high-level language is known as source code. However, computers cannot understand source code. - Before it can be run, source code must first be translated into a form which a computer understands. - A translator is a program that converts source code into machine code. - Language translators allow computer programmers to write sets of instructions in specific programming languages. - These instructions are converted by the language translator into machine code. - The computer system then reads these machine code instructions and executes them. - A program that is written in a high-level language must be translated into machine language. - This is a process called compilation or interpretation, depending on how it is done. - Compilation is done by a compiler while interpretation is done by an interpreter. ## Compilers vs Interpreters **Compiler** - A compiler takes the source code as a whole and translates it into machine code all in one go. - Once converted, the object code can be run unassisted at any time. - This process is called compilation. **Advantages** - Compiled programs run quickly, since they have already been translated. - A compiled program can be supplied as an executable file. - An executable file is a file that is ready to run. - Since an executable file cannot be easily modified, programmers prefer to supply executables rather than source code. - Compilers optimize code. - Optimized code can run quicker and take up less memory space. **Disadvantages** - The source code must be re-compiled every time the programmer changes the program. - Source code compiled on one platform will not run on another - the machine code is specific to the processor's architecture. **Interpreter** - An interpreter translates source code into machine code one instruction at a time. - It is similar to a human translator translating what a person says into another language, sentence by sentence, as they speak. - The resulting machine code is then executed immediately. - The process is called interpretation. **Advantages** - Instructions are executed as soon as they are translated. - Errors can be quickly spotted - once an error is found, the program stops running and the user is notified at which part of the program the interpretation has failed. This makes interpreters extremely useful when developing programs. **Disadvantages** - Interpreted programs run slowly as the processor has to wait for each instruction to be translated before it can be executed. - Additionally, the program has to be translated every time it is run. - Interpreters do not produce an executable file that can be distributed. - As a result, the source code program has to be supplied, and this could be modified without permission. - Interpreters do not optimize code - the translated code is executed as it is. ## Assemblers - Assemblers are a third type of translator. - The purpose of an assembler is to translate assembly language into machine code. - Whereas compilers and interpreters generate many machine code instructions for each high-level instruction, assemblers create one machine code instruction for each assembly instruction. - **Diagram:** High-level languages (Java, PHP, Python, etc) ↓ Assembly language ↓ Machine code ↓ Hardware Assembler ↓ Instruction set - The final compiled code runs faster and may be run as many times as desired. A drawback occurs where correction of errors must be done on the source code that must then be re-compiled. - The compilation process produces the object code that is then linked to produce the executable code. ## Program Execution Process (Summary) - **Source Code:** Code that has been written and saved as a file - **Object Code:** Compilation - **Executable Code:** Linking (This phase includes all the existing code) - **Execution** ## Integrated Development Environment - This is a development environment in which Compilers, debuggers and editors are available to the developer from one central point, usually an opening window or menu. - The developer simply selects the software tool needed. - Examples of integrated environments include **Borland** or **Microsoft Visual Studio Development environments**, **CodeBlocks**. ## Debuggers - These are programs that are used to assist the process of error correction in an environment where the compiler is used. - Debuggers behave like interpreters allowing the testing of the program as it is being developed. ## Text Editors/Word Processors - Text editors are computer software that allows the user to create and maintain ASCII texts. They are the most suitable means of writing programs. Most programming environments will therefore have their own text editors. - Word processors are computer software that allows users to create and maintain highly formatted texts. These texts may also contain images and specially shaped characters. If they are used to create a program source code then the code must be save as plain text or ASCII text.

Use Quizgecko on...
Browser
Browser