Appendix 11--Modula-2 and Pascal

This information is included for the benefit of those who are coming to the Modula-2 language from Pascal. Only the differences between the two languages are shown. Since there are many versions of Pascal, the information here may not be correct for a given version.

A11.1 Statement Syntax Differences

: :
Modula-2Pascal
FOR i := S TO N [BY M] for i := S [down]to N do
DO statement sequence END; <compound> statement
WHILE .. DO .. END; while .. do .. ;
LOOP .. {EXIT} .. END; n/a
RETURN (* Required in function procedure,
optional in regular procedure *)
n/a
IF .. THEN .. if .. then
{ELSIF .. THEN ..} [else ..]
[ELSE ..]
END;
CASE labels:
constant expressions or ranges must be constants
ELSE available; no else available
delimiter is |
RECORDS:
Any number or order of variants in record one variant at end of record
WITH unqualifies one level with can unqualify many levels
NEW, DISPOSE must be translated to NEW, DISPOSE execute directly
functions [DE]ALLOCATE

A11.2 Symbols

Modula-2 Pascal
Not equals <> or # <>
Conjunction AND or & and
Comment delimiters (* *) (* *) or { }
Quotation marks ' or " ' only
Character constants literal or <octal>C literal only
Decimal explicit may be implicit
Scale factor E E or e
Set delimiters { .. } [ .. ]
Subrange delimiters [ .. ] n/a
Statement delimiter ;* ;
Case delimiter |* ;
Dereferencing operator ^ (not in declaration) ^ (also in declaration)
Set operations IN,INCL,EXCL,+,-,*,/ IN,+,-
Symbols for octal, hex
and char constants B, H, C n/a
* may be superfluous

A11.3 Overall Structure

Modula-2 Pascal
Modules yes no
Regular Procedures yes yes
Function Procedures PROCEDURE function
Separate Compilation yes not usually
Low-level facilities yes no
Coroutines yes no
Compound Statements statement sequence begin .. end
Comment Nesting yes no
Ranges used by name yes no
Control transfer EXIT, RETURN goto
I/O Statements imported type specific (general) read[ln], write[ln]
General Syntax:
Program Heading MODULE name; PROGRAM Name (I/O list);
Program Ending END name. end.
Import Lists any number n/a
Export lists only one n/a
Declaration order any order const, type, var, procedures
Reserved words, upper case any case
Standard identifiers upper case any case
Constant expressions
in Declaration
yes no
Identifiers - case sensitive insensitive
- length unlimited usually limited
Predefined types CARDINAL n/a
INTEGER integer
REAL, LONGREAL real
COMPLEX, LONGCOMPLEX n/a
CHAR char
POINTER pointer
BOOLEAN boolean
ARRAY array
RECORD record
PACKEDSET n/a
PROC n/a
SYSTEM.LOC n/a
Type coercion SYSTEM.CAST no
Procedures as variables yes no
Scalar type arithmetic INC (s), INC (s,n),
DEC (s), DEC (s,n) pred, succ
function declaration PROCEDURE name Function name
({params}): resultType {(params)}: resultType
Calls to parameterless
functions
empty parameter list required no parameter list
Mutual recursion FORWARD in one-pass compilers forward is required
Boolean expression
evaluation Short-circuted whole expression
Mixed expressions not allowed often allowed
Open arrays using
generic LOC allowed not allowed
Explicit SET typing yes no
Packing ARRAY OF CHAR automatic explicitly done
Multiple range [a..b],[c..d] {a..b,c..d}
inverse of ORD VAL only for CHR
Terminate program HALT use goto
capitalization CAP n/a
Round off TRUNC (x+.5) round (x)
NIL standard identifier reserved word
Exceptions available n/a
Termination can be trapped & handled n/a

Contents