History. Lecture 4: Modula-2 & InTouch. Modula-2. Aims Capitals. Comments. Niklaus Wirth, ETH, Switzerland. [RTCS Ch. 6.2; DMOC Ch.

Similar documents
clean way to do separate compilation. ECS140A Programming Languages 12-1

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996.

Topic IV. Block-structured procedural languages Algol and Pascal. References:

Today's Topics. CISC 458 Winter J.R. Cordy

The ACK Modula-2 Compiler

The PCAT Programming Language Reference Manual

Chapter 11. Abstract Data Types and Encapsulation Concepts

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Chapter 11. Abstract Data Types and Encapsulation Concepts

G Programming Languages - Fall 2012

Chapter 11. Abstract Data Types and Encapsulation Concepts ISBN

Introduction to Programming Using Java (98-388)

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CSE P 501 Compilers. Static Semantics Hal Perkins Winter /22/ Hal Perkins & UW CSE I-1

Flow Control. CSC215 Lecture

Programming Languages Third Edition. Chapter 7 Basic Semantics

NOTE: Answer ANY FOUR of the following 6 sections:

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms

Symbol Tables. ASU Textbook Chapter 7.6, 6.5 and 6.3. Tsan-sheng Hsu.

C-LANGUAGE CURRICULAM

Data Types. Outline. In Text: Chapter 6. What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers 5-1. Chapter 6: Data Types 2

Abstract data types &

Abstract Data Types & Object-Oriented Programming

G Programming Languages - Fall 2012

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

UNIT 3

Why Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ...

UNIT-4 (COMPILER DESIGN)

Abstract Data Types and Encapsulation Concepts

Data Types In Text: Ch C apter 6 1

Classes and Methods לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

LECTURE 18. Control Flow

Section 5: Pascal. Evolution of Software Languages

Tuple Abstract Data Type

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

Run Time Environment

Compiler Construction

Classes and Methods גרא וייס המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

Compiler Construction

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

Chapter 11. Abstract Data Types and Encapsulation Concepts 抽象数据类型 与封装结构. 孟小亮 Xiaoliang MENG, 答疑 ISBN

Short Notes of CS201

History. used in early Mac development notable systems in Pascal Skype TeX embedded systems

Implementing Subprograms

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004

University of Arizona, Department of Computer Science. CSc 520 Assignment 4 Due noon, Wed, Apr 6 15% Christian Collberg March 23, 2005

OBJECT ORIENTED PROGRAMMING USING C++

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Table of Contents. Initial Configuration of Runtime Workstation SMSI Server Development System OpenHMI P/N A 1-1

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

Modules. Cardelli, 1996

Annex A (Informative) Collected syntax The nonterminal symbols pointer-type, program, signed-number, simple-type, special-symbol, and structured-type

CS201 - Introduction to Programming Glossary By

CSc 520. The Oberon Programming Language Report. Manish Swaminathan, Bharathwaj 05/14/2008

Compiler Construction

CSE 307: Principles of Programming Languages

CFB Software. Astrobe. ARM Cortex-M Oberon Programmers Guide

Informatica 3 Syntax and Semantics

Programmin Languages/Variables and Storage

Table of Contents. Initial Configuration of Runtime Workstation SMSI Server Development System OpenHMI P/N A 1-1

Index. Numerics 0X String sentinel 65, Invariant violation Precondition violation 120

CS313D: ADVANCED PROGRAMMING LANGUAGE

Lecture 11: Subprograms & their implementation. Subprograms. Parameters

Recovering a Corrupted InTouch Application

520 Principles of Programming Languages. Arithmetic. Variable Declarations. 19: Pascal

Review for Test 1 (Chapter 1-5)


CMSC 4023 Chapter 11

Compiler Construction

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

10. Abstract Data Types

Review of the C Programming Language

System Software Assignment 1 Runtime Support for Procedures

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

CSCI312 Principles of Programming Languages!

CSc 520 Principles of Programming Languages. 26 : Control Structures Introduction

A Short Summary of Javali

Introduction to Internet of Things Prof. Sudip Misra Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

CS11 Java. Fall Lecture 1

[0569] p 0318 garbage

Programmiersprachen (Programming Languages)

The SPL Programming Language Reference Manual

Lecture 1: Overview of Java

Data Structure for Language Processing. Bhargavi H. Goswami Assistant Professor Sunshine Group of Institutions

CSCI 171 Chapter Outlines

Modularity. Modular program development. Language support for modularity. Step-wise refinement Interface, specification, and implementation

Chapter 5 Names, Binding, Type Checking and Scopes

Unit 2 : Computer and Operating System Structure

Data Structures and Algorithms for Engineers

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \

Michele Van Dyne Museum 204B CSCI 136: Fundamentals of Computer Science II, Spring

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University

Final Exam. 11 May 2018, 120 minutes, 26 questions, 100 points

Compiler Construction

Multiple Choice Questions. Chapter 5

Goals of this Lecture

Example. program sort; var a : array[0..10] of integer; procedure readarray; : function partition (y, z :integer) :integer; var i, j,x, v :integer; :

Transcription:

Lecture 4: Modula-2 & InTouch Modula-2 overview InTouch demo [RTCS Ch. 6.2; DMOC Ch. 2] 1 History Niklaus Wirth, ETH, Switzerland 1970 Pascal 1975 Modula 1979 Modula-2, first implementation on PDP-11 1980 Language definition, Technical Report 1981 Compilers outside ETH Oberon operative system language less real-time emphasis Modula-3 DEC object-oriented 2 garbage collection Aims Capitals Modula-2 Facilitate the construction of large programs. The module concept. Separate Compilation. Be a hardware close systems programming language. Control over allocation. ADDRESS... Support concurrent programming. NEWPROCESS, TRANSFER, IOTRANSFER A more systematic syntax than in Pascal Reserved words are written with CAPITALS. The compiler distinguishes between capitals and non-capital characters. Comments Can be nested. (* This is a comment *) (* (* *) *) 3 4

Data Types INTEGER, CARDINAL, BOOLEAN, CHAR REAL ch: CHAR; ch := 'a'; ORD('A') = 65 CHR(65) = 'A' x: REAL; x := 5; (* Wrong *) x := 5.0; (* Correct *) Enumeration types optype = (plus,minus,times,divide); op : optype; op := plus; INC(op); (* minus *) DEC(op); (* plus again *) INC(op,3); (* divide *) op := VAL(optype,2); (* times *) ORD(minus); (* 1 *) 5 6 Arrays (* Modula-2 *) (* Pascal *) ARRAY [1..10] OF INTEGER; array [1..10] of integer; type Index = [1..10]; Index = 1..10; var a: ARRAY Index OF INTEGER; a: array [Index] of integer; ARRAY [1..m],[1..n] OF REAL array[1..m,1..n] of real; Strings Represented as ARRAY OF CHAR Library module Strings Records PersonType = RECORD name: ARRAY [0..79] OF CHAR: age: [0..110]; sex: (male,female); anders: PersonType; anders.age := 28; 7 8

ComponentType = (monitor,printer); StringType = ARRAY [0..19] OF CHAR; MechanismType = (dotmatrix,laser); Records with variant part SystemComponent = RECORD manufacturer: StringType; model: StringType; CASE kind: ComponentType OF monitor: colour: BOOLEAN; numlines, numcolumns: CARDINAL printer: mechanism: MechanismType; speed: CARDINAL Thetagfieldcanbeomitted RECORD CASE : BOOLEAN OF TRUE: a: INTEGER; FALSE:b: REAL END A record may have more than one variant part. Variant parts can be nested. component: SystemComponent; Set Types As in Pascal component.manufacturer := 'IBM'; component.kind := printer; component.speed := 10000; 9 10 Pointers Procedure Types p,q: POINTER TO CARDINAL; c: CARDINAL; c := p^; q^ := c; q^ := p^; q := p; NEW(p) allocates memory for a dynamic object of the type pointed to by p. DISPOSE(p) deallocates the memory. To use NEW and DISPOSE one must import STORAGE.ALLOCATE and STORAGE.DEALLOCATE 11 WriteProcedure = PROCEDURE(INTEGER); PROCEDURE WriteDecimal(i: INTEGER); BEGIN END WriteDecimal; PROCEDURE WriteHex(i: INTEGER); BEGIN END WriteHex; WP: WriteProcedure; BEGIN WP := WriteDecimal; WP(10); WP := WriteHex; WP(10); 12

Statements Conditions Assignment a := b + 3; Repetition WHILE i <= limit DO REPEAT UNTIL i > limit; 13 IF a = b THEN ELSIF a < b THEN ELSE Multiple Choice CASE color OF green: blue: red: ELSE END 14 Iteration FOR i := 1 TO n DO FOR i := 1 TO n BY 2 DO Infinite loop LOOP Statements not in Pascal Procedure call Exit from infinite loop P(a,b) EXIT; Function call Return from function procedure x := F(a,b) + 3; RETURN a + b; With reference Alternative return from procedure WITH p DO 15 RETURN 16

Procedures Statements not found in Modula-2 Function procedures and "ordinary" procedures Two kinds of formal parameters: variable parameters and value parameters Variable parameters preceded by go to L1; A change of a variable formal parameter affects the actual parameter (values are passed out of the procedure). (Call by reference) A value parameter gets its value by copying the value of the actual parameter. 17 18 Open array parameters PROCEDURE Sum(s: ARRAY OF CARDINAL): CARDINAL; i, sum: CARDINAL; BEGIN sum := 0; FOR i := 0 TO HIGH(s) DO sum := sum + s[i]; RETURN sum; END Sum; Called by v := ARRAY [m..n] OF CARDINAL; k := Sum(v); v[m] is mapped to s[0] v[n] is mapped to s[n-m] HIGH(s) = n - m Only the first index in a multi-dimensional array 19 Systems programming WORD BYTE ADDRESS (* assignment compatible with all pointer types *) PROCEDURE ADR(x:AnyType): ADDRESS; (* Returns the address of x *) PROCEDURE SIZE( v:anytype): CARDINAL; (* Returns the size needed for v *) PROCEDURE TSIZE(AnyType): CARDINAL; (* Returns the size needed for a variable of the given type *) Plus NEWPROCESS, TRANSFER, IOTRANSFER 20

Modules The primary difference between Pascal and Modula-2 A program consists of modules. One of the modules is the main program. The others are library modules. Separately compiled. Local modules are modules defined inside other modules not so much used. Modules act as walls. Entities declared inside a module are not visible outside the module unless they have been exported by the module. In order for another module to use an exported entity the module must import the entity. A module may import from multiple other modules. A complete Modula-2 program consists of a set of interconnected modules = dependency graph. 21 22 Library modules Two parts: a definition part and an implementation part. The definition part specifies the entities that the module exports. Constitutes the externally visible interface of the module. The implementation part contains the full declaration of the entity, i.e., the implementation. MODULE Main; END Main. Library modules DEFINITION MODULE M; END M. M.def IMPLEMENTATION MODULE M; END M. M.mod Main program: Main.mod 23 24

Import MODULE name ";" {import} {declarations} [BEGIN StatementSequence] END name "." Main Module The items that can be imported by another module must be defined in the Definition module (exported by default) import = [FROM name] IMPORT namelist ";" namelist could contain modules, procedures, variables, types, constants IMPORT M1; FROM M1 IMPORT x, y; Selective "dequalification" x and y can be referenced directly. Other exported entities of M1 can be referenced with M1.entity 25 26 Definition modules Implementation modules DEFINITION MODULE name ";" {import} {definition} END name ";" definition = CONST {constant decl. ";"} {name ["=" type] ";"} {name : type ";"} ProcedureHead ";" 27 CompilationUnit = DefinitionModule [IMPLEMENTATION] ProgramModule ProgramModule = MODULE name ";" {import} {declaration} [BEGIN StatementSequence] END name "." Example IMPLEMENTATION MODULE TreeConstructor; BEGIN END TreeConstructor. 28

DEFINITION MODULE TreeConstructor; Opaque types A data type whose structure is hidden inside a module. The value of an opaque type must be a pointer. Thus the compiler knows how much space to allocate for a variable of an opaque type. FROM RuleHandler IMPORT GetConsequent, GetAntecedent; TreePtr; PROCEDURE MakeTree( T: Treeptr); PROCEDURE Traverse(T: TreePtr); END TreeConstructor. 29 30 IMPLEMENTATION MODULE TreeConstructor; Tree = RECORD TreePtr = POINTER TO Tree; END TreeConstructor. Separate compilation A change in a definition module means that all modules that import from the changed definition module must be recompiled. Then, all modules that import from the recompiled modules must be recompiled, etc. A change in an implementation module only results in a recompilation of that module. 31 32

A Dependency Graph IMPL DEF Main Program MODULE M; Modules A powerful tool for creating large programs. B DEF IMPL Help make programs easier to modify by supporting information hiding. Help make programs more portable. Make separate compilation possible. C DEF IMPL D DEF IMPL Enable the development of libraries of resuable code. 33 34 DEFINITION MODULE Stack; ElementType = ; StackType; PROCEDURE Push( S: StackType, value: ElemenType); PROCEDURE Pop( S: StackType): ElementType; PROCEDURE Init( S: StackType); END Stack. DEFINITION MODULE Stack; FROM User IMPORT ElementType; StackType; PROCEDURE Push( S: StackType, value: ElemenType); PROCEDURE Pop( S: StackType): ElementType; PROCEDURE Init( S: StackType); END Stack. 35 36

IMPLEMENTATION MODULE Stack; FROM Storage IMPORT ALLOCATE; CONST StackMax = 100; StackRange = [0..StackMax]; StackType = POINTER TO RECORD top : StackRange; s : ARRAY StackRange OF ElementType; PROCEDURE Push( S: StackType; value : ElementType); BEGIN WITH S^ DO END Push 37 InTouch Graphical User Interface (GUI) package from Wonderware Corp. Two parts: WindowMaker: graphical editor WindowViewer: run-time environment Animation Links: animated objects two types: TouchLinks DisplayLinks Scripts: command language 38 Tagname Data Dictionary Run-time database The variable of applications Variable: tagname type DDE tag types Memory tag types DDE Dynamic Data Exchange Message-based protocol from Microsoft Client-server system server: provides data client: requests data 39 40

A DDE Conversation Addressing Cold links: one-time requests, snapshot Hot links: the server automatically supply data to the clients whenever the data has changed Warm links: the server informs the cliens that the data has changed. The client may then request the data if needed. Three parts: Application/server name Topic name Item name 41 42 Type definitions: Server; Topic; RealItem; BooleanItem; InTouch WindowViewer InTouch (NT process) DDE Server Module Tagname Data Dictionary DDE communication DDE server Kernel Process (NT thread) Real Time Kernel (NT process) 43 PROCEDURE NewServer( s name DDE primitives : Server; : ARRAY OF CHAR); This primitive creates and returns a server, s. The parameter name defines the application name for the server. PROCEDURE DisposeServer( s : Server); The server is deleted. PROCEDURE NewTopic( t : Topic; s : Server; name : ARRAY OF CHAR); A topic belonging to server s is created and returned. The name of the topic is given by name. PROCEDURE DisposeTopic( t : Topic); A topic is deleted. 44

PROCEDURE NewReal( r : RealItem; t : Topic; name : ARRAY OF CHAR); An item of type real belonging to topic t is created and returned. The name of the item is given by name. PROCEDURE DisposeReal( r : RealItem); An item of type real is deleted. PROCEDURE GetReal(r : RealItem) : LONGREAL; Returns the current value of the real type item r. The operation is nonblocking. PROCEDURE SetReal(r : RealItem; value : LONGREAL); Sets the value of the real type item r. If the item is requested by a DDE-client (e.g., InTouch) and the value has changed then a DDE message is sent to the client. PROCEDURE NewBoolean( r : BooleanItem; t : Topic; name : ARRAY OF CHAR); An item of type boolean belonging to topic t is created and returned. The name of the item is given by name. PROCEDURE DisposeBoolean( r : BooleanItem); An item of type boolean is deleted. PROCEDURE GetBoolean(r : BooleanItem) : BOOLEAN; Returns the current value of the boolean type item r. The operation is nonblocking. PROCEDURE SetBoolean(r : BooleanItem; value : BOOLEAN); Sets the value of the boolean type item r. If the item is requested by a DDE-client (e.g., InTouch) and the value has changed then a DDE message is sent to the client. 45 46 Application: Topic: Item Item Item InTouch Information DDE message Topic: GetReal DMOC Chapter 2 incl. example InTouch Getting Started InTouch User s Guide DDE message Topic: SetReal 47 48