4.2 Programming Languages, Translators, and IDEs

Question Bank · 22 Questions

Objectives: Students should be able to —

  • 1 Identify and describe different types of programming language, translator and use of IDEs.
  • 2 Give advantages and disadvantages of High-level and Low-level languages.
  • 3 Describe how Assembly language is a low-level language that uses mnemonics and assemblers.
  • 4 Describe the operation of Compilers and Interpreters for high-level languages.
  • 5 Give advantages and disadvantages of Compilers and Interpreters.
  • 6 Describe the role and functions of Integrated Development Environment (IDE) when writing code.

High-level and Low-level Programming Languages

(a) Computer Program:

A set of instructions that directs a computer how to perform a specific task.

(b) Programming and Programming Language:

Programming is the process of writing a set of instructions called program or software.

★ A Programming Language is a vocabulary and set of grammatical rules, for writing computational algorithm or program, to instruct a computer to perform specific tasks.

★ Computer programs can be written in either Low-level or High-level languages depending on the task to be performed and the computer or digital device to be used.

★ Mostly programs are written in high-level languages, like — BASIC, C, C++, JavaScript, Pascal, Fortran, Python, etc.

(c) Three types of programming language:

  1. Machine Language.
  2. Assembly Language.
  3. High-level Language.
⚠ Note: Machine language and Assembly language are called Low-level language because they directly correspond to a specific machine; use machine dependent codes; difficult for humans to read and write.

(a) Machine language:

★ A digital language that uses 0s and 1s, which is the only language understood by a computer, is called machine language.

★ The machine language is machine dependent. The manufacturer designs the machine code by a string of binary digits (bits) 0 and 1.

★ Different types of computer systems use different sets of binary instructions.

Example:

00010101 10110010 11110011
10111011 00010001 01011101

(b) Advantages and disadvantages of Machine language:

★ Advantages:

  1. Don't need any translator to translate the code.
  2. Machine specific codes can be used to write machine specific software, like device drivers.
  3. Its file size is too small and executes very fast.

★ Disadvantages:

  1. It is very difficult to understand and tedious process of writing programs in machine languages.
  2. Need to remember machine specific codes and its different memory location addresses.
  3. It is very difficult to edit or debug the program.

(a) Assembly language:

★ A programming language that uses mnemonic codes (alphanumeric) and symbols.

★ It is machine dependent codes. The codes written in one machine cannot be used in another.

★ It is easier for the computer to understand but more difficult for the programmer to write.

★ The instructions of the assembly language have to be converted into machine codes by a language translator called Assembler before execution.

Example:

LDA #6ad
ADD #f3c
STO #46b
  • LDA means load the value of the variable (held at location address #6ad) into the accumulator.
  • ADD means add the value of variable (held at location address #f3c) to the value stored in the accumulator.
  • STO means store / replace the value of the variable (held in location address #46b) by the value stored in the accumulator.

(b) Advantages and disadvantages of Assembly language:

★ Advantages:

  1. Assembly language is easier to understand and use than Machine language.
  2. Machine specific codes can be used to write machine specific software, like device drivers.
  3. Its file size is too small and executes very fast.

★ Disadvantages:

  1. Programmer needs to have knowledge of the hardware and its machine specific codes.
  2. Need to remember different memory location addresses.
  3. It is difficult to edit or debug the program than high-level language.

(a) Low-level language:

Assembly language which uses mnemonic codes and Machine language which uses only binary digits 0s and 1s are collectively called Low-level language.

★ Low-level languages are machine dependent. They use machine specific codes.

★ Programs written in one machine cannot be used in another machine.

(b) Difference between Machine language and Assembly language:

Machine language Assembly language
Machine language is only understood by computers.Assembly language is only understood by humans, not by computers.
Machine language can only be represented by 0s and 1s.Assembly language uses mnemonic codes (alphanumeric) and symbols instead of 0s and 1s.
Machine language does not need any translator.It needs Assembler to translate it into machine code before execution.
Difficult to read, remember and write.Easy to read, remember and write than Machine language.

(c) Why a programmer would choose Low-level language:

★ Low-level Assembly language uses processor specific mnemonic code that allows programmers to write highly optimized code for CPU to interact with hardware directly.

★ It uses machine dependent codes, so it is used to write programs for a specific hardware or device, like device drivers.

★ It takes very less memory.

★ It performs its task very quickly.

(a) High-level language:

★ A programming language that uses English-like statements and mathematical symbols; easy to read and write.

★ It is machine independent code. The code written in one machine can be used in all machines.

★ High-level language programmers don't need to have hardware knowledge.

Example:

INPUT "Enter the length : ", L
INPUT "Enter the width : ", W
Area = L * W
PRINT "Area of rectangle = ", Area

(b) Advantages of High-level language:

  1. Easy to read and understand as the language used is closer to human language.
  2. No need to have hardware knowledge.
  3. It is portable. Same program can be used on different computers.
  4. It is easy to debug and test programs.
  5. Easy to edit and update.

(c) Disadvantages of High-level language:

  1. Accessing and controlling hardware directly is difficult.
  2. It needs to be translated into machine code before execution.
  3. It occupies more memory than low-level programs.
  4. High-level programs are comparatively slower than low-level programs.
High-level language Low-level language
Easy to read and write.Difficult to read and write.
Uses machine independent code.Uses machine dependent code.
Easy to modify.Difficult to modify.
No need to have hardware knowledge.Deep hardware knowledge is needed.
Slow in execution.Faster in execution.

Translators: Assembler, Interpreter and Compiler

Translators are system software which are used to translate the human-readable source codes into binary machine-readable codes.

★ It is a programming language processor that converts Low-level (Assembly language) and High-level programming language codes into machine codes.

★ Translators are of three types:

  1. Assembler.
  2. Interpreter.
  3. Compiler.

Assembler is a translation program used to convert the program written in Assembly language into Machine code.

★ It converts the code line by line and produces an executable file.

★ It is machine dependent.

★ Once a program is assembled to the machine code, it can be directly used again and again to perform the same task.

Assembler Translation Flow:

Source Code
(Line-1, Line-2, Line-3 …)
Translator / Assembler Object Code
(Line-1, Line-2, Line-3 …)
Linker
+ Run-time Library modules
(Machine dependent codes)
Executable File
/ Machine code

High-level programs could be translated into machine code by any one of the two translators:

  1. Interpreter.
  2. Compiler.

★ Interpreter:

⇒ Interpreter translates and executes the programming code each line at a time.

⇒ It produces error message whenever it encounters an error line by line, so it is easy to debug and test program during development.

⇒ It does not produce any separate executable file in machine code.

⇒ It is slower than compiler.

Interpreter Flow:

Source Code
(Line-1, Line-2, Line-3 …)
Translator / Interpreter
+ Run-time Library Files
(Linux, Windows, Mac OS)
Program Output
(Line by line)

★ Compiler:

⇒ Compiler reads and translates the whole program in one go.

⇒ It produces a list of errors of the whole program before translation.

⇒ It produces an object-code and a separate executable file in machine code, if there is no error in the source code.

⇒ It is faster than Interpreter.

Compiler Flow:

Source Code Translator / Compiler Object Code Linker
+ Run-time Library Files
(Linux, Windows, Mac OS)
Executable File
/ Machine code
  1. Object code is a mid-level code between source code and machine code.
  2. Object code is a machine-readable instruction but can't be executed directly by the CPU. [e.g. *.ELF (Executable Linking Format)].
Whereas machine code is binary code that can be executed directly by the CPU. [e.g. .EXE (Executable) file format]
  1. Object code has to establish links to run-time library modules using specialized software called Linker to become an executable program.

★ Advantages:

  1. Source code is no longer needed once it is compiled to execute the program.
  2. A compiled program can be supplied as an executable file.
  3. Compiled programs run quickly, since they have already been translated.

★ Disadvantages:

  1. You can't change the program without the source code.
  2. The source code must be re-compiled every time the programmer changes the program.
  3. The machine code produced by the compiler depends on the target computer architecture like its operating system and word size — 16-bits, 64-bits, etc.

★ Advantages:

  1. Easier and quicker to debug and test programs during development.
  2. It is portable, because it translates and executes the code directly.
    (The translation of source code depends on the target computer's architecture which may vary from one computer to another.)

★ Disadvantages:

  1. Program cannot run without interpreter.
  2. Interpreted code runs slower.
  3. Does not produce machine code at all.

(a) Why David prefers Interpreter when creating the program:

⇒ Interpreter translates high-level language source code one line of instruction at a time and executes it.

⇒ It would be easy to debug the program as it produces an error each time it encounters one.

(b) Why David needed to compile the program after completion:

⇒ Compiler translates high-level language source code all at a time and produces a separate executable file.

⇒ This executable file could be sold as it could be used independently without the source file or compiler.

Compiler Interpreter
Reads and translates the whole high-level language program into machine code in one go.Reads, translates and executes a high-level program, one statement at a time.
It produces a list of errors, if it encounters them, before translation.It produces only one error message, if it encounters it while reading a statement.
It takes a longer time to debug and test program during development.It is easy to debug and test program during development.
An executable file of machine code is produced.No executable file of machine code is produced.
Compiled programs are run without the compiler.Interpreted programs cannot run without the interpreter.
A compiled program is usually distributed for general use.An interpreter is often used when a program is being developed.

⇒ Low-level Assembly language uses processor specific mnemonic code that allows programmers to write highly optimized code for CPU to interact with hardware directly.

⇒ Assembled programs are faster than high-level compiled programs and use very less memory.

Compiler Assembler
Compiler is machine independent.Assembler is machine dependent.
Compiler is used to convert High-level language into machine code.Assembler is used to convert low-level assembly language into machine code.
Compiler considers the entire code as one block, converts and produces an executable file.Assembler converts the code line by line and produces an executable file.

Integrated Development Environment (IDE)

(a) Source code:

Source code is the list of human-readable instructions that a programmer writes using a simple text editor for the computer to perform some specific task.

★ Source code cannot be executed by a computer until it is converted into Machine code, using a Translator (like Assembler, Interpreter or Compiler).

★ All source code programs need to be translated before they can be executed, unless they are written directly in Machine code.

(b) Difference between Syntax error and Logic error:

Syntax error Logic error
It is where a program statement doesn't obey the rules of the programming language.It is where the program doesn't do what the programmer wanted it to do.
A program cannot be translated if it contains syntax errors.Logic errors are found when a program is being run.

(a) Integrated Development Environment (IDE):

★ An IDE is a software that provides useful functions for a programmer writing a computer program.

★ IDE is an interface which provides Source code editor, Translator (Interpreter / Compiler), and Run-time environment to execute, debug and test the program.

(b) Three main features of an IDE and their purpose:

IDE essentially contains:

  1. A Code editor: used to write and edit source code.
  2. A Compiler or Interpreter: translates the source code into machine-readable language and executes it.
  3. A Run-time environment with debugger: allows to execute, test and debug the program during development.

(c) Benefits of using IDE for a programmer:

  • IDE allows developing software without spending much time on language syntax.
  • It offers predefined templates.
  • No need to switch between multiple programs and applications. All the tools needed are available at one place within the IDE.
  • It includes a debugger which helps to prevent mistakes and provides instant feedback as the developer writes code.
  1. Code editor.
  2. A translator (compiler or interpreter).
  3. A Runtime environment with a debugger.
  4. Error diagnostics.
  5. Auto-completion.
  6. Auto-correction.
  7. An auto-documenter and pretty-printing.

(a) Code editor:

⇒ Code editor allows a program to be written and edited without changing to a separate text editor.

⇒ It speeds up the program development process.

⇒ It provides auto-complete feature through prompts with text completion for variable names and reserved words.

(b) Translator:

⇒ IDE provides a translator, which could be either interpreter or compiler or both to convert source code into executable machine code.

⇒ Interpreter is often used for developing the program and the compiler is used to produce the final executable file to be used without source code.

(c) Runtime environment with debugger:

⇒ It allows to run and test the program line by line before completing the whole program.

⇒ It allows to set a breakpoint in the source code to stop execution of the program at that point.

⇒ A report window shows the contents of variables and expressions evaluated up to the set breakpoint in the program.

⇒ This allows the programmer to see if there are any logic errors in the program and check that the program works as intended.

(d) Error diagnostics and Auto-correction:

⇒ Automatically check for errors as the program code is being typed.

⇒ Alerts the programmer about the error in code and suggests possible correction by highlighting the error.

⇒ It helps the programmer to correct the errors while writing a programming statement before going to the next.

(e) Auto-documenter and pretty-printing:

Auto-documenter allows to create a document that can be used by other developers to understand how and why the code was created — describes what each variable, array and subroutine is used for, and explains the purpose of each function and module used in the program and its expected outcomes or behaviour.

Pretty-printing feature allows to provide different colours to the keywords, programming statements, variables, numbers and text data in a meaningful way.

Example: Keywords in "blue", numerical data in "red", programming statements in "black", etc.

Purpose of Error diagnostics:

  • Automatically check for errors as the program code is being typed.
  • Alert the programmer about the error in code and provide suggested correction by highlighting the error.
  • Allow the programmer to correct the error in code while the program development is in progress.

Example:

01 INPUT "Enter the number = " Num
08 PRENT Average

Error is underlined in red and a description about the errors is listed, like:

  • Error in Line-01: Comma "," or a valid expression — continuation expected.
  • Error in Line-08: Invalid function "PRENT".

(a) Three features for program readability, with examples:

Feature 1: Easy to read, understand and debug as it uses simple English.

Example: INPUT Num / OUTPUT Result / IF Age >= 18 THEN OUTPUT "Eligible to vote" / REPEAT … UNTIL Accept = TRUE

Feature 2: Allows to write comments (Documentation) — the statement marked as comment will not be considered as programming code.

Example: It allows to provide explanations and usage guidelines for others to understand the purpose of the codes. Like — double forward slash ( // ) to comment in Java, single quote ( ' ) to comment in VB.

Feature 3: Object-oriented programming (OOP) — allows to organize code into classes and objects.

Example: Procedures and functions make it easier to understand the program's structure.

(b) Other three useful features of high-level language:

Feature 1: Provides a well-defined Syntax.

Example: A well-defined way of writing programs makes it easy to understand, learn and write the program.

Feature 2: Availability of Library functions — it provides a large number of built-in functions to perform some specific task.

Example: To calculate the square-root of a number, the programmer can use the available built-in function without writing its own code.

Feature 3: Machine independent code.

Example: The program written in one computer with an Intel processor can be run on another computer having a Motorola processor.

Revision: Statements and Key Computing Terms

Term Definition
Machine codeA binary programming language; a program written in machine code can be loaded and executed without translation.
High-level language (HLL)A programming language that is independent of computer hardware; a program written in a HLL needs to be translated into machine code before it is executed.
Low-level language (LLL)A programming language that is dependent on computer hardware; both machine code and assembly language are LLLs.
TranslatorConverts a program written in a human-readable language or a language which the machine cannot read into machine code.
Assembly languageA programming language that is dependent on computer hardware; a program written in assembly language needs to be translated into machine code before it is executed.
AssemblerA computer program that translates programming code written in assembly language into machine code.
CompilerA computer program that translates a source program written in a high-level language to machine code.
InterpreterA computer program that reads, translates and executes a program written in a high-level language line by line.
Integrated Development Environment (IDE)A suite of programs used to write and test a computer program written in a high-level language.
DebuggingFinding errors in a computer program by running or tracing the program.
Pretty-printingDisplaying source code using different colours and formatting, which makes the code easier to read and understand.
Report windowA separate window in the runtime environment of an IDE that shows the contents of variables during the execution of a program.