© Alan Burns and Andy Wellings, 2001 Programming in the Small n Aim: to remind you how to read/write programs in Ada 95, Java and ANSI C n Practicals will.

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

Adapted from Scott, Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
Slide: 1 Copyright © AdaCore Arrays Presented Quentin Ochem university.adacore.com.
Names and Bindings.
Chapter 5 Names, Bindings, and Scopes
Designing an ADT The design of an ADT should evolve naturally during the problem-solving process Questions to ask when designing an ADT What data does.
Elementary Data Types Prof. Alamdeep Singh. Scalar Data Types Scalar data types represent a single object, i.e. only one value can be derived. In general,
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
Gary MarsdenSlide 1University of Cape Town Statements & Expressions Gary Marsden Semester 2 – 2000.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
CS 330 Programming Languages 10 / 18 / 2007 Instructor: Michael Eckmann.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Introduction to Fortran Fortran Evolution Drawbacks of FORTRAN 77 Fortran 90 New features Advantages of Additions.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes Names Variables The Concept of Binding Type Checking Strong Typing Type Compatibility.
Structured Data Types and Encapsulation Mechanisms to create new data types: –Structured data Homogeneous: arrays, lists, sets, Non-homogeneous: records.
Lecture 9 Concepts of Programming Languages
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
© Alan Burns and Andy Wellings, 2001 Programming in the Small Aim: to remind you how to read/write programs in Ada 95, Java and ANSI C.
Abstract Data Types and Encapsulation Concepts
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
Scope.
© 2003 G. Drew Kessler and William M. Pottenger1 Subroutines (Part 1) CSE 262, Spring 2003.
Language Evaluation Criteria
MT311 Java Application Programming and Programming Languages Li Tak Sing ( 李德成 )
Block-Structured Procedural Languages Lecture 11: Dolores Zage.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
Names Variables Type Checking Strong Typing Type Compatibility 1.
5-1 Chapter 5: Names, Bindings, Type Checking, and Scopes Variables The Concept of Binding Type Checking Strong Typing Type Compatibility Scope and Lifetime.
Porting Implementation of Packet Utilization Standard from ADA to JAVA Annelie Hultman (TEC-EME) Donata Pedrazzani (TEC-EMS) ESA/ESTEC 2004 JPUS de-briefing.
1 CS Programming Languages Class 15 October 17, 2000.
Introduction A variable can be characterized by a collection of properties, or attributes, the most important of which is type, a fundamental concept in.
Basic Semantics Associating meaning with language entities.
Programming Languages and Paradigms Imperative Programming.
Ada How was Ada conceived. The language, not the lady.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Implementing Subprograms What actions must take place when subprograms are called and when they terminate? –calling a subprogram has several associated.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
ICS 313: Programming Language Theory Chapter 14: Exceptions.
Chapter 10, Slide 1 ABSTRACT DATA TYPES Based on the fundamental concept of ABSTRACTION:  process abstraction  data abstraction Both provide:  information.
Chapter 6 Functions 6.1 Modular Design A valuable strategy when writing complex programs is to break down the program into several smaller modules. A module.
Copyright © 1998 by Addison Wesley Longman, Inc. 1 Chapter 7 Levels of Control Flow: 1. Within expressions 2. Among program units 3. Among program statements.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Structure of Programming Languages Names, Bindings, Type Checking, and Scopes.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
1 Chapter 11 © 1998 by Addison Wesley Longman, Inc The Concept of Abstraction - The concept of abstraction is fundamental in programming - Nearly.
1 CS Programming Languages Class 22 November 14, 2000.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Essential Ada Terminology copyright © Michael B. Feldman, All Rights Reserved.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes.
Ada, Scheme, R Emory Wingard. Ada History Department of Defense in search of high level language around Requirements drafted for the language.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Def: A control structure is a control statement and
Abstract Data Types and Encapsulation Concepts
Type Checking, and Scopes
11.1 The Concept of Abstraction
Lecture 9 Concepts of Programming Languages
Abstract Data Types and Encapsulation Concepts
MSIS 655 Advanced Business Applications Programming
Overview of Programming Paradigms
Controlling Program Flow
11.1 The Concept of Abstraction
Lecture 9 Concepts of Programming Languages
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

© Alan Burns and Andy Wellings, 2001 Programming in the Small n Aim: to remind you how to read/write programs in Ada 95, Java and ANSI C n Practicals will be in Ada 95 n For exams, you should be able to sketch solutions to problems in the three languages. However, we will not expect programs to be syntactically correct! n We will expect a higher literacy in Ada 95 n We will also consider aspect of Modula-1 (for device driving) and occam2 (for its pure message-based IPC facility).

© Alan Burns and Andy Wellings, 2001 Fortran Example DO 20 I = 1, 100 Loop to label 20, iterating I from 1 to 100 On the U.S. Viking Venus Probe, a programmer wrote DO 20 I = The compiler interpreted this as an assignment statement and ignored the spaces DO20I = Variables need not be declared in Fortran, and those beginning with D are assumed to be of type real is a real literal!

© Alan Burns and Andy Wellings, 2001 An Overview of Ada An Ada program consists of one or more program units: l a subprogram (procedure or function) — can be generic l a package (possibly generic) — used for encapsulation and modularity l a task — used for concurrency l a protected unit — a data-oriented synchronisation mechanism Library units: package, subprogram Subunits: subprogram, package, task, protected unit

© Alan Burns and Andy Wellings, 2001 Blocks Ada is a block-structured language declare -- definitions of types, objects, -- subprograms etc. begin -- sequence of statements exception -- exception handlers end; A block can be placed anywhere a statement can be placed

© Alan Burns and Andy Wellings, 2001 Points about Blocks n objects declared in a block may only be used in that block (scope) n any statement in the sequence of statement may itself be a block n exception handlers can be used to trap errors arising out of the execution of the sequence of statements (they may be omitted)

© Alan Burns and Andy Wellings, 2001 Example function Largest(X : Vector) return Integer is Max : Integer := 0; begin for I in X’Range loop if X(I) > Max then Max := X(I); end if; end loop; return Max; end Largest; ’Range is an attribute and = ’First - ’Last What is wrong with this example?

© Alan Burns and Andy Wellings, 2001 The C Language n Is sequential n Main structuring units are functions (although files can be used to aid separate compilation) n Block structured (called compound statements) { } n Declarative part cannot contain functions n Sequence of statements can contain compound statement

© Alan Burns and Andy Wellings, 2001 C Example int largest(vector X, int len) { int max = 0; int i; for (i = 0; i < len; i++) { // bounds start at 0 if(X[i] > max) max = X[i]; } return max; } Assignment statement is = Equality is = = Not so type secure as Ada. Typedefs are synonyms for types not derived types. However, the insecurities in C are well known.

© Alan Burns and Andy Wellings, 2001 An Overview of Java n A class-based language n Programming in the small component is similar to C but without explicit pointer values n More type secure than C n As with Ada, Java can have exception handler at the end of a block (but only if the block is a try block) n Functions can only be declared in the context of a class

© Alan Burns and Andy Wellings, 2001 class SomeArrayManipulationClass { public int largest(vector X) { int max = 0; int i; for (i = 0; i < X.length; i++) { // bounds start at 0 // length is an instance variable of array objects if(X[i] > max) max = X[i]; } return max; } A Java Example All arrays are objects

© Alan Burns and Andy Wellings, 2001 Java and Reference Types n All objects in Java are represented as reference values n Comparing two objects will compare their references not their values: Node Ref1 = new Node(); Node Ref2 = new Node();... if(Ref1 == Ref2) {... } will compare the locations of the objects not their values; it is necessary to implement a compareTo method A similar situation occurs with object assignment; it is necessary to provide a clone method

© Alan Burns and Andy Wellings, 2001 Discrete Types