A Comparison of Pascal

Cours A Comparison of Pascal, tutoriel & guide de travaux pratiques en pdf.

A Comparison of Pascal and Modula-2

Modula-2[1,2] grew out of a practical need for a general, efficiently implementable, systems programming language. Its ancestors are Pascal[3] and Modula[4]. From the latter, it has inherited the name, the important module concept, and a systematic, modern syntax; from Pascal, most of the rest. This includes in particular the data structures, i.e. arrays, records, variant records, sets, and pointers. Structured statements include the familiar IF, CASE, REPEAT, WHILE, FOR, and WITH statements.
This Report reviews the differences between Pascal and Modula-2. It is not intended to teach you how to program in Modula-2. For that purpose, the definitions by Wirth[1, 2] should be consulted.

Identifiers
Identifiers are defined the same as in Pascal. Modula-2, however, is case sensitive. For example, the keyword « IF » is only recognized in its all caps form.

Examples:
x scan starMod firstLetter test1 1.2 Numbers
The Pascal number format is expanded to allow octal and hexadecimal constants to be expressed.
Furthermore, the type CARDINAL is added to explicitly represent unsigned, 16-bit integers, and
LONGINT is provided for 32-bit integers. Some important values for these types are as follows:
MIN( ) MAX( )
INTEGER -32768 32768
CARDINAL 0 65535
LONGINT -2147483648D 2147483647D
REAL -1.0E-35 1.0E+35
A decimal LONGINT constant is different from an INTEGER in that it must have a « D » following the
last digit. Even a very large number must have the D. For an octal or hexadecimal LONGINT, the value of the number must either be too large for an integer or it must have enough leading zeroes to make the number at least six digits long.

Examples:
1980 decimal
3764B octal (denoted by the trailing « B »)
0CADH hexadecimal (denoted by the trailing « H »)
CADH an identifier, not a number
48H hexadecimal, leading zero is not required
236713D decimal LONGINT (denoted by the trailing « D »)
356165B octal LONGINT
000121B octal LONGINT with leading zeroes
36FA51H hexadecimal LONGINT
000029H hexadecimal LONGINT with leading zeroes
REAL numbers are supported in Modula-2 in precisely the same manner as Pascal. All REAL numbers must have a decimal point and must start with a digit; although, digits are not required in the fraction. An exponent field is also supported, but is optional. Following the fraction portion of the REAL number, an « E » must precede the exponent. The exponent has a range from -35 to 35. The unary plus (« + ») can be placed on positive exponents as an option.

LIRE AUSSI :  GAU/SUDO

Examples:
5.32 typical REAL
433. REAL without fraction portion
3.34E-22 REAL with negative exponent
83.28E31 REAL with positive exponent
12.3E+22 also a positive exponent

Characters and strings

Both the double quote character (« ) and single quote (’) may be used as quote marks. However, the
opening and closing marks must be the same character, and this character cannot occur within the string. A string must not extend over the end of a line. A string, consisting of a single-character, is of type CHAR; a string consisting of n>1 characters is of type ARRAY [0..n-1] OF CHAR.
By convention, many of the library modules use the null character, ASCII code 0, to delimit the end of a string. The storage for constant strings ends with the null automatically. Any string that the user creates should end with the null in order to work properly with string functions.
There is also a notation to represent characters that are not in the language’s character set. A sequence of digits terminated with a « C » is interpreted as an octal value of type CHAR. For example, « 123C » has the same value and type as « CHAR(123B) ».

Examples:
« . » ‘.’ 123C « Modula »
« Don’t Worry! » ‘a « quoted » word’

Operators, delimiters, and comments

Operators and delimiters are the special characters, character pairs, or reserved words listed below. The reserved words consist exclusively of capital letters and MUST NOT be used as identifiers. The Modula-2 symbols, which differ from Pascal’s, are listed separately.

Cours gratuitTélécharger le cours complet

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *