Modula 2 - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Modula 2

Description:

Ordinal Types: bijection with natural numbers. Reals: approx. ... Wrench : device to loose or fasten bolts. RECORD example. TYPE. Date = RECORD. Day : [1. ... – PowerPoint PPT presentation

Number of Views:168
Avg rating:3.0/5.0
Slides: 23
Provided by: dtwma
Category:
Tags: fasten | modula

less

Transcript and Presenter's Notes

Title: Modula 2


1
Chapter 2.6
  • Modula 2
  • Structured Types

2
Types in Modula 2
  • Simple Types values cant be decomposed
  • Ordinal Types bijection with natural numbers
  • Reals approx. representation for real values
  • Pointers addresses in data memory
  • Structured Types Values have components
  • Arrays all components have same type
  • Records components can have types
  • Sets small sets of ordinal values
  • Procedures entire subprograms

3
Types in Modula 2
  • Simple Types values cant be decomposed
  • Ordinal Types bijection with natural numbers
  • Reals approx. representation for real values
  • Pointers addresses in data memory
  • Structured Types Values have components
  • Arrays all components have same type
  • Records components can have types
  • Sets small sets of ordinal values
  • Procedures entire subprograms

4
ARRAY type
ARRAY type
index type
component type
5
ARRAY element
array element
array variable designator
index expression
6
ARRAY applications
Mon
Sun
Sat
Fri
Thu
Wed
Tue
8
info.
9
st.pr.
info.
10
st.pr.
info.
11
st.pr.
info.
12
13
14
15
teleN
16
teleN
17
st.pr.
18
teleE
st.pr.
19
teleE
st.pr.
7
ARRAY applications
TYPE Day (Mon,Tue,Wed,Thu,Fri,Sat,Sun) H
our 8..19 Course ARRAY0..10 OF
CHAR Schedule ARRAY Day, Hour OF
Course VAR RoomK1 Schedule BEGIN ... Roo
mK1Wed,8 "info." ... END
8
Sieve of Eratosthenes
Print all primes lt Max
Make a set of cardinals 2 lt x lt MAX
FOR all cardinals present in set
Print the first cardinal x remaining in the set
Remove all multiples of x from the set
9
Sieve of Eratosthenes
Make a set of cardinals 2 lt x lt MAX
CONST Max 1000 VAR Sieve ARRAY2..Max
OF BOOLEAN i 2..Max .. . FOR i 2
TO MAX DO Sievei TRUE END ( FOR )
10
Sieve of Eratosthenes
FOR all cardinals present in the set
Print the first cardinal in the set
Remove all multiples of it
VAR p CARDINAL .. . FOR i 2 TO Max DO
IF Sievei THEN p i
WriteCard(p,5) WriteLn
WHILE p lt Max DO
Sievep FALSE p
p i END ( WHILE )
END ( IF ) END ( FOR )
11
Types in Modula 2
  • Simple Types values cant be decomposed
  • Ordinal Types bijection with natural numbers
  • Reals approx. representation for real values
  • Pointers addresses in data memory
  • Structured Types Values have components
  • Arrays all components have same type
  • Records components can have types
  • Sets small sets of ordinal values
  • Procedures entire subprograms

12
Repairing a flat tireRefinement of tools
  • Tools
  • Jack device to lift a car
  • Wrench device to loose or fasten bolts

13
RECORD example
14
RECORD type
field list
fields
fixed fields
field type
15
RECORD element
WITH Today DO Day 20 Month 10
Year 1998 END
Today.Day 20 Today.Month 10 Today.Year
1998
16
Nested RECORDs example (1)
TYPE Date RECORD Day
1 .. 31 Month 1 ..
12 Year 1900 .. 2100
END String ARRAY 0..29 OF
Char Identity RECORD
Name, FirstName String
BirthPlace String
BirthDate Date
IssueDate Date END VAR
Myself Identity Today Date
17
Nested RECORDs example (2)
Today.Day 20 Today.Month
10 Today.Year
1998 Myself.Name
"Tiberghien" Myself.FirstName
"Jacques" Myself.BirthPlace
"Berchem" Myself.BirthDate.Day
1 Myself.BirthDate.Month 4 Myself.BirthDate.Y
ear 1946 Myself.IssueDate Today
18
Nested RECORDs example (2)
WITH Today DO Day 20
Month 10 Year
1998 END WITH Myself DO Name
"Tiberghien" FirstName "Jacques"
BirthPlace "Berchem" WITH
BirthDate DO Day 1
Month 4 Year 1946
END IssueDate Today END
19
Variant RECORDs
variant fields
variant list
variant
20
Variant RECORDwith explicit tag field
21
Variant RECORDwith implicit tag field
22
Types in Modula 2
  • Simple Types values cant be decomposed
  • Ordinal Types bijection with natural numbers
  • Reals approx. representation for real values
  • Pointers addresses in data memory
  • Structured Types Values have components
  • Arrays all components have same type
  • Records components can have types
  • Sets small sets of ordinal values
  • Procedures entire subprograms
Write a Comment
User Comments (0)
About PowerShow.com