Programs are: CMPSCI 105/119/120: Programming, Flowchar<ng, and Running Program Flowcharts

Similar documents
SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

Low-Level Languages. Computer Programs and Programming Languages

Principles of Programming Languages. Lecture Outline

Software Development. Integrated Software Environment

General Concepts. Abstraction Computational Paradigms Implementation Application Domains Influence on Success Influences on Design

CS2303 C14 Systems Programming Concepts. Bob Kinicki

Principles in Programming: Orientation & Lecture 1. SWE2004: Principles in Programming Spring 2014 Euiseong Seo

Design & Implementation Overview

Terminology & Basic Concepts

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Computer Programming-I. Developed by: Strawberry

Introduction to Programming: Variables and Objects. HORT Lecture 7 Instructor: Kranthi Varala

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

Informatica 3 Syntax and Semantics

Outline. Programming Languages 1/16/18 PROGRAMMING LANGUAGE FOUNDATIONS AND HISTORY. Current

Comp 333: Concepts of Programming Languages Fall 2016

Concepts of Programming Languages

Chapter 1. Preliminaries

Introduction to Scientific Computing Languages

Discovering Computers Chapter 13 Programming Languages and Program Development

LECTURE 1. Overview and History

INFS 214: Introduction to Computing

Introduction to Scientific Computing Languages

Högnivåspråk och översättning

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

SCAN: Computer Science - second year. Christian Wolf

UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi

Chapter 1. Preview. Reason for Studying OPL. Language Evaluation Criteria. Programming Domains

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

COMPILER DESIGN LECTURE NOTES

W1005 Intro to CS and Programming in MATLAB. Brief History of Compu?ng. Fall 2014 Instructor: Ilia Vovsha. hip://

G Programming Languages - Fall 2012

Discovering Computers 2008

Programming: detailed instructions which tell the computer hardware what to do aka software Computer Science: the study NOT of computers, but of what

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

CSCI 3136 Principles of Programming Languages

Evolution of Fortran. Presented by: Tauqeer Ahmad. Seminar on Languages for Scientific Computing

Fundamentals of Programming. By Budditha Hettige

CSI32 Object-Oriented Programming

8/16/12. Computer Organization. Architecture. Computer Organization. Computer Basics

Why are there so many programming languages?

1 Little Man Computer

Principles in Programming: Orientation & Lecture 1. SWE2004: Principles in Programming Spring 2015 Euiseong Seo

Chapter 5 Names, Binding, Type Checking and Scopes

A Func'onal Introduc'on. COS 326 David Walker Princeton University

Working with JavaScript

Programmiersprachen (Programming Languages)

1) What is the first step of the system development life cycle (SDLC)? A) Design B) Analysis C) Problem and Opportunity Identification D) Development

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Early computers (1940s) cost millions of dollars and were programmed in machine language. less error-prone method needed

CGS 3066: Spring 2015 JavaScript Reference

Introduction. A. Bellaachia Page: 1

LECTURE 18. Control Flow

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CSC180: Lecture 2. Wael Aboulsaadat.

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Lecture 1: Course Introduction

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility

NOTE: Answer ANY FOUR of the following 6 sections:

CSC 533: Organization of Programming Languages. Spring 2005

Lecture 1 - Introduction (Class Notes)

Com S 541. Programming Languages I

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

Software. Programming Languages. Types of Software. Types of Languages. Types of Programming. Software does something

Lecture 01 & 02 Computer Programming

Programming Languages and Program Development Life Cycle Fall Introduction to Information and Communication Technologies CSD 102

A Tour of Language Implementation

Programming Languages

CS101 Introduction to Programming Languages and Compilers

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware

Logic Programming II & Revision

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

Lecture 1: Course Introduction

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

Module 1: Introduction to Computers, Programs, and Java

CS383 PROGRAMMING LANGUAGES. Kenny Q. Zhu Dept. of Computer Science Shanghai Jiao Tong University

Language Translation, History. CS152. Chris Pollett. Sep. 3, 2008.

Lecture 15: Iteration and Recursion

Compilation I. Hwansoo Han

Chapter 5. Names, Bindings, and Scopes

Programming Languages, Summary CSC419; Odelia Schwartz

LESSON 13: LANGUAGE TRANSLATION

Programming Languages and Program Development

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

CS 3304 Comparative Languages. Lecture 1: Introduction

Ruby: Introduction, Basics

What is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573

Appendix A The DL Language

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

1/14/2014. Introduction to CSE 1325 Object Oriented Programming (Using Java) Introduction (Cont.) Introduction

Compilers. Prerequisites

Control Structures. Outline. In Text: Chapter 8. Control structures Selection. Iteration. Gotos Guarded statements. One-way Two-way Multi-way

Chapter 11 Introduction to Programming in C

CS558 Programming Languages. Winter 2013 Lecture 1

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Chapter 1. Preliminaries

Programming Languages 2nd edition Tucker and Noonan"

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

Elements of Computers and Programming Dr. William C. Bulko. What is a Computer?

Transcription:

Programs are: CMPSCI 105/119/120: Programming, Flowchar<ng, and Running Program Flowcharts 2014-2017 Dr. William T. Verts Source code wrilen in a text editor, Following the syntax of a language, Specifying both memory loca<ons (variables) and instruc<ons (statements), That must be translated into a form the computer can actually use (oten binary instruc4ons directly executable by the CPU). Translators Assemblers Translate very low- level statements into binary instruc<ons (1à 1), crea<ng stand- alone.exe files. Compilers Translate high- level statements into many binary instruc<ons (1à many), crea<ng stand- alone.exe files. Interpreters Translates and executes each statement as it is encountered, requiring translator to run programs. Errors Syntax Errors Viola<ons of the rules of the language Run- Time Errors (Bugs) Computa<ons giving the wrong results Computa<ons hal<ng the program (unchecked divide- by- zero, for example) Both require edi<ng the source text of the program, retransla<ng it, and trying again. Languages Early compiled languages (FORTRAN, COBOL, ALGOL, PL/I) from the 1950s and 1960s. Later compiled languages (Pascal, C, C++, Ada) from the 1970s and 1980s. Early interpreted languages (BASIC, LISP, APL) from the 1960s. Later interpreted languages (Python, JavaScript, Perl, many scrip<ng languages for Web servers) Modern languages compiled to a generic computer model, then interpreted by a virtual machine (Java) Flowcharts Provide a visual, non- language- specific way of describing a program, Used to be how programmers designed programs in the first place, Are a good teaching tool to illustrate how programs work. 1

Statements (Flowchart) Example: Factorial The factorial of an integer N is the product of all integers from 1 up through N. N factorial is wrilen as N! N! = 1 2 3 N (itera<ve defini<on) N! = N (N- 1)! (recursive defini<on) 0! = 1 (makes recursion work) 5! = 1 2 3 4 5 = 120 Flowcharts Here's the flowchart version of the factorial program: 2014 Dr. William T. Verts Tracing Flowcharts Put your finger on the START box, Follow the flow- arrows, When you enter a box do what it says, Update the variables appropriately, Don't take your finger off un<l you hit STOP. 2014 Dr. William T. Verts 2

3

4

5

What Does This Give Us? By following a flowchart, we see how computers execute their programs, We also see how detailed programs must be to accomplish any task, But computers do each step extremely fast (on the order of a few nanoseconds). Programs may be wrilen in Different Ways: Some are shorter Some are faster Some use less memory Some use bizarre techniques Some are easier to teach Some are easier to debug Some languages are easier than others 6

Here's the Factorial Program in Python N = input("enter a Number --- ") F = 1 I = 1 while (I <= N): F = F * I I = I + 1 print F Here's the same program in JavaScript (embedded in HTML Web Page) <SCRIPT TYPE="text/javascript"> <!-- N = parsefloat(window.prompt( "Enter a Number --- ")) ; F = 1 ; I = 1 ; while (I <= N) { F = F * I ; I = I + 1 ; } document.writeln (F) ; //--> </SCRIPT> Here's the same program in Pascal Program Factorial ; Var N,F,I : Integer ; Begin Readln(N) ; F := 1 ; I := 1 ; While (I <= N) Do Begin F := F * I ; I := I + 1 ; End ; Writeln (F) ; End. Here's the same program in BASIC 10 INPUT N 20 LET F = 1 30 LET I = 1 40 IF I > N THEN 80 50 LET F = F * I 60 LET I = I + 1 70 GOTO 40 80 PRINT F 90 END Here's the same program in 8088 Assembly Language MOV AX,1 ; F=1 MOV BX,5 ; N=5 MOV CX,1 ; I=1 TopLoop: CMP CX,BX ; Test I:N JG EndLoop ; Jump if > MUL CX ; F=F*I ADD CX,1 ; I=I+1 JMP TopLoop ; Jump back EndLoop: CALL PRINT ; Languages (1/3) Python: Interpreted, Dynamically Typed, One statement per line, Whitespace (indenta<on) determines lexical scope. JavaScript (not Java): Interpreted (typically by Web browser), Dynamically Typed, Statements terminated by semicolons (;), Curly braces ({}) determine lexical scope. 7

Languages (2/3) Pascal: Compiled, Sta<cally Typed, Statements separated by semicolons (;) Keywords (Begin-End) determine lexical scope. BASIC (as originally implemented): Interpreted, Sta<cally Typed (suffixes carry type: A, A$, A%), One statement per line, What lexical scope? Languages (3/3) Java (not JavaScript): Compiled to intermediate form interpreted by JVM, Sta<cally Typed, Statements terminated by semicolons (;) Curly braces ({}) determine lexical scope. Assembly Language: Assembled (for par<cular machine architecture), Instruc<ons carry type (ADD vs. FADD), One statement per line, What lexical scope? Here's the Factorial Program in Python Again N = input("enter a Number --- ") F = 1 I = 1 while (I <= N): F = F * I I = I + 1 print F Here's a more efficient way N = input("enter a Number --- ") F = 1 for I in range(1,n+1): F = F * I print F Here's a radically different way: def Factorial(N): if (N <= 1): return 1 else return N*Factorial(N-1) N = input("enter a Number --- ") print Factorial(N) On the 105 Final Exam I will provide a flowchart of roughly this complexity (but not the same program), I will provide boxes for each of the variables, You will trace the flowchart and determine the final results. I will NOT ask you to draw a flowchart. 8