SlideShare a Scribd company logo
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

DOCX
Programming Fundamentals lecture 4
PPTX
datatypes and variables in c language
PPT
Variables in C Programming
PPTX
C Token’s
PPTX
Variables, Data Types, Operator & Expression in c in detail
PPT
C program compiler presentation
PDF
CP Handout#3
PDF
Learn C# Programming - Operators
Programming Fundamentals lecture 4
datatypes and variables in c language
Variables in C Programming
C Token’s
Variables, Data Types, Operator & Expression in c in detail
C program compiler presentation
CP Handout#3
Learn C# Programming - Operators

What's hot (18)

PPTX
Precedence and associativity (Computer programming and utilization)
PPT
pointer, structure ,union and intro to file handling
PDF
Assignment2
PDF
CP Handout#2
PPT
Getting Started with C++
PPT
Ch2 introduction to c
PPT
Types of c operators ppt
PDF
Learning the C Language
PPTX
Keywords in c language
PDF
Python Programming
PDF
CP Handout#1
PPTX
Overview of C Mrs Sowmya Jyothi
DOCX
Programming Global variable
PPTX
Sample for Simple C Program - R.D.Sivakumar
PPTX
LISP: Declarations In Lisp
PPTX
Operators and expressions in c language
PPT
Types of operators in C
Precedence and associativity (Computer programming and utilization)
pointer, structure ,union and intro to file handling
Assignment2
CP Handout#2
Getting Started with C++
Ch2 introduction to c
Types of c operators ppt
Learning the C Language
Keywords in c language
Python Programming
CP Handout#1
Overview of C Mrs Sowmya Jyothi
Programming Global variable
Sample for Simple C Program - R.D.Sivakumar
LISP: Declarations In Lisp
Operators and expressions in c language
Types of operators in C
Ad

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

PDF
Programming concepts By ZAK
PPTX
ADA programming language
PPT
VHDL lecture 2.ppt
PPTX
13.1 User-defined data types.pptx
PPTX
data types in C programming
PDF
cassignmentii-170424105623.pdf
PPTX
Hema wt (1)
PDF
Modula 2 tutorial - 005 - statements
PDF
Using Variables in Programming
PPTX
PF 2- Data Types and Veriables (1).pptx
PPT
Pemrograman komputer 3 (representasi data)
PDF
Using Variables in Programming
PPTX
Bsc cs i pic u-2 datatypes and variables in c language
PPTX
Diploma ii cfpc u-2 datatypes and variables in c language
PPTX
C programming Tutorial Session 2
PPTX
Modula-2 tutorial - 002 - modules
PDF
Using Variables in Programming
PPTX
Mca i pic u-2 datatypes and variables in c language
PPTX
Btech i pic u-2 datatypes and variables in c language
PDF
Embedded C - Lecture 2
Programming concepts By ZAK
ADA programming language
VHDL lecture 2.ppt
13.1 User-defined data types.pptx
data types in C programming
cassignmentii-170424105623.pdf
Hema wt (1)
Modula 2 tutorial - 005 - statements
Using Variables in Programming
PF 2- Data Types and Veriables (1).pptx
Pemrograman komputer 3 (representasi data)
Using Variables in Programming
Bsc cs i pic u-2 datatypes and variables in c language
Diploma ii cfpc u-2 datatypes and variables in c language
C programming Tutorial Session 2
Modula-2 tutorial - 002 - modules
Using Variables in Programming
Mca i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c language
Embedded C - Lecture 2
Ad

Recently uploaded (20)

PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
Empowerment Technology for Senior High School Guide
PDF
RMMM.pdf make it easy to upload and study
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
1_English_Language_Set_2.pdf probationary
PDF
Indian roads congress 037 - 2012 Flexible pavement
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Classroom Observation Tools for Teachers
Orientation - ARALprogram of Deped to the Parents.pptx
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
History, Philosophy and sociology of education (1).pptx
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
A systematic review of self-coping strategies used by university students to ...
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Paper A Mock Exam 9_ Attempt review.pdf.
Empowerment Technology for Senior High School Guide
RMMM.pdf make it easy to upload and study
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
What if we spent less time fighting change, and more time building what’s rig...
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Hazard Identification & Risk Assessment .pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
1_English_Language_Set_2.pdf probationary
Indian roads congress 037 - 2012 Flexible pavement
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Classroom Observation Tools for Teachers

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/