[go: up one dir, main page]

0% found this document useful (0 votes)
55 views19 pages

Programs: Programs Are Written in Programming Languages

The document discusses programming languages and how programs are developed. It explains that programs are written in programming languages, which are sets of rules and symbols used to construct computer programs. There are three major types of programming languages: machine languages, assembly languages, and high-level languages. It also describes the differences between compiled and interpreted languages, and how compilers and interpreters process source code.

Uploaded by

Ashar Azeem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views19 pages

Programs: Programs Are Written in Programming Languages

The document discusses programming languages and how programs are developed. It explains that programs are written in programming languages, which are sets of rules and symbols used to construct computer programs. There are three major types of programming languages: machine languages, assembly languages, and high-level languages. It also describes the differences between compiled and interpreted languages, and how compilers and interpreters process source code.

Uploaded by

Ashar Azeem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 19

Programs

Programs are written in programming languages


PL = programming language
Pieces of the same program can be written in different
PLs
 Languages closer to the machine can be more efficient
 As long as they agree on how to communicate

A PL is
A special purpose and limited language
A set of rules and symbols used to construct a computer
program
A language used to interact with the computer

Ms Qurat-ul-Ann
Programming Languages
Programming languages allow programmers to code
software.
The three major families of languages are:
Machine languages
Assembly languages
High-Level languages

Ms Qurat-ul-Ann
Computer Languages
– Machine Language
• Uses binary code
• Machine-dependent
• Not portable
Assembly Language
Uses mnemonics
Machine-dependent
Not usually portable
High-Level Language (HLL)
Uses English-like language
Machine independent
Portable (but must be compiled for different platforms)
Examples: Pascal, C, C++, Java, Fortran, . . .

Ms Qurat-ul-Ann
Machine

Language
The representation of a computer program which is
actually read and understood by the computer.
 A program in machine code consists of a sequence of machine
instructions.
Instructions:
 Machine instructions are in binary code
 Instructions specify operations and memory cells involved in the
operation
Example: Operation Address

0010 0000 0000 0100

0100 0000 0000 0101

0011 0000 0000 0110

Ms Qurat-ul-Ann
Assembly Language
A symbolic representation of the machine language of a
specific processor.
Is converted to machine code by an assembler.
Usually, each line of assembly code produces one machine
instruction (One-to-one correspondence).
Programming in assembly language is slow and error-
prone but is more efficient in terms of hardware
performance.
Mnemonic representation of the instructions and data
Example:
Load Price
Add Tax
Store Cost

Ms Qurat-ul-Ann
High-level language
A programming language which use statements consisting
of English-like keywords such as "FOR", "PRINT" or “IF“, ...
etc.
Each statement corresponds to several machine language
instructions (one-to-many correspondence).
Much easier to program than in assembly language.
Data are referenced using descriptive names
Operations can be described using familiar symbols
Example:
Cost := Price + Tax

Ms Qurat-ul-Ann
Procedural Languages
Early high-level languages are typically called
procedural languages.
Procedural languages are characterized by sequential
sets of linear commands. The focus of such languages
is on structure.
Examples include C, COBOL, Fortran, LISP, Perl,
HTML, VBScript

Ms Qurat-ul-Ann
Structured Programming
A method for designing and coding programs in a
systematic, organized manner.
It combines the principles of top-down design,
modularity and the use of the three accepted control
structures of sequence, repetition and selection.

Ms Qurat-ul-Ann
Syntax & Semantics
Syntax:
The structure of strings in some language. A language's
syntax is described by a grammar.
Examples:
 Binary number
<binary_number> = <bit> | <bit> <binary_number>
<bit> =0|1
 Identifier
<identifier> = <letter> {<letter> | <digit> }
<letter> =a|b|...|z
<digit =0|1|...|9
Semantics:
The meaning of the language

Ms Qurat-ul-Ann
Syntax & Grammars
Syntax descriptions for a PL are themselves written in
a formal language.
E.g. Backus-Naur Form (BNF)
The formal language is not a PL but it can be
implemented by a compiler to enforce grammar
restrictions.
Some PLs look more like grammar descriptions than
like instructions.

Ms Qurat-ul-Ann
Compilers & Programs
Compiler

A program that converts another program from some

source language (or high-level programming language /


HLL) to machine language (object code).
Some compilers output assembly language which is then

converted to machine language by a separate assembler.


Is distinguished from an assembler by the fact that each

input statement, in general, correspond to more than one


machine instruction.

Ms Qurat-ul-Ann
Compilation into Assembly L
Source Assembly
Program Compiler Language

Assembly Assembler Machine


Language Language

Ms Qurat-ul-Ann
Compilers & Programs
Source program

The form in which a computer program, written in

some formal programming language, is written by


the programmer.
Can be compiled automatically into object code or

machine code or executed by an interpreter.


Pascal source programs have extension ‘.pas’

Ms Qurat-ul-Ann
Compilers & Programs
Object program
Output from the compiler
Equivalent machine language translation of the source
program
Files usually have extension ‘.obj’

Executable program
Output from linker/loader
Machine language program linked with necessary libraries &
other files
Files usually have extension ‘.exe’

Ms Qurat-ul-Ann
Program Errors
Syntax Errors:
Errors in grammar of the language
Runtime error:
When there are no syntax errors, but the program can’t
complete execution
 Divide by zero
 Invalid input data

Logical errors:
The program completes execution, but delivers
incorrect results
Incorrect usage of parentheses

Ms Qurat-ul-Ann
Compilation
Source Target
Program Compiler Program

Input Target Program Output

Compiler translates source into target (a machine


language program)
Compiler goes away at execution time
Compiler is itself a machine language program,
presumably created by compiling some other high-level
program
Machine language, when written in a format understood
by the OS is object code
Ms Qurat-ul-Ann
Interpretation
Source
Program

Interpreter Output

Input

• The interpreter stays around during execution


• It reads and executes statements one at a time

Ms Qurat-ul-Ann
• Translates instructions to machine code line-by-line or
statement by statement.
• It executes statement before translating the next statement
of the source program
• If there is an error in the statement , the interpreter stops
working and displays an errors message.
• The disadvantage of interpreter is that it is not very efficient
• The interpreter does not produce an object code .it must
convert the program each time it is executed .
• Visual Basic uses interpreter.

Ms Qurat-ul-Ann
Compilation vs. Interpretation
Compilation:
Syntax errors caught before running the program
Better performance
Decisions made once, at compile time
Interpretation:
Better diagnostics (error messages)
More flexibility
Supports late binding (delaying decisions about
program implementation until runtime)
 Can better cope with PLs where type and size of variables
depend on input

Ms Qurat-ul-Ann

You might also like