0% found this document useful (0 votes)
7 views

Introduction to Programming Languages

The document provides an overview of programming languages, categorizing them into machine languages, assembly languages, and high-level languages, each with distinct characteristics. It explains the differences between compilers and interpreters, highlighting their respective functions and efficiency. Additionally, it introduces Pascal as a procedural high-level language, detailing its program structure, common errors, and examples of code.

Uploaded by

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

Introduction to Programming Languages

The document provides an overview of programming languages, categorizing them into machine languages, assembly languages, and high-level languages, each with distinct characteristics. It explains the differences between compilers and interpreters, highlighting their respective functions and efficiency. Additionally, it introduces Pascal as a procedural high-level language, detailing its program structure, common errors, and examples of code.

Uploaded by

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

INTRODUCTION TO PROGRAMMING LANGUAGES

A program is set of instructions that tell the computer what to do. A programming language is a formal
computer language designed to communicate instructions to the machine, particularly a computer.

Types of computer Languages

The three major families of languages are:

– Machine languages or native language

– Assembly languages or Low level language

– High-Level languages

1. Machine Languages

• Comprised of 1s and 0s

• The “native” language of a computer, the language which the computer can understand.

• Difficult to program – one misplaced 1 or 0 will cause the program to fail.

• Example of code:
1110100010101 111010101110
10111010110100 10100011110111

2. Low level Language /Assembly Languages


 Assembly languages are a step towards easier programming.
 Works directly at the hardware level of the computer.
 Assembly languages are comprised of a set of elemental commands which are tied to a specific
processor.
 Assembly language code needs to be translated to machine language before the computer
processes it.
 Example:
ADD 1001010, 1011010

3. High-Level Languages
 High-level languages represent a giant leap towards easier programming.
 The syntax of HL languages is similar to English.
 Needs a compiler or interpreter to convert the source code into machine code.
 Historically, we divide HL languages into two groups:
a) Procedural languages
o Early high-level languages are typically called procedural languages.
o Procedural languages are characterized by sequential sets of linear commands. The focus
of such languages is on structure.
o Examples include C, COBOL, Fortran, LISP, Perl, HTML, VBScript, Pascal etc
b) Object-Oriented languages (OOP)
o Most object-oriented languages are high-level languages.
o The focus of OOP languages is not on structure, but on modeling data.
o Programmers code using “blueprints” of data models called classes.
o Examples of OOP languages include C++, Visual Basic.NET and Java.

Differences between a Compiler and an Interpreter

The difference between an interpreter and a compiler is given below:

Interpreter Compiler

Scans the entire program and


Translates program one statement
translates it as a whole into machine
at a time.
code.

It takes large amount of time to


It takes less amount of time to
analyze the source code but the
analyze the source code but the
overall execution time is
overall execution time is slower.
comparatively faster.

No intermediate object code is Generates intermediate object code


generated, hence are memory which further requires linking, hence
efficient. requires more memory.

Continues translating the program It generates the error message only


until the first error is met, in which after scanning the whole program.
case it stops. Hence debugging is Hence debugging is comparatively
easy. hard.

Programming language like Python, Programming language like C, C++


Ruby use interpreters. use compilers.
INTRODUCTION TO PASCAL PROGRAMMING

Pascal is a procedural High level language. Some of the famous programs written in this language are
Skype and Apple Lisa.

Program Structure

A Pascal program is divided into two main sections-The program header and the instructions block. These
main sections comprise of the following parts:

 Program name
 Uses command
 Constant declarations
 Variables declarations
 Main program block

Example
Program header
PROGRAM HELLOWORLD;

USES Crt;
(*Variable declaration section*)
VAR ……..; Variable Declaration
……..;

(*instruction block*)
BEGIN
Clrscr;
Instruction Block
Writeln(‘Hello St.Marys’);
Readln;
END.

 The first line of the program HellowWorld; indicates the name of the program.
 The second line of the program uses crt; is a preprocessor command, which tells the compiler to
include the crt unit before going to actual compilation.
 The third line (*Variable declaration section*) is a comment. Comments are messages that
describe what the section of code does and comments are ignored by the compiler.
 The next line VAR is a variable statement which is used to tell the compiler to reserve space in
primary memory for the variables which will be used in the program.
 The next lines enclosed within begin and end statements are the main program block. However,
the end statement indicating the end of the main program is followed by a full stop (.) instead of a
semi-colon (;)
 The reserved word Clrscr; is a procedure that clears the screen for the output
 The Writeln(‘Hello St.Marys’); used print out the output on the screen.
Writeln(‘ hello’); will display hello
 The Readln; establishes communication between the computer and the user. It allows the
display to pause until the user presses a key. It is part of the crt unit. A unit is like a pascal library.

Types of Compiler errors


Code that has mistakes won’t compile. The types of errors in Pascal are:
 Syntax errors an error resulting from the a typing error or from disobeying one of the pascal
programming rules
 Logical error a mistake in the logic of the steps followed in the program
 Run time error an error that occurs during the execution of a program. Runtime errors indicate
bugs in the program or problems that the designers had anticipated but could do nothing about e.g
running out of memory will often cause a run time error.

Display output on screen

You might also like