4.2 Languages
4.2 Languages
Programming Language:
“A set of rules that provide a way of telling computer what operation to perform is called a
Programming Language.”
A COMPUTER PROGRAM is a list of instructions that enable a computer to perform a
specific task. Computer needs instructions to perform a task.
There are some rules and regulations to write programs and these rules and regulations are
programming languages.
Different types of programming languages are given below:
1. Low Level Language (Machine Language and Assembly Language)
2. High level Languages
For Count=1 to 10
Print ''Allah''
Next Count
High-level languages are designed with programmers in mind; programming statements are easier
to understand than those written in a low-level language.
This means that programs written in a high-level language are easier to:
• read and understand as the language used is closer to human language
• write in a shorter time
• debug at the development stage
• maintain once in use.
Examples: Python, COBOL, Pascal, FORTRAN, GWBASIC, C++, JAVA, VB.Net.
Source Code:
''A program written in any language except the machine language is called Source Code.''
Programmers can write programs in Machine Language, Assembly Language and High
Level Languages like COBOL, PASCAL, and GWBASIC etc. The programs, written in Assembly
Language or any High Level Language are called Source Code.
Object Code:
''A program written in Machine Language is called Object Code.''
Computer can understand only machine language code. Language translators converts
source code of High Level Language into machine code, these converted codes are Object
Codes.
Language Translator:
''Language Translators are programs that convert or translate the instructions in Assembly
Language or High Level Language i.e. source code into instructions of machine language i.e.
object codes are called Language Translators.''
Computer can understand only machine language. Programs written in Assembly Language
and High Level Language are translated into Machine Language so as computer can understand
execute them.
3 Compilers:-
''A compiler is a language translator that translates whole source program written in High
Level Language into object code in machine language before execution of program.''
Compilers translate all instructions before executions. The object code is saved as object
file, which is executable. Object files don't need compiler or language for execution.
An executable file of machine No executable file of machine code is An executable file of machine
code is produced. produced. code is produced.
One high-level language One high-level language program One low-level language
statement can be translated statement may require several statement is usually translated
into several machine code machine code instructions to be into one machine code
instructions. executed. instruction.
Compiled programs are used Interpreted programs cannot be used Assembled programs can be
without the compiler. without the interpreter. used without the assembler.
A compiled program is usually An interpreter is often used when a An assembled program is
distributed for general use. program is being developed. usually distributed for general
use.
Tick (✔) to show whether each statement about interpreters is true or false.
Statement Assembler Compiler Interpreter
Translate a line of code at a time then execute it.
Stop executing the code when an error occurs.
Report all syntax errors at the same time in a report.
Will not run the program at all until all errors are corrected.
A report of all syntax errors is produced at the same time.
The program is translated one line at a time then executed.
The program is translated from high-level language into machine
code.
An executable file is produced.
The program will not run at all if an error is detected.
Translates low-level language to machine code
Integrated/Interactive Development Environment (IDE)
Most high-level programming languages offer the use of an IDE for program development. This
contains an editor with an interpreter and/or
compiler together with debugging tools, which
Code Editor
can improve the speed of program
development.
Auto
Translator
completion
Functions of IDE:
1. Code editor: IDE provides a text editor
to type and edit program codes.
2. Auto-completion: feature displays hints Error
Diagnostic:
IDE Auto
correction
(or a choice of keywords) and available Dubug
Divide by zero, numeric overflow are examples of run-time error. Run-time error may be identified
by careful testing in an IDE. They are much more difficult to discover, as program appears to work
until a certain set of data causes a malfunction.
Logic Error
An error in the logic of program, program is executed but not work as it is intended to be. It causes
program to operate incorrectly, but not to terminate abnormally (or crash). A logic error produces
unintended or undesired output or other behaviour, although it may not immediately be recognized
as such. Because a program with a logic error is a valid program in the language, though it does
not behave as intended.
Often the only clue to the existence of logic errors is the production of wrong solutions, though
static analysis may sometimes spot them.
Why errors in a program are called BUG
The term "bug" was used in an account by computer pioneer Grace Hopper, who publicized the cause of a
malfunction in an early
electromechanical computer. A typical
version of the story is:
Explain what is meant by a high-level language and a low-level language, including the
1
advantages and disadvantages of each
Understand that assembly language is a form of low-level language that uses
2 mnemonics, and that an assembler is needed to translate an assembly language
program into machine code
Describe the operation of a compiler and an interpreter, including how high-level
3
language is translated by each and how errors are reported
4 Explain the advantages and disadvantages of a compiler and an interpreter
Explain the role of an IDE in writing program code and the common functions IDEs
5
provide
Topical Past Papers - SoW
(b) Darius will use a translator to translate the program. He could use a compiler or an interpreter.
Five statements are given about compilers and interpreters.
Tick to show if the statement applies to a Compiler or an Interpreter. Statements may apply to
both. [5]
Statement Compiler Interpreter
A report of errors is produced at the end of translation.
The program is translated one line at a time.
The program is translated from high-level language into machine code.
An executable file is produced.
The program will not run at all if an error is detected.
Identify, using the letters A, B or C, which of the above codes is an example of assembly code,
high-level language code or machine code:
Assembly code ....................................................................................................................
High-level language code .................................................................................................
Machine code .............................................................................................................................. [2]