simula programming language lenar uri t. barcelona

20
Simula Programming Simula Programming Language Language Lenar Uri T. Barcelona Lenar Uri T. Barcelona

Upload: fay-berry

Post on 31-Dec-2015

229 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Simula Programming Language Lenar Uri T. Barcelona

Simula Programming Simula Programming LanguageLanguage

Lenar Uri T. BarcelonaLenar Uri T. Barcelona

Page 2: Simula Programming Language Lenar Uri T. Barcelona

It all started with a need…It all started with a need…

Kristen Nygaard realized, Kristen Nygaard realized, through his work in the through his work in the Norwegian Defense Research Norwegian Defense Research Establishment, that there is a Establishment, that there is a need for simulation toolsneed for simulation tools

Page 3: Simula Programming Language Lenar Uri T. Barcelona

It all started with a need…It all started with a need…

Nygaard left NDRE and put up Nygaard left NDRE and put up NCC (Norwegian Computing NCC (Norwegian Computing Center) where, similar to his Center) where, similar to his previous job, he realized that previous job, he realized that there is a need for simulation there is a need for simulation toolstools

Page 4: Simula Programming Language Lenar Uri T. Barcelona

History of SimulaHistory of Simula

Summer 1961-Summer 1961-Fall 1962Fall 1962 The concept of a The concept of a

mathematical mathematical discrete event discrete event network and network and programming programming language language reasoning for reasoning for Simula I were Simula I were developed by developed by Nygaard and Dahl Nygaard and Dahl

Fall 1962-Fall 1962-September 1963September 1963

It was decided that It was decided that Simula I would be Simula I would be implemented as a implemented as a simulation simulation procedure package procedure package along with a along with a preprocessor to preprocessor to Algol 60Algol 60

Page 5: Simula Programming Language Lenar Uri T. Barcelona

History of SimulaHistory of Simula

September 1963 - September 1963 - March 1964March 1964 A new storage A new storage

management management schemescheme

Simula I would be Simula I would be implemented implemented through a through a modification and modification and extension of extension of Univac's Algol 60 Univac's Algol 60 compiler compiler

March 1964-March 1964-December 1964December 1964 The first prototype The first prototype

was completed in was completed in December December

Minor language Minor language modifications were modifications were made made

Extensions based Extensions based on implementation on implementation experience and experience and programming test programming test cases were cases were completed completed

Page 6: Simula Programming Language Lenar Uri T. Barcelona

History of SimulaHistory of Simula

Fall of 1965Fall of 1965 The Technical The Technical

University of University of Norway wanted to Norway wanted to implement a new implement a new Algol 60 compiler Algol 60 compiler on the Univac 1100 on the Univac 1100 seriesseries

Nygaard and Dahl Nygaard and Dahl determined that determined that attribute accessing attribute accessing and common and common properties of properties of processes were processes were the most significant the most significant problems in Simula problems in Simula I I

December 1966December 1966 PrefixingPrefixing

Today, prefixing Today, prefixing is known as is known as inheritanceinheritance

Class ConceptClass Concept Prefixing can be Prefixing can be

extended to extended to include multiple include multiple prefixing thus prefixing thus establishing establishing hierarchies of hierarchies of process classes process classes

This led to the This led to the idea of objects idea of objects

Page 7: Simula Programming Language Lenar Uri T. Barcelona

Features of SimulaFeatures of Simula

Classes Classes

Objects Objects instance variables instance variables methods methods

Inheritance Inheritance

Sub-typingSub-typing

““Inner”Inner” supports method supports method

combination combination

"Virtual" methods "Virtual" methods methods that can be methods that can be

redefined in derived redefined in derived classes classes

Inspect/QUA Inspect/QUA run-time class (type) run-time class (type)

tests tests EncapsulationEncapsulation

"Protected" which "Protected" which means that they are means that they are accessible for accessible for subclassessubclasses

"Hidden" in which "Hidden" in which case that are not case that are not accessible to accessible to subclasses either subclasses either

Page 8: Simula Programming Language Lenar Uri T. Barcelona

Extensions/Modifications of Extensions/Modifications of Algol 60 Algol 60 Added: Added:

Class concepts and reference-variables Class concepts and reference-variables (pointers to objects) (pointers to objects)

Pass-by-reference Pass-by-reference Char, Text, and I/O Char, Text, and I/O Co-routines Co-routines

Removed: Removed: Changed default parameter passing mechanism Changed default parameter passing mechanism

from call-by-name to pass-by-value from call-by-name to pass-by-value Pass-by-result Pass-by-result Some variable initialization requirements Some variable initialization requirements String type (in favor of "text" type) String type (in favor of "text" type)

Page 9: Simula Programming Language Lenar Uri T. Barcelona

Problems with SimulaProblems with Simula

Language Language features:features: Limited file access Limited file access

facilities facilities Missing data types Missing data types

(records, sets) (records, sets) No real time No real time

support support No GUI support No GUI support Long executable Long executable

files for short files for short programs programs

OOP features: OOP features: No multiple No multiple

inheritance inheritance No interfacesNo interfaces

Simulation: Simulation: No automatic No automatic

collection of collection of statistics statistics

No report No report generatorgenerator

No specialized No specialized facilitiesfacilities

Page 10: Simula Programming Language Lenar Uri T. Barcelona

Implicit ConversionImplicit Conversion

Implicit Implicit conversion is conversion is performed, performed, where where necessary, each necessary, each time a term-time a term-operator-term operator-term triple is triple is evaluatedevaluated

General RulesGeneral Rules

1.1. If the operator If the operator is integer divide, is integer divide, //, both terms //, both terms must be integer must be integer or short integer; or short integer; use of reals or use of reals or long reals long reals constitutes a constitutes a runtime errorruntime error

Page 11: Simula Programming Language Lenar Uri T. Barcelona

Implicit ConversionImplicit Conversion

2.2. All short integer All short integer values are values are converted to converted to integer; this can integer; this can never cause a never cause a conversion errorconversion error

3.3. If the operator is If the operator is real divide, /, both real divide, /, both terms are terms are converted to real converted to real or long real, in or long real, in accordance with accordance with (4)(4)

4.4. Where the terms Where the terms are of different are of different types and at least types and at least one is real or long one is real or long real conversion is real conversion is performed; if one performed; if one term is long real term is long real the other is the other is converted to long converted to long real otherwise the real otherwise the non-real term is non-real term is converted to realconverted to real

Page 12: Simula Programming Language Lenar Uri T. Barcelona

Operators in SimulaOperators in Simula

  Operator Example

Exponentiation ** 2**5 = 32

Multiplication * 2*5 = 10

Division of real numbers

/ 2/5 = .4

Division of integers

// 2/5 = 0

Addition + 2+5 = 7

Subtraction - 2-5 = -3

Page 13: Simula Programming Language Lenar Uri T. Barcelona

Relational Operators in SimulaRelational Operators in Simula

Symbol Alternative Meaning

= eq is equal to

<> ne is not equal to

> gt is greater than

< lt is less than

>= geis greater than

or equal to

<= leis less than or

equal to

Page 14: Simula Programming Language Lenar Uri T. Barcelona

Simple Types in SimulaSimple Types in Simula

Keyword Initial Value Description

integer 0Any integer value, positive or

negative.

short integer

0  

real 0.0Any decimal value, positive or

negative.

long 0.0  

character ISO NULL Any single character.

Boolean FalseCan only hold one of two values,

True or False.

textNoText,

equivalent to ""

Any string.

Page 15: Simula Programming Language Lenar Uri T. Barcelona

Syntax Rules - BlocksSyntax Rules - Blocks

begin begin     comment Our first SIMULA     comment Our first SIMULA program; program;     integer Count;     integer Count;     count := 3;     count := 3;     OutInt(Count,4);     OutInt(Count,4);     OutImage     OutImage end end

Page 16: Simula Programming Language Lenar Uri T. Barcelona

Syntax Rules - DeclarationsSyntax Rules - Declarations

procedure PrintTimes(T1, count); text T1; integer count;procedure PrintTimes(T1, count); text T1; integer count;

beginbegin   integer i;   integer i;   i := 0;   i := 0;   while i < count do   while i < count do   begin   begin      OutText(T1);      OutText(T1);      OutImage;      OutImage;   end;   end;end; end;

Page 17: Simula Programming Language Lenar Uri T. Barcelona

Syntax Rules - DeclarationsSyntax Rules - Declarations

class HelloWorld;class HelloWorld;beginbegin   text outPut;   text outPut;   outPut :- "Hello World";   outPut :- "Hello World";         procedure sayHello;   procedure sayHello;   begin   begin      OutText(outPut);      OutText(outPut);   end;   end;end; end;

Page 18: Simula Programming Language Lenar Uri T. Barcelona

Syntax Rules - RecursionSyntax Rules - Recursion

beginbegin

   procedure factorial(m); integer m;   procedure factorial(m); integer m;   begin   begin      if m > 0 then      if m > 0 then      begin      begin         factorial := m * factorial(m-1);         factorial := m * factorial(m-1);      end;      end;      else      else         factorial := 1;         factorial := 1;   end;   end;

   OutInt(factorial(5),4);   OutInt(factorial(5),4);endend

Page 19: Simula Programming Language Lenar Uri T. Barcelona

Syntax Rules – if then elseSyntax Rules – if then else

integer count, countAgain;integer count, countAgain;

count := 2;count := 2;

countAgain := 3;countAgain := 3;

if count = 2 thenif count = 2 then   begin   begin      if countAgain = 3 then      if countAgain = 3 then         OutText("I will be printed");         OutText("I will be printed");   end;    end;

Page 20: Simula Programming Language Lenar Uri T. Barcelona

Syntax Rules - whileSyntax Rules - while

integer count;integer count;

count := 0;count := 0;

while count < 10 dowhile count < 10 do   begin   begin      OutInt(count, 4);      OutInt(count, 4);      OutImage;      OutImage;      count := count + 1;      count := count + 1;   end;    end;