TSMODUL1.PDF

(1174 KB) Pobierz
L
ANGUAGE
AND
L
IBRARY
R
EFERENCE
1
TopSpeed
®
Modula-2
For IBM
®
Personal Computers and Compatibles
Language and Library
Reference
TopSpeed Corporation
2
T
OP
S
PEED
M
ODULA
-2™
Copyright
©
1990-1991, by TopSpeed Corporation. All rights reserved.
TopSpeed
®
is a registered trademark of TopSpeed Corporation.
Other brand or product names are trademarks or registered trademarks of their respective holders.
Printed in the United Kingdom.
10
9
8
7
6
5
4
3
2
1
L
ANGUAGE
AND
L
IBRARY
R
EFERENCE
3
Contents
C
HAPTER
1
I
NTRODUCTION
...................................................... 20
Manual Structure .................................................................................................21
Typographic Conventions ..............................................................................21
Modula-2 Syntax and Semantics.........................................................................23
Syntax............................................................................................................23
Static Semantics ............................................................................................23
Dynamic Semantics .......................................................................................23
The TopSpeed Implementation of Modula-2 ..................................................24
Textual Topics ......................................................................................................25
Tokens ...........................................................................................................25
Keywords .......................................................................................................25
Delimiters .......................................................................................................26
Generic tokens ..............................................................................................26
Separators .....................................................................................................27
Syntax Descriptions .......................................................................................28
Declarations and Visibility....................................................................................30
Alias Declarations ..........................................................................................31
Predefined Identifiers .....................................................................................31
Types ...................................................................................................................32
Numeric Types ...............................................................................................32
Ordinal Types .................................................................................................33
Subrange Types .............................................................................................33
Set Types .......................................................................................................34
Array Types ....................................................................................................34
Record Types .................................................................................................35
Pointer Types .................................................................................................36
Type Compatibility .........................................................................................37
Objects and Values .............................................................................................38
4
T
OP
S
PEED
M
ODULA
-2™
Constants ......................................................................................................38
Set Values ......................................................................................................39
Designators ...................................................................................................40
Expressions.........................................................................................................41
Statements ..........................................................................................................43
Assignment Statement ..................................................................................43
IF Statement ..................................................................................................43
CASE Statement ...........................................................................................44
WHILE Statement ..........................................................................................44
REPEAT Statement .......................................................................................44
LOOP Statement ...........................................................................................45
FOR Statement ..............................................................................................45
WITH Statement ............................................................................................46
GOTO Statement ...........................................................................................46
Procedures ..........................................................................................................47
Bodies............................................................................................................47
External Procedures ......................................................................................49
Calling Procedures ........................................................................................49
Procedure Types ............................................................................................50
Predefined Procedures ..................................................................................51
Modules...............................................................................................................54
Server Module ...............................................................................................54
Importing .......................................................................................................56
Local Module .................................................................................................57
C
HAPTER
3
O
BJECT
-
ORIENTED
E
XTENSIONS
.............................. 58
What is Object Oriented Programming?..............................................................59
Encapsulation ................................................................................................59
Inheritance .....................................................................................................60
Polymorphism ................................................................................................61
Class Declarations ..............................................................................................63
Class Interface Declarations ..........................................................................63
Class Implementation Declarations ...............................................................64
L
ANGUAGE
AND
L
IBRARY
R
EFERENCE
5
Declaring Class Variables ..............................................................................66
Invoking Methods...........................................................................................67
Inheritance ..........................................................................................................68
Over-riding Methods ......................................................................................69
Invoking a Base Class Method ......................................................................70
Multiple Inheritance .......................................................................................70
Aliasing ................................................................................................................72
Compatibility Rules .............................................................................................73
The Checked Guard Operator .......................................................................74
The IS Operator...................................................................................................76
Virtual and Static Methods ..................................................................................78
Virtual Methods .............................................................................................78
Static Methods ...............................................................................................79
Case Study ..........................................................................................................83
C
HAPTER
4
L
IBRARY
S
UMMARY
.............................................. 91
Overview .............................................................................................................92
Library Summary .................................................................................................93
BiosIO — (DOS Only) ...................................................................................93
Dev — (OS/2 Only) .......................................................................................93
Dos — (OS/2 Only) .......................................................................................93
Err — (OS/2 Only) ........................................................................................93
FIO — ...........................................................................................................94
FIOR — ........................................................................................................94
FloatExc — ...................................................................................................94
FormIO ..........................................................................................................94
Isp — (OS/2 Only) ........................................................................................94
Gpi — (OS/2 Only) .......................................................................................95
Graph.............................................................................................................95
IO ...................................................................................................................95
Kbd — (OS/2 Only) .......................................................................................96
Lib — ............................................................................................................96
LIM.................................................................................................................96
Zgłoś jeśli naruszono regulamin