Chapter 2.3 Modula 2 An Introduction. Summary First example Terminal symbols Comments Data –Constants –Variables Actions –Assignment statement –Control.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

Programming Languages and Paradigms
Chapter 2.5 Modula 2 Control Instructions. Modula 2 Control Statements Selection statements –BOOLEAN Selector : IF statement –Ordinal Selector : CASE.
1 C++ Syntax and Semantics The Development Process.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Pascal By: Liane Tom. Outline o Background o Data types and Syntax o Procedures and Functions o Advantages o Disadvantages.
Chapter 2 Data Types, Declarations, and Displays
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Programming Logic and Design Fourth Edition, Introductory
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Basic Elements of C++ Chapter 2.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
CIS Computer Programming Logic
©J.Tiberghien - ULB-VUB Version 2007 Première partie, chap. 4, page 1 Chapitre 1.4 Langages et outils de programmation.
1 The CONST definition CONST Pi = , City = ‘New York’; Constant identifiers are used when you do not want the value of an identifier to change why.
Pascal Programming Strings, Arithmetic operators and output formatting National Certificate – Unit 4 Carl Smith.
Copyright 1999 by Larry Fuhrer. Pascal Programming Getting Started...
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
CPS120: Introduction to Computer Science
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Chapter 2.6 Modula 2 Structured Types. Types in Modula 2 Simple Types: values can’t be decomposed –Ordinal Types: bijection with natural numbers –Reals:
1 C++ Syntax and Semantics, and the Program Development Process.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems.
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
Elements of a Java Program Bina Ramamurthy SUNY at Buffalo.
Introduction to Programming with RAPTOR
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 1 (Monday)
Chapter 1.4 Programming Languages and Programming.
VARIABLES AND DATA TYPES Chapter2:part1 1. Objectives: By the end of this section you should: Understand what the variables are and why they are used.
Data Types Declarations Expressions Data storage C++ Basics.
CHAPTER 2 C++ SYNTAX & SEMANTICS #include using namespace std; int main() { cout
Chapter 2.4 Modula 2 Simple Types. Constants and Variables Constants –Name –Value The value of a constant belongs to a type. Variables –Name –Type Type.
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
CHAPTER THREE Representing Data: Constants and Variables.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Fundamentals of Programming I Overview of Programming
Chapter 1.2 Introduction to C++ Programming
Definition of the Programming Language CPRL
Egyptian Language School Computer Department
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
BASIC ELEMENTS OF A COMPUTER PROGRAM
The CONST definition CONST Pi = , City = ‘New York’;
Basic Elements of C++.
Data Types, Identifiers, and Expressions
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
Basic Elements of C++ Chapter 2.
Introduction to the C Language
Data Types, Identifiers, and Expressions
Unit-1 Introduction to Java
High Level Programming Languages
Chapter 2: Introduction to C++.
Data Types and Expressions
An Introduction to Programming with C++ Fifth Edition
Variables and Constants
Presentation transcript:

Chapter 2.3 Modula 2 An Introduction

Summary First example Terminal symbols Comments Data –Constants –Variables Actions –Assignment statement –Control statements

A first example MODULE FirstExample; (* This program computes the area of a circle *) FROM InOut IMPORT WriteString, WriteLn; FROM RealInOut IMPORT WriteReal, ReadReal; CONST pi = ; VAR radius, area : REAL; BEGIN WriteLn; WriteLn; WriteString("Hello, I compute the area of a circle for you"); WriteLn; WriteString("Give me the radius in meters "); ReadReal(radius); area := pi * radius * radius; WriteString("The area of this circle is "); WriteReal(area,0); WriteString(" square meters "); WriteLn; END FirstExample.

Terminal Symbols Upper- and Lower-case letters a b c d e... A B C D E... Digits Special signs ;,. | + - * / = # > < ( ) [ ] { } Composed signs (* *) := >= <= Reserved Words MODULE BEGIN END IMPORT FROM

Source BSource CSource DSource A Reloc. DReloc. AReloc. BReloc. C Compiler XCompiler YAssembler LINKER Object Code A+B+C+D Role of a Linker FROM InOut IMPORT WriteString, WriteLn; FROM RealInOut IMPORT WriteReal, ReadReal;

Comments (* This program computes the area of a circle *) (* Text not containing (* nor *) *) Comment

Summary First example Terminal symbols Comments Data –Constants –Variables Actions –Assignment statement –Control statements

Constants Data whose value can not change during program execution Literal Constants Only a value: Named Constants A name and a value: The value can be a constant expression "The area of this circle is " pi = twopi = pi * 2.0

Syntax of Constants = Constant ExpressionIdentifier Constant Declaration Whole Number Literal Literal Real Literal String Literal Pointer Literal

Whole Number Literal + - Decimal Literal Octal Literal Hexadecimal Literal

Decimal Literal DecimalDigit

Octal Literal OctalDigit B 10B 8B

Hexadecimal Literal HexadecimalDigit H ABCDE F DecimalDigit HexadecimalDigit 10FFFH 0FFFFFH 1000F FFFFFH

Real Literal E E E-4 3,1416

String Literal "The area of this circle is " 'The area of this circle is ' "This string contains a ' "'but no " ' " Text not containing " " ' Text not containing ' '

Why named constants ? Area := 6 * Length*Length... Tax := (Price * 6) DIV 100 CONST VAT = 6;... Area := 6 * Length*Length... Tax := (Price * VAT) DIV 100 Area := 21 * Length*Length... Tax := (Price * 21) DIV 100 CONST VAT = 21;... Area := 6 * Length*Length... Tax := (Price * VAT) DIV 100

Constants and Variables Constants –(Name) –Value The value of a constant belongs to a type. Variables –Name –Type Type = set of all values the variable can have The type determines the internal representation of data as well as the operations that can be performed on the data

Types in Modula 2 Simple Types: values can’t 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

Summary First example Terminal symbols Comments Data –Constants –Variables Actions –Assignment statement –Control statements

Assignments Assignment operator := –Fundamentally different from the = sign –The = sign denotes a timeless relation –The := operator describes a particular action: The right side expression is evaluated Its value is stored in the left side variable –Illustrative example : a := a + 1 area := pi * radius * radius;

Control Statements Influence the order of execution of instructions Selection –IF THEN ELSE –CASE Iteration –WHILE –REPEAT –FOR –LOOP Procedure Call WriteString("Hello, I comput WriteLn; WriteString("Give me the rad ReadReal(radius); area := pi * radius * radius WriteString("The area of thi WriteReal(area,0); WriteString(" square meters WriteLn;