Simple Procedural Languages: FORTRAN and C Lecture 9: Dolores Zage.

Slides:



Advertisements
Similar presentations
CSE 105 Structured Programming Language (C)
Advertisements

Agenda Definitions Evolution of Programming Languages and Personal Computers The C Language.
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Programming Languages and Paradigms
Programming Languages and Paradigms The C Programming Language.
Fortran Jordan Martin Steven Devine. Background Developed by IBM in the 1950s Designed for use in scientific and engineering fields Originally written.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Kernighan/Ritchie: Kelley/Pohl:
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,
Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
Lecture 2 Introduction to C Programming
Introduction to C Programming
1 CS 201 Introduction to C (1) Debzani Deb. 2 Outline Overview of C General form of a C program C Language Elements.
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
Introduction to Fortran Fortran Evolution Drawbacks of FORTRAN 77 Fortran 90 New features Advantages of Additions.
Three types of computer languages
G. Levine Chapter 6 Chapter 6 Encapsulation –Why do we want encapsulation? Programmer friendliness- programmer need not know about these details –Easier.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
Structured Data Types and Encapsulation Mechanisms to create new data types: –Structured data Homogeneous: arrays, lists, sets, Non-homogeneous: records.
Guide To UNIX Using Linux Third Edition
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
Introduction to C Programming
C++ fundamentals.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Computer Science 210 Computer Organization Introduction to C.
“C” Programming Language CIS 218. Description C is a procedural languages designed to provide lowlevel access to computer system resources, provide language.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Block-Structured Procedural Languages Lecture 11: Dolores Zage.
Imperative Programming
High-Level Programming Languages: C++
Fortran 1- Basics Chapters 1-2 in your Fortran book.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.
Names and Scope. Scope Suppose that a name is used many times for different entities in text of the program, or in the course of execution. When the name.
Programming With C.
FORTRAN FORmula TRANslator -Anand Trivedi. HISTORY  Designed and written from scratch in by an IBM team lead by John W. Backus as the first.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Programming Languages and Paradigms Imperative Programming.
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
Ch. 5 Ch. 51 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan.
Ch. 5 Ch. 51 jcmt Summer 2003Programming Languages CSE3302 Programming Languages (more notes) Summer 2003 Dr. Carter Tiernan.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 1 Scott Marino.
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
From Algorithms to Programs Both are sets of instructions on how to do a task Algorithm: –talking to humans, easy to understand –in plain (English) language.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Definition of the Programming Language CPRL
Computer Science 210 Computer Organization
Introduction to the C Language
Compiler Construction (CS-636)
C Language VIVA Questions with Answers
Revision Lecture
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
Introduction to C Programming Language
' C ' PROGRAMMING SRM-MCA.
Computer Science 210 Computer Organization
Govt. Polytechnic,Dhangar
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
C programming Language
The C Language: Intro.
C – Programming Language
Programming Languages and Paradigms
C Language B. DHIVYA 17PCA140 II MCA.
Presentation transcript:

Simple Procedural Languages: FORTRAN and C Lecture 9: Dolores Zage

Procedural Languages n Are the closest thing to “typical” programming language for demonstrating common language features. n Language consists of a series of procedures that execute when called n Each procedure consists of a sequence of statements n Each statement manipulates data that either is local to the procedure, a parameter passed in from the calling procedure, or defined globally

Procedural Languages n Local data for each procedure are stored in an activation record associated with that procedure n data stored in such activation records typically have relatively simple types, such as integer, real, character, and Boolean n FORTRAN and C (examples) n both have similar virtual computer and execution characteristics

FORTRAN and C n FORTRAN is characterized by static storage allocation (activation records can be created during language translation) FORTRAN 90 changes this n C is characterized by dynamic activation record creation. n Both were designed for run-time efficiency

FORTRAN n Widely used for scientific and engineering computation n A text editor is used to create the program n A FORTRAN compiler translates the program into executable form. n A linker is used to merge subprograms, the main program, and run-time library routines into one executable program

Hello World in FORTRAN PROGRAM TRIVIAL INTEGER I I = 2 IF( I.GE. 2 ) CALL PRINTIT STOP END SUBROUTINE PRINTIT PRINT *, “Hello World” RETURN END

FORTRAN Overview n No run-time management is provided n All storage is allocated statically before program execution begins n Only a restricted set of data types provided: four types of numeric data( integer, real, complex, and double-precision real), Boolean data (called logical), arrays, character strings, and files n An extensive set of arithmetic operations and mathematical functions is provided

FORTRAN Overview n Relational and Boolean operations are provided n Simple selection from arrays using subscripting n Both sequential and direct-access files are supported n Flexible set of input-output facilities and format specification features are available

FORTRAN’s weakest point n Restricted data structuring facilities n Essentially arrays and character strings of fixed length n No facilities for type definitions or data abstraction. n Subprograms provide the only abstraction mechanism

Other weakness n Statement sequence relies heavily on statement labels and GOTO statements u although each revision has added more nested control structures u FORTRAN 77 added the IF … THEN … ELSE n Only two levels of referencing environment are provided: local and global u the global environment may be divided into separate common environments (called COMMON blocks) n No special features are included to support construction of large programs beyond the provision for independent compilation

FORTRAN example to sum an array PROGRAM MAIN PARAMETER (MAXSIZ=99) REAL A(MAXSIZ) 10 READ(5, 100, END=999) K 100 FORMAT(I5) IF( K.LE. 0.OR. K.GT. MAXSIZ) STOP READ *, (A(I), I=1,K) PRINT *, (A(I), I=1,K) PRINT *, “SUM=“, SUM(A,K) GO TO PRINT *, “ALL DONE” STOP END Labels are placed in columns A C in column 1 indicates a comment All statements require one line unless column 6 has a nonblank character, indicating continuation of previous statement Statements begin in column 7

Notes on FORTRAN main u MAXSIZ is a programmer defined constant. The value of 99 is actually what the translator uses. u By default arrays begin at 1. u K is undeclared so it is an integer u 5 is used for keyboard input, 6 is used for display output u optional END=999 refers to end-of-file exception u * denotes a list directed read which parses numbers sequentially from the input stream u FORTRAN 77 has no WHILE construct

Notes on FORTRAN main n Variable names are 1 to 6 characters long, begin with a letter, and contain letters and digits u FORTRAN chars long and also the _ n FORTRAN is case insensitive n blanks are ignored ( all 3 represent the same statement) u DO 20 I = 1, 20

The FORTRAN Function SUM C SUMMATION SUBPROGRAM FUNCTION SUM(V,N) REAL V(N) SUM = 0.0 DO 20 I = 1, N SUM = SUM + V(I) 20 CONTINUE RETURN END

Notes on FORTRAN SUM n Information from the main program is not used to pass information to the compiler. The erroneous line: n FUNCTION SUM (V, N, M) n would also compile but may fail when the loader tries to merge this subprogram with MAIN n Although array is given as V(N), it refers to the statically allocated parameter, real array A(99)

Language Evaluation n Has amazing staying power n Compiling techniques for arithmetic expression evaluation, sparse matrix calculations and large array processing are excellent n numerical calculations that rely on computing derivatives, numerical integration, fluid dynamics, and solving for roots of complex equations - FORTRAN is as efficient as any language

Language Evaluation n Individual lines are easily understandable n overall structure is opaque because the heavy use of statement labels and GOTOs n restriction of identifiers

C n Developed in 1972 by Dennis Ritchie and Ken Thompson of AT&T Bell Telephone Laboratories n Compact syntax and efficient execution characteristics have made it a popular systems programming language, even though it is a general-purpose language

C Hello World #include void main() { int i; i=2; if(i >= 2) printit(); } void printit() { printf(“Hello World”);} Semicolons now terminate statements - need no continuation marker

The C concept n You generally cannot just look at grammar, but at n the C language n the C preprocessor n the C interface assumptions (the h files) n the C library

A C module n Consists of global declarations and a sequence of functions n multiple modules are linked together to form one executable program n each function may invoke other functions and access data local to that function or global n each function has a local activation record which is dynamic and allows for recursion

C function n Each function has access to global data n there is no real block, thus activation records do not need static links, only dynamic links

Data items n Each data item has an efficient implementation n Multi-dim arrays are built from one dimensional n one dimensional have indices beginning with 0 which avoids the need for descriptors (attributes of data type) n the starting address of the array is the same as the virtual origin which avoids all complex array calculations

Data items n C has pointers n there is an equivalence between arrays and pointers, permitting programs to use whichever method of access is most appropriate n Strings are implemented as arrays of characters, completely transparent so that strings may be access as strings, as arrays, or as pointers to individual characters

Other features n C has a large set of arithmetic operators n C has a full set of control structures with very flexible semantics n C has a flexible type definition n C has always been closely tied to OS functionality ( in UNIX, example: malloc - OS function for allocating dynamic storage, but you use and include to do this)

Language Evaluation n Crisp, clear syntax n close association of C data objects and underlying machine architecture permits very efficient programs n large library

C Weakness n Does permit very sloppy and error-prone programming n all enumerated types are integers, no strong typing n break and switch are error-prone n the == mistake n use of call-by-value parameter passing when pointers are needed to implement call-by- reference n C has no real encapsulation

C popularity n It is flexible (any application) n it is efficient (low-level semantics of language) n it is available (C compiler on most every computer n it is portable (you can write C program that can execute on multiple platforms)

C assignment