Programming Languages Tucker and Noonan

Slides:



Advertisements
Similar presentations
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Advertisements

Programming Languages and Paradigms
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Characters and Strings.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 12 Imperative Programming I really hate this.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Chapter 7: Semantics Fall 2009 Marco.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 12 Imperative Programming I really hate this.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 12 Imperative Programming I really hate this.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 12 Imperative Programming I really hate this.
Programming Language Concepts
Computer Science 210 Computer Organization Introduction to C.
CSE 341, S. Tanimoto Concepts 1- 1 Programming Language Concepts Formal Syntax Paradigms Data Types Polymorphism.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Chapter 12.  Programs written in imperative programming languages consist of ◦ A program state ◦ Instructions that change the program state  Program.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
Imperative Programming
High-Level Programming Languages: C++
CIS Computer Programming Logic
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
C for Java Programmers Tomasz Müldner Copyright:  Addison-Wesley Publishing Company, 2000 Introduction to C Muldner, Chapters 1, 2.
CPS 506 Comparative Programming Languages Imperative Programming Language Paradigm.
C Programming Language Bill Jensen CS 354 May, 3 rd 2007.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
Computer Science 101 Introduction to Programming.
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.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Introduction to Perl Yupu Liang cbio at MSKCC
Perl Language Yize Chen CS354. History Perl was designed by Larry Wall in 1987 as a text processing language Perl has revised several times and becomes.
Ch. 5 Ch. 51 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan.
Types(1). Lecture 52 Type(1)  A type is a collection of values and operations on those values. Integer type  values..., -2, -1, 0, 1, 2,...  operations.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Ch. 5 Ch. 51 jcmt Summer 2003Programming Languages CSE3302 Programming Languages (more notes) Summer 2003 Dr. Carter Tiernan.
Slide 1 WEEK 8 Imperative Programming Original by Vitaly Shmatikov.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Chapter 8 Characters and Strings. Objectives In this chapter, you will learn: –To be able to use the functions of the character handling library ( ctype).
C Part 1 Computer Organization I 1 August 2009 © McQuain, Feng & Ribbens A History Lesson Development of language by Dennis Ritchie at Bell.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Chapter 8 Statement-Level Control Structures. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 8 Topics Introduction Selection Statements.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
小型系統 心情 vs. 古典樂 心情 vs. 古典樂 浪漫求籤系統 美食導航系統 季潔亭雅鈺熒岱芸 美食導航系統 楊氏音樂模擬大會考人瑋 若維 芷萱 伽倩 楊氏音樂模擬大會考 麥當勞熱量計算系統 火星文困擾你嗎 ? 火星文困擾你嗎 ? 歌詞知多少 - 挑戰你的腦容量英琪 日馨 青雪 鈺娟.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 6: Stepwise refinement revisited, Midterm review.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Functional Programming
Information and Computer Sciences University of Hawaii, Manoa
Zuse’s Plankalkül – 1945 Never implemented Problems Zuse Solved
The Machine Model Memory
Computer Science 210 Computer Organization
Chapter 6: Data Types Lectures # 10.
Representation, Syntax, Paradigms, Types
Revision Lecture
Getting Started with C.
Programmazione I a.a. 2017/2018.
Computer Science 210 Computer Organization
Representation, Syntax, Paradigms, Types
Programming Languages 2nd edition Tucker and Noonan
Program Breakdown, Variables, Types, Control Flow, and Input/Output
High Level Programming Languages
Representation, Syntax, Paradigms, Types
Programming Languages 2nd edition Tucker and Noonan
Representation, Syntax, Paradigms, Types
Chapter 11 Programming in C
Lecture 7: Types (Revised based on the Tucker’s slides) 10/4/2019
Presentation transcript:

Programming Languages Tucker and Noonan Chapter 12: Imperative Programming 12.1 What Makes a Language Imperative? 12.2 Procedural Abstraction 12.3 Expressions and Assignment 12.4 Library Support for Data Structures 12.5 C 12.6 Ada 12.7 Perl CSC321: Programming Languages

Imperative Programming Oldest and most well-developed paradigm Mirrors computer architecture Typical Languages Fortran, Pascal C, Clite Ada 83 Perl CSC321: Programming Languages

What Makes Languages Imperative? In a von Neumann machine memory holds: Instructions Data Intellectual heart: assignment statement Others: Conditional branching Unconditional branch (goto) CSC321: Programming Languages

CSC321: Programming Languages Flowchart CSC321: Programming Languages

Procedural Abstraction Procedural abstraction allows the programmer to be concerned mainly with a function interface, ignoring the details of how it is computed. The process of stepwise refinement utilizes procedural abstraction to develop an algorithm starting with a general form and ending with an implementation. Ex: sort(list, len) CSC321: Programming Languages

Expressions and Assignment Assignment statement is fundamental: target = expression Copy semantics: Expression is evaluated to a value, which is copied to the target; used by imperative languages Reference semantics: Expression is evaluated to an object, whose pointer is copied to the target; used by object-oriented languages. CSC321: Programming Languages

Library Procedures/Functions There exist vast libraries of functions for most imperative languages. Partially accounts for the longevity of languages like Fortran, Cobol, and C. Typical libraries for data structures Iterators Vectors Lists Stacks, queues, deques, priority queues Sets and bags Maps CSC321: Programming Languages

CSC321: Programming Languages Supports Turing Completeness Assignment Sequence Conditional statement: If Loop statement: Goto Structured programming revolution of 1970s replace the goto with while loops. Other supports Integer variables, values, operations Input/output, error/exception handling, library support CSC321: Programming Languages

CSC321: Programming Languages “C was originally designed for and implemented on the UNIX Operating system on the DEC PDP-11, by Dennis Ritchie. The operating system, the C compiler, and essentially all UNIX applications programs (including all of the software Used to prepare this book) are written in C. ... C is not tied to Any particular hardware or system, however, and it is easy to Write programs that will run without change on any machine that supports C.” CSC321: Programming Languages

CSC321: Programming Languages Influences Multics, PL/I Application: typesetting documentation PDP-11: 16-bit minicomputer; 32 KB memory BCPL: typeless Portability: big-endian vs. little-endian machines Good code from a non-optimizing compiler Hardware support for: ++, --, +=, etc. CSC321: Programming Languages

General Characteristics Relatively low level language Macro facility Conditional compilation Lacks: iterators, generics, exception handling, overloading Assignments are expression ex: strcpy CSC321: Programming Languages

CSC321: Programming Languages Dynamic Allocation int *a; ... a = malloc(sizeof(int) *size); /* ANSI C: a = (int *) malloc(sizeof(int) *size); C++: a = new int[size]; */ /* deallocation left to programmer */ CSC321: Programming Languages

CSC321: Programming Languages Ex: Grep Grep is a Unix utility to search for strings in a text file #include libraries Two functions main processes command line arguments find Forward reference First signature/prototype, second definition Procedure reads file search each line write line if match fgets CSC321: Programming Languages

CSC321: Programming Languages Ex: Average Compute min, max, average of a set of numbers Formatting: scanf, printf Conditional assignment 2nd argument to scanf must be an address caught by some compilers segment violation at run time CSC321: Programming Languages

CSC321: Programming Languages Average C Code #include <stdio.h> Int main(int argc, char *argv[]) { int ct, number, min, max, sum; sum = ct = 0; printf(“Enter number: “); while (scanf(“%d”, &number) != EOF) { if (ct=0) min = max = number; ct++; sum += number; min = number < min? number : min; max = number > max? number : max; } printf(“%d numbers read\n”, ct); if (ct>0) printf(“Average: \t%d\n”, sum / ct); printf(“Maximum:\t%d\n”, max); printf(“Minimum: \t%d\n”, min); CSC321: Programming Languages

CSC321: Programming Languages Ada Developed in late 1970’s by DoD DoD spending billions of dollars on software Over 450 languages in use Solution: standardize on one language Higher Order Language Working Group Ada 83 problem: size of language/compiler no subsets rule Hard times during 1990s use of COTS Renewed interest COTS proved problematic development of Spark Ada NYU GNAT (Ada) compiler CSC321: Programming Languages

General Characteristics Influences: Algol, Pascal Large language; case insensitive Unlike C, array indexing errors trapped Type safe Union Generics Exception handling -- strictly control CSC321: Programming Languages

CSC321: Programming Languages Tagged Union type union(b: boolean) is = record case b is when true => i : integer; when false => r : float; end case end record; tagged : union; begin tagged := (b => false, r => 3.375); put(tagged.i); -- error case tagged(b) is put(tagged.i); put(tagged.r); CSC321: Programming Languages

CSC321: Programming Languages Generics Generic sort Sort various data set of different types Code generic type element is private; type list is array(natural range <>) of element; with function ">"(a, b : element) return boolean; package sort_pck is procedure sort (in out a : list); end sort_pck; CSC321: Programming Languages

CSC321: Programming Languages package body sort_pck is procedure sort (in out a : list) is begin for i in a'first .. a'last - 1 loop for j in i+1 .. a'last loop if a(i) > a(j) then declare t : element; t := a(i); a(i) := a(j); a(j) := t; end; end if; end loop end loop; end sort; end sort_pck; CSC321: Programming Languages

CSC321: Programming Languages Ada: Average Comparable to C Infinite loop; exit on end of file via exception Inner loop to catch errors caused by non-numeric data Exception handling Wordy than C CSC321: Programming Languages

CSC321: Programming Languages with Ada.Text_IO: with Ada.Integer_Text_IO; Procedure Average is sum := 0; Ct := 0; Ada.Text_IO.Put(“Enter number: “); loop begin Ada.Integer_Text_IO.Get(Number); if Ct = 0 then Min := Number; Max := Number; end if Count := Count + 1; if Number < Min then elsif Number > Max then exception when Constraint_Error => Ada.Text_IO.Put(“Value out of range.”); when Ada.Text_IO.Data_Error => Ada.Text_IO.Put(“Value not an integer.“); when Ada.Text_IO.End_Error => exit; end end loop Ada: Average Code Ada.Integer_Text_IO.Put(Ct, 5); Ada.Text_IO.Put(“ numbers read”); Ada.Text.IO.New_Line; if Ct > 0 then Ada.Text_IO.Put(“Average: “); Ada.Integer_Text_IO.Put(Sum/ Ct); Ada.Text_IO.Put(“Masimum: “); Ada.Integer_Text_IO.Put(Max); Ada.Text_IO.Put(“Minimum: “); Ada.Integer_Text_IO.Put(Min); end if End Average; CSC321: Programming Languages

CSC321: Programming Languages Perl Widely used A scripting language (originally for Unix) Dynamically typed Encourages a variety of styles Supports regular expression pattern matching Default conversion from one type to another (vs. Python) Result is distinct operators; ex: . for string concatenation Types: numbers, strings, regular expressions Dynamic arrays: indexed and associative CSC321: Programming Languages

CSC321: Programming Languages Scripting Languages “glue” Take output from one application and reformat into desired input format for a different application. Most time is spent in the underlying applications. Also used for Web applications CSC321: Programming Languages

CSC321: Programming Languages Arrays Indexed Arrays @a = (2, 3, 5, 7); # size is 4 ... $a[7] = 17; # size is 8; # $a[4:6] are undef Associative Arrays %d = (“bob” => “3465”, “allen” => “3131”, “rebecca” => “2912”); print $d{“bob”}; # prints 3465 CSC321: Programming Languages

CSC321: Programming Languages Perl: Grep #! /usr/bin/perl die "Usage mygrep string \n" if @ARGV < 1; use strict; my $string = shift; my $ct = 0; while (<>) { $ct++; print "$ct:\t$_" if /$string/; } exit; CSC321: Programming Languages

CSC321: Programming Languages Comments on Grep Scalar variables start with a $ Indexed arrays with an @ Hash arrays with % Otherwise: bare word syntax error use strict forces declaration of variables local : dynamic scoping my : static scoping NB: only 1 $_ CSC321: Programming Languages

CSC321: Programming Languages Strings Double quotes: special characters interpreted ex: “$a \n” forms: “ “, qq{ }, qq/ / Single quotes: special characters uninterpreted forms: ‘ ‘, q{ }, q/ / Comparison 10 < 2 # false - numeric 10 < "2" # false "10" lt "2" # true - string 10 lt "2" # true CSC321: Programming Languages

CSC321: Programming Languages Loops and Patterns while (<>) { ... }is same as: while ($_ = <STDIN>) { ... } where <> is read a line returns undef at end of file; undef interpreted as false no subject: $_ if $_ =~ m/pattern/ # implied subject, operator CSC321: Programming Languages

CSC321: Programming Languages Alternative Code #! /usr/bin/perl if (@ARGV < 1) { die "Usage mygrep string \n" ; } use strict; my $string = shift(@ARGV); my $ct = 0; my $line; while ($line = <STDIN>) { $ct++; if ($line =~ m/$string/) { print STDOUT $ct, ":\t", $line; } exit; CSC321: Programming Languages