Course : INTRODUCTION TO PASCAL / PDF
Course : INTRODUCTION TO PASCAL / PDF
Sample of the PDF document
INTRODUCTION
A Pascal program is usually represented as a plain text (ASCII) file, i.e., a sequence of (ASCII or keyboard) characters. Such a file is called a Pascal source file. This file is then transformed by a Pascal compiler into an executable file which is a set machine instructions that are executed or run by the operating system of the computer. The general process of creating, compiling, and running a program is as follows :
1. Create a source program file using a plain text editor
2. Transform or compile the source program into an executable program file using a compiler.
3. Run the executable program using the operating system.
Let us look at a simple Pascal program to find the area of a rectangle whose width is w and whose height is h.
program AreaRect;
var
h, w, area : REAL;
begin
h := 12.5;
w := 5.0;
area : h * w;
Writeln('The height of the rectangle is : ', h);
Writeln('The width of the rectangle is : ', w);
Wri
Lexical Elements
The ASCII characters of a Pascal source file are grouped into 4 categories :
1. Letters : a,b,...,z,A,B,...,Z.
2. Digits : 0,1,2,3,4,5,6,7,8,9
3. Special : - * ( ) % $ + = g etc.
4. Control : non-printable
Tokens
The characters of a source file are grouped into tokens which are separated by at least one space (blank). No spaces are allowed within tokens except for string constants (see below).
Thus tokens are strings of characters with no spaces.
The tokens of a Pascal program are classified into 6 categories :
1. one and two character symbols.
2. reserved words
3. identifiers
4. numbers
5. character and string literals
Symbols
One-Character +, - , *, /, =, <, >, f g ( ) [ ] , ; : ^
and
Two-Character :=, <=, >=, <>, ..
Reserved Words Strings of alphabetic characters that have special meaning within Pascal.
The following are some of the reserved words
array, begin, const, do, end, for ,if, of,
procedure, then, to, type, var, while
Identifiers These are tokens that ‘name’ various elements in Pascal. They are strings of letters
and digits that must begin with a letter. Examples are : Alpha, x, i, X2x, Three3Four4.
We note that Pascal does not distinguish between upper-case and lower-case letters,i.e., the identifier alpha is the same as ALPHA.
Numbers
123, -45877, 23.45, -0.001
Character and String Literals
Anything enclosed with quotes.
’This is a literal’, ’2334’, ’A’. Note that a blank is significant in a sting literal
Course : INTRODUCTION TO PASCAL / PDF
0 commentaires: