Sabtu, 03 Oktober 2009

Introduction to Pascal

Introduction to Pascal

Introduction to Pascal
A Brief History of Pascal
• Designed by Prof.. Nicklaus Wirth from the Technical
University of Zurich, Switzerland in 1971.
• The name comes from Pascal Blaise Pascal, a specialist
mathematics and philosopi from France (17th century).
• Development of language Algol 60 and Algol W
(derivative of Algol 60).
• Have multiple versions, such as: Turbo Pascal, Ms.
Pascal (Microsoft), Apple Pascal, UCSD (University of
California at San Diego Pascal), etc..
• Turbo Pascal made by Borland Inc.. is version
The most widely used because it uses
Compiler to translate it and also follow
Pascal language standards created by Nicklaus Wirth
and K. Jensen.
• Pascal is a high-level programming language
(high level language) and structured (Structured
Programming language).

Structure of Language PASCAL
in common
1. Section Title Programs
2. Declaration Section
• Declaration of data types (TYPE)
• Declaration of variables (VAR)
• Declaration constants (CONST)
• Declaration label (LABEL)
• Declaration of sub-programs (PROCEDURE and
FUNCTION)
3. Section Main Program Statement.

Rules Prgram
• Each end of the semicolon terminated statement
(;), Except for the name of the label.
• End the program were given a period (.).

Comments
• Is the information given to
documentation purposes.
• Not result in action (not
influence the course of the program).
• Can use the sign:
(This comment) or (* this comment *)

Basic Commands / Simple Pascal
• Write ( 'Text / writing', variable);
Command to display or print
the monitor screen without moving the line
• WriteLn ( 'Text / Writing', variable);
Command to display / print screen
monitor and move the line down
• Read (variable);
Command to enter / fill data
without moving the line
• readln (variable);
Command to enter / fill data
then move the line




Basic Pascal
Programming elements
• Obtain data by reading data from
The default input (key board, files or data source
others).
• Storing data into memory with
appropriate data structures,
• Processing the data with the right instruction.
• Presenting or sending the data processed
the default output (monitor, file, or destination
others).

Identifier
• Public Identifier
Identifier is defined solely by
programmers. Programmers have the freedom
to determine the name identifiernya, with
conditions are not the same name with the identifier
standards and reserved word that will be discussed
further. This is to prevent errors
that could arise due to overlapping identifier
program

Terms of General Identifier
• Beginning with the letter
• There should be no spaces / blank
• May not use a reserved word
• May not use a special symbol,
except an underscore (sign below)
• 63 character maximum length

Examples of public Identifier
• Luas_Segi_Tiga
• LuasSegiTiga
• LuasS3
• LS3

Identifier
• Standard Identifier (Baku)
Identifier is defined by
Pascal compiler makers. Usually maker
compiler provides a library that has
There in the compiler. Library contains a variety of
procedure, function or unit that is ready to use.
Eg Windows Turbo Pascal 1.5 has a
unit to process the output of wincrt, gotoxy,
which can easily be used by programmers
in the writing program codes

Sample Standard Identifier
• abs int cos arctan dispose boolean eof
exp false eoln integer input new maxint ln
odd output Ord Pred pack page read readln
reset rewrite real sin sqr sqrt round succ
trunc true text write writeln


Identifier reserved word
• Identifier "reserved word", ie the
already defined and used by
PASCAL language itself (We can not
identifier naming us with this).



Sample Identifier Reserved word
and array begin case const div do downto
end else files for forward function goto if in
label mod nil not of or packed procedure
program record repeat set then to type
until var while with

Variable Declaration:
• Variable Declaration:
Declaring variables is:
a. Variable name as the identity
identifier
b. Determining the type of variable data
• Examples of variable declarations:
Var K: integer;
R: real;
C: char;
Q: boolean;

Similar variables
• Some similar identivier
can be declared together.
• Example var i, j, k: integer; (variable i,
j and k as an integer)
namaMHS, alamatMHS: char;
(Name and address of the student)

Constant
• Constant Declaration:
Declaring constants are:
a. Providing a constant as
user ID
b. Determining the value of the constant
• Examples of constant declarations:
const MaximumSize = 100; (integer)
Exit = 'Q'; (char)

Type Declaration
Identifier (identifier) of the data
type used should be introduced.
If you want to use the data type
name created by the user, then
should be mentioned standard data types.

Example of the Type
• Sample type
Type
Nm: String [25];
Kls: String [7];
Nil: Integer;
Gr: Char;
Var
Name: Nm;
Class: Kls;
Value: Nil;
Grade: Gr;

Sample No Type
Var Name: String [25];
Class: String [7];
Value: Integer;
Grade: Char;



Example programs:
TAMBAH_00 programs; (Sum
two numbers whose value is given
in order)
var angka1, angka2, result: integer; (
Declaration of variables as integers)
BEGIN (Main Program Start)
angka1: = 50; (command gives the value
50 in var. angka1)
angka2: = 25; (command gives the value
25 in var. angka2)
result: = angka1 + angka2; (Commands
outcome add up and save
the results)
Write (result); (command to print the results)
END. (End of Main Program)

Sample Program 2
TAMBAH_01 programs; (Menjumlahlan
two numbers are read from
default input)
bilbulat type: integer;
var angka1, angka2, results: bilbulat; (
Declaration as integer)
BEGIN (Main Program Start)
read (angka1); (Reading angka1 value
through the key-board)
read (angka2); (Reading angka2 value
through the key-board)
result: = angka1 + angka2; (Sum
and save the results to the results)
write (result); (Presenting the results to the screen
monitor)
END. (End of Main Program)

Ditulis Oleh : Admin // 11.14
Kategori:

0 komentar: