Pascal. Basic constructions of Pascal language





Basic constructions of Pascal language


Contents


Search other websites:

1. The character set used in Pascal

Pascal, like any other language, uses a character set. Each character has its own ASCII code. In Pascal, the following characters are used:

  • 1. Uppercase and lowercase letters of the Latin alphabet
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  • 2. Underscore _
  • 3. Arabic decimal digits
0 1 2 3 4 5 6 7 8 9
  • 4. Special symbols
# $ ' ( ) * + , _ . / : ; < = > @ [ ] ^ { }
  • 5. The space character ‘ ‘.
  • 6. Control characters with codes from 0 to 31

 

2. The concept of a lexema. Categories of lexemas. Picture

A Pascal program consists of lexemas. A lexema is the smallest significant unit of program text. Categories of lexemas are shown in Figure 1.

Categories of Pascal lexemas

Figure 1. Categories of Pascal lexemas

 

3. Reserved words of Pascal

Some of the words in Pascal are keywords or reserved words. This means that you cannot use these words as the names (identifiers) of variables, constants, procedures, functions, and the like. The list of reserved words is as follows:

ABSOLUTE     EXPORTS          LIBRARY     SET
ASSEMBLER    EXTERNAL         MOD         SHL
AND          FAR              NAME        SHR
ARRAY        FILE             NIL         STRING
ASM          FOR              NEAR        THEN
ASSEMBLER    FORWARD          NOT         TO
BEGIN        FUNCTION         OBJECT      TYPE
CASE         GOTO             OF          UNIT
CONST        IF               OR          UNTIL
CONSTRUCTOR  IMPLEMENTATION   PACKED      USES
DESTRUCTOR   IN               PRIVATE     VAR
DIV          INDEX            PROCEDURE   VIRTUAL
DO           INHERITED        PROGRAM     WHILE
DOWNTO       INLINE           PUBLIC      WITH
ELSE         INTERFACE        RECORD      XOR
END          INTERRUPT        REPEAT
EXPORT       LABEL            RESIDENT

 

4. Special characters. List

In Pascal to special characters include the following:

+ – * / < = > [ ] ( ) { } . , : ; ^ @ # $

 

5. Names (identifiers). What are the requirements put to the definition of names in Pascal? Examples of names.

Name – this is a sequence of letters and numbers, that is begun from letter. In the names can be used the underline symbol. The name can contain any number of characters, but meaningful have the first 63 characters.

An examples of names in Pascal:

A
b12
r1m
SIGMA
gamma
I80_86

 

6. Labels

In a program, individual command lines can be marked with labels. Labels are divided into numeric and symbolic. A numeric label is a set of numbers in the range 0 to 9999. In the program text, the label is separated from the identifier by the symbol : (colon).

Examples of labels in the program.

25: x := 28; // label 25
...
sum: z := x+y; // label with the name 'summ'
...
A1: z:= x-y; // label with the name 'A1'

 

7. Numbers

In Pascal, the following types of numbers are used:

  • decimal integers;
  • integer hexadecimal numbers;
  • real decimal numbers.

Examples of numbers: 255, 2.85, 1E8, -1E-2, 1000, $B5.

 

8. What words must not be used as names in Pascal?

You can not use as names the functional words and standard names, for which are named the standard constants, types, procedures, functions and files.

For example: begin, and, label, for, repeat, integer, real, implementation and others (see p.3).

 

9. Examples of recording the integers in decimal and hexadecimal systems.

In most cases the numbers in Pascal is written in the decimal system. However, you can also write the integers in hexadecimal system. To write the number in hexadecimal system, you need to use the character ‘$’ before the number.

An examples of using the numbers in decimal system:

217
-45
8954
+483

An examples of using the numbers in hexadecimal system:

$7F
$40
$ABCD

 

10. How the character values are represented in Pascal?

The separate character constant – this is a symbol of the allowable character set specific computer.

A character constant can be written in the program in two ways:

1. As one character disposed between apostrophes, for example:

'A'
'a'
'5'

2. With the help of construction of type #K, where K – the corresponding symbol code, while the value of K should be between 0..255. For example, the character constant ‘R‘ you can write as #82.

 

11. Strings

In Pascal, a string is a sequence of characters enclosed in single quotes. This sequence should be placed on one line. If a single quote character is to be included in the string, this character is indicated twice in a row . An empty string is a character-free string .

Examples of strings

'Hello world!'
'This doesn''t work.'

 

12. Comments

Comments allow you to describe the course of solving the problem in verbal, understandable to humans, form. It is considered a good programming style if the program contains comments describing its operation. In the program, comments perform an informational function. A program containing comments is later easier to maintain and modify.

Pascal distinguishes 3 types of comments:

  • single line comment. It is designated by symbols //. This comment starts with // and continues to the end of the current line.
  • multi-line comment. It is denoted by single characters { }. This comment is valid from the character {to the character} and can be placed on several lines
  • a multi-line comment that is placed between compound characters (* and *).

Comment examples

// single line comment

{
multi-line
comment
}

(* another
multi-line
comment *)

 

13. Identifiers of directives. List

Directive identifiers (procedural directives) refer to standard predefined identifiers. They also refer to reserved words. The directive identifiers are as follows:

absolute
assembler
export
external
far
forward
index
interrupt
near
private
public
resident
virtual

 

14. What are lexemas delimiters? Examples

The following characters are used as lexemas delimiters:

  • space (ASCII code 32);
  • tabulation (ASCII code 09);
  • compound character of transition to the beginning of the next line. This character consists of a pair of characters: carriage return (ASCII code 13) and newline (ASCII code 10).

 

15. What are delimiters?

In Pascal, the following delimiters can be distinguished:

. , ' ( ) [ ] (. .) { } (* *) .. : ;

 


Related topics