SlideShare a Scribd company logo
1 of 7
Download to read offline
Modula-2
ISO/IEC 10514
programming language tutorial
Declarations
Julian Miglio 2019
Declarations rules
IMPLEMENTATION MODULE MyModule;
CONST
TYPE
VAR
Constants declaration
Types declaration
Variables declaration
PROCEDURE MyProc;
CONST
TYPE
VAR
Constants declaration
Types declaration
Variables declaration
Every identifier occurring in a program must be introduced by a declaration, unless it is a standard identifier.
Declarations also specify certain permanent properties of an object, such as whether it is a constant, a type, a variable, a
procedure, or a module. The identifier is then used to refer to the associated object.
Julian Miglio 2019
BEGIN
END MyModule.
Procedures declaration
BEGIN
END MyProc;
Procedures declaration
Constants declaration
CONST
One = 1;
Pi = 3.14159;
PiOver2 = Pi / 2.0;
Debug = TRUE;
Integer constant
Floating point constant
Floating point constant
Boolean constant
Constants are objects that have a specific value assigned at compile time. Constants cannot change during the execution of the
program. For simple types, value is an expression giving the value of the constant. The expression must be made up of constants
only, so that the compiler can evaluate it at compile time. It is also possible declare constants of array and record types.
Julian Miglio 2019
Debug = TRUE;
Message = "That's not right!";
Boolean constant
String constant
Types declaration
TYPE
Integer = INTEGER;
SmallInt = [-10..10];
Color = (Red, Green, Blue);
CharPointer = POINTER TO CHAR;
ColorSet = SET OF COLOR;
String = ARRAY [0..255] OF CHAR;
Integer type
Pointer type
Set type
Array type
Subrange type
Enumeration type
A data type determines a set of values which variables of that type may assume, and it associates an identifier with the type.
In the case of structured types, it also defines the structure of variables of this type. There are three different structures, namely
arrays, records, and sets. Standard types are: INTEGER, CARDINAL, BOOLEAN, REAL, CHAR, POINTER.
There are other useful types exported by the module SYSTEM that specified the machine size such as CARD16, INT16, CARD32,
INT32, BYTE, WORD and others.
Julian Miglio 2019
Complex = RECORD A,B : REAL; END;
RealFunc = PROCEDURE(REAL) : REAL;
Record (structure) type
Procedure type
Variables declaration
VAR
I, J : INTEGER;
MAT : ARRAY [1..3],[1..3] OF REAL;
BackGround, ForeGround : Color;
PossibleColors : SET OF Color;
RecordPointer : POINTER TO RecType;
Integer variable
Set variable
Pointer to record variable
Array variable
Enumeration variable
Variable declaration is the definition and allocation of memory of a particular type. The data type determines the set of values
that a variable may assume and the operators that are applicable to it, it also defines the structure of the variable.
Each of the identifiers to the left of the colon is declared as a variable of the type that is specified to the right of the colon.
Julian Miglio 2019
Procedures and functions declaration
PROCEDURE Error;
BEGIN
WriteString('ERROR');
END Error;
PROCEDURE tan(x : REAL) : REAL;
BEGIN
RETURN sin(x) / cos(x);
END tan;
Function with an input parameter and a return
parameter
Procedure without parameters
Procedure declarations consist of a procedure heading and a block. The heading specifies the identifier and the formal
parameters, the block contains other declarations and executable statements. There are two kinds of procedures: procedures and
functions. The first is activated by a procedure call, while the second is called in an expression and returns a value.
Procedures are sequences of instructions that perform a specific task. Usually, procedures are used when the same sequence of
code is required more than once in a program. In this case, the procedure is written once and is called from several places.
Julian Miglio 2019
PROCEDURE tan(x : REAL) : REAL; FORWARD; Forward declaration
Reference
• Modula-2: Abstractions for Data and Programming Structures:
http://www.arjay.bc.ca/Modula-2/Text/index.html
• ISO/IEC 10514 Modula-2, Base Language: https://www.iso.org/standard/18583.html
• Modula2.org: https://www.modula2.org/
Julian Miglio 2019
• Modula2.org: https://www.modula2.org/

More Related Content

What's hot

Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)Digvijaysinh Gohil
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingRai University
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
Types of c operators ppt
Types of c operators pptTypes of c operators ppt
Types of c operators pptViraj Shah
 
Keywords in c language
Keywords in c languageKeywords in c language
Keywords in c languageJoydeep16
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiSowmya Jyothi
 
Programming Global variable
Programming Global variableProgramming Global variable
Programming Global variableimtiazalijoono
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSivakumar R D .
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c languagetanmaymodi4
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in CPrabhu Govind
 

What's hot (18)

Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)Precedence and associativity (Computer programming and utilization)
Precedence and associativity (Computer programming and utilization)
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 
Assignment2
Assignment2Assignment2
Assignment2
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 
Getting Started with C++
Getting Started with C++Getting Started with C++
Getting Started with C++
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
Unit ii ppt
Unit ii pptUnit ii ppt
Unit ii ppt
 
Types of c operators ppt
Types of c operators pptTypes of c operators ppt
Types of c operators ppt
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
Keywords in c language
Keywords in c languageKeywords in c language
Keywords in c language
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
CP Handout#1
CP Handout#1CP Handout#1
CP Handout#1
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
 
Programming Global variable
Programming Global variableProgramming Global variable
Programming Global variable
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.Sivakumar
 
LISP: Declarations In Lisp
LISP: Declarations In LispLISP: Declarations In Lisp
LISP: Declarations In Lisp
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Types of operators in C
Types of operators in CTypes of operators in C
Types of operators in C
 

Similar to Modula 2 tutorial - 003 - declarations

PPT ON VHDL subprogram,package,alias,use,generate and concurrent statments an...
PPT ON VHDL subprogram,package,alias,use,generate and concurrent statments an...PPT ON VHDL subprogram,package,alias,use,generate and concurrent statments an...
PPT ON VHDL subprogram,package,alias,use,generate and concurrent statments an...Khushboo Jain
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptxmadhurij54
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniquesvalarpink
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxKrishanPalSingh39
 
434090527-C-Cheat-Sheet. pdf C# program
434090527-C-Cheat-Sheet. pdf  C# program434090527-C-Cheat-Sheet. pdf  C# program
434090527-C-Cheat-Sheet. pdf C# programMAHESHV559910
 
Introduction to c
Introduction to cIntroduction to c
Introduction to cAjeet Kumar
 
CSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdfCSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdfssusera0bb35
 
C-Programming Chapter 1 Fundamentals of C.ppt
C-Programming Chapter 1 Fundamentals of C.pptC-Programming Chapter 1 Fundamentals of C.ppt
C-Programming Chapter 1 Fundamentals of C.pptMehul Desai
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...RSathyaPriyaCSEKIOT
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdfAdiseshaK
 

Similar to Modula 2 tutorial - 003 - declarations (20)

PPT ON VHDL subprogram,package,alias,use,generate and concurrent statments an...
PPT ON VHDL subprogram,package,alias,use,generate and concurrent statments an...PPT ON VHDL subprogram,package,alias,use,generate and concurrent statments an...
PPT ON VHDL subprogram,package,alias,use,generate and concurrent statments an...
 
Computer programming questions
Computer programming questionsComputer programming questions
Computer programming questions
 
Computer programming questions
Computer programming questionsComputer programming questions
Computer programming questions
 
Pc module1
Pc module1Pc module1
Pc module1
 
Programming-in-C
Programming-in-CProgramming-in-C
Programming-in-C
 
Hd6
Hd6Hd6
Hd6
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptx
 
VHDL lecture 2.ppt
VHDL lecture 2.pptVHDL lecture 2.ppt
VHDL lecture 2.ppt
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptx
 
434090527-C-Cheat-Sheet. pdf C# program
434090527-C-Cheat-Sheet. pdf  C# program434090527-C-Cheat-Sheet. pdf  C# program
434090527-C-Cheat-Sheet. pdf C# program
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
CSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdfCSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdf
 
C-Programming Chapter 1 Fundamentals of C.ppt
C-Programming Chapter 1 Fundamentals of C.pptC-Programming Chapter 1 Fundamentals of C.ppt
C-Programming Chapter 1 Fundamentals of C.ppt
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
 
C programming notes
C programming notesC programming notes
C programming notes
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdf
 

Recently uploaded

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 

Recently uploaded (20)

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

Modula 2 tutorial - 003 - declarations

  • 1. Modula-2 ISO/IEC 10514 programming language tutorial Declarations Julian Miglio 2019
  • 2. Declarations rules IMPLEMENTATION MODULE MyModule; CONST TYPE VAR Constants declaration Types declaration Variables declaration PROCEDURE MyProc; CONST TYPE VAR Constants declaration Types declaration Variables declaration Every identifier occurring in a program must be introduced by a declaration, unless it is a standard identifier. Declarations also specify certain permanent properties of an object, such as whether it is a constant, a type, a variable, a procedure, or a module. The identifier is then used to refer to the associated object. Julian Miglio 2019 BEGIN END MyModule. Procedures declaration BEGIN END MyProc; Procedures declaration
  • 3. Constants declaration CONST One = 1; Pi = 3.14159; PiOver2 = Pi / 2.0; Debug = TRUE; Integer constant Floating point constant Floating point constant Boolean constant Constants are objects that have a specific value assigned at compile time. Constants cannot change during the execution of the program. For simple types, value is an expression giving the value of the constant. The expression must be made up of constants only, so that the compiler can evaluate it at compile time. It is also possible declare constants of array and record types. Julian Miglio 2019 Debug = TRUE; Message = "That's not right!"; Boolean constant String constant
  • 4. Types declaration TYPE Integer = INTEGER; SmallInt = [-10..10]; Color = (Red, Green, Blue); CharPointer = POINTER TO CHAR; ColorSet = SET OF COLOR; String = ARRAY [0..255] OF CHAR; Integer type Pointer type Set type Array type Subrange type Enumeration type A data type determines a set of values which variables of that type may assume, and it associates an identifier with the type. In the case of structured types, it also defines the structure of variables of this type. There are three different structures, namely arrays, records, and sets. Standard types are: INTEGER, CARDINAL, BOOLEAN, REAL, CHAR, POINTER. There are other useful types exported by the module SYSTEM that specified the machine size such as CARD16, INT16, CARD32, INT32, BYTE, WORD and others. Julian Miglio 2019 Complex = RECORD A,B : REAL; END; RealFunc = PROCEDURE(REAL) : REAL; Record (structure) type Procedure type
  • 5. Variables declaration VAR I, J : INTEGER; MAT : ARRAY [1..3],[1..3] OF REAL; BackGround, ForeGround : Color; PossibleColors : SET OF Color; RecordPointer : POINTER TO RecType; Integer variable Set variable Pointer to record variable Array variable Enumeration variable Variable declaration is the definition and allocation of memory of a particular type. The data type determines the set of values that a variable may assume and the operators that are applicable to it, it also defines the structure of the variable. Each of the identifiers to the left of the colon is declared as a variable of the type that is specified to the right of the colon. Julian Miglio 2019
  • 6. Procedures and functions declaration PROCEDURE Error; BEGIN WriteString('ERROR'); END Error; PROCEDURE tan(x : REAL) : REAL; BEGIN RETURN sin(x) / cos(x); END tan; Function with an input parameter and a return parameter Procedure without parameters Procedure declarations consist of a procedure heading and a block. The heading specifies the identifier and the formal parameters, the block contains other declarations and executable statements. There are two kinds of procedures: procedures and functions. The first is activated by a procedure call, while the second is called in an expression and returns a value. Procedures are sequences of instructions that perform a specific task. Usually, procedures are used when the same sequence of code is required more than once in a program. In this case, the procedure is written once and is called from several places. Julian Miglio 2019 PROCEDURE tan(x : REAL) : REAL; FORWARD; Forward declaration
  • 7. Reference • Modula-2: Abstractions for Data and Programming Structures: http://www.arjay.bc.ca/Modula-2/Text/index.html • ISO/IEC 10514 Modula-2, Base Language: https://www.iso.org/standard/18583.html • Modula2.org: https://www.modula2.org/ Julian Miglio 2019 • Modula2.org: https://www.modula2.org/