High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)



Similar documents
Notes on Assembly Language

CSCI 3136 Principles of Programming Languages

Lecture 1: Introduction

Moving from CS 61A Scheme to CS 61B Java

Chapter 6: Programming Languages

The previous chapter provided a definition of the semantics of a programming

McGraw-Hill The McGraw-Hill Companies, Inc.,

CSE 307: Principles of Programming Languages

Chapter 13: Program Development and Programming Languages

High level code and machine code

CSE 130 Programming Language Principles & Paradigms

Chapter 5 Names, Bindings, Type Checking, and Scopes

Functional Programming

Programming Languages

Levels of Programming Languages. Gerald Penn CSC 324

Object Oriented Software Design

Organization of Programming Languages CS320/520N. Lecture 05. Razvan C. Bunescu School of Electrical Engineering and Computer Science

Chapter 12 Programming Concepts and Languages

CS 106 Introduction to Computer Science I

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Chapter 14. Programming and Languages. McGraw-Hill/Irwin. Copyright 2008 by The McGraw-Hill Companies, Inc. All rights reserved.

1.1 WHAT IS A PROGRAMMING LANGUAGE?

Object Oriented Software Design

Introduction to Python

3 SOFTWARE AND PROGRAMMING LANGUAGES

Semester Review. CSC 301, Fall 2015

#820 Computer Programming 1A

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

VB.NET Programming Fundamentals

The C Programming Language course syllabus associate level

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Chapter 13: Program Development and Programming Languages

CSC Software II: Principles of Programming Languages

Chapter 1. Dr. Chris Irwin Davis Phone: (972) Office: ECSS CS-4337 Organization of Programming Languages

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Static vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer

Computer Programming I & II*

Introduction. Compiler Design CSE 504. Overview. Programming problems are easier to solve in high-level languages

Compilers. Introduction to Compilers. Lecture 1. Spring term. Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam.

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

History OOP languages Year Language 1967 Simula Smalltalk

How To Understand Programming Languages And Programming Languages

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

1/20/2016 INTRODUCTION

Chapter 13 Computer Programs and Programming Languages. Discovering Computers Your Interactive Guide to the Digital World

Informatica e Sistemi in Tempo Reale

Compiler Construction

Variables, Constants, and Data Types

Chapter 15 Functional Programming Languages

1 Classical Universal Computer 3

Instructor Özgür ZEYDAN BEU Dept. of Enve. Eng. CIV 112 Computer Programming Lecture Notes (1)

Programming Languages

Computational Mathematics with Python

Computer Programming I

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms.

Computer Programming I

Announcements FORTRAN ALGOL COBOL. Simula & Smalltalk. Programming Languages

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

Visual Basic Programming. An Introduction

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

Computational Mathematics with Python

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters

AP Computer Science Java Subset

Sources: On the Web: Slides will be available on:

OAMulator. Online One Address Machine emulator and OAMPL compiler.

CS 40 Computing for the Web

The Little Man Computer

Language Evaluation Criteria. Evaluation Criteria: Readability. Evaluation Criteria: Writability. ICOM 4036 Programming Languages

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

The programming language C. sws1 1

Fundamentals of Programming and Software Development Lesson Objectives

Evolution of the Major Programming Languages

Flowchart Techniques

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

Module 2 Stacks and Queues: Abstract Data Types

What is a programming language?

Python Programming: An Introduction to Computer Science

Explain the relationship between a class and an object. Which is general and which is specific?

Some programming experience in a high-level structured programming language is recommended.

Computing Concepts with Java Essentials

River Dell Regional School District. Computer Programming with Python Curriculum

Programming Languages & Tools

Ch. 10 Software Development. (Computer Programming)

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Glossary of Object Oriented Terms

n Introduction n Art of programming language design n Programming language spectrum n Why study programming languages? n Overview of compilation

ATSBA: Advanced Technologies Supporting Business Areas. Programming with Java. 1 Overview and Introduction

I PUC - Computer Science. Practical s Syllabus. Contents

Charles Dierbach. Wiley

Computer Programming Tutorial

The Clean programming language. Group 25, Jingui Li, Daren Tuzi

Algorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha

Programming in Java Course Technology, a part of Cengage Learning.

Tutorial on C Language Programming

Transcription:

High-Level Programming Languages Nell Dale & John Lewis (adaptation by Michael Goldwasser)

Low-Level Languages What are disadvantages of low-level languages? (e.g., machine code or assembly code) Programming in a low-level language is tedious! (have we made that clear yet?) Programs are only applicable to a particular CPU. Only primitive data types are directly supported. Languages offer minimal expressiveness for describing complex behaviors 8-2

High-Level Languages Higher-level languages provide a richer set of instructions and support, making the programmer s life even easier. Yet before a high-level program can be executed on a given CPU, it must be translated back to machine code. 8-3

Advantages Advantages of high-level languages include: - better portability (program runs on many CPUs) - richer data types and memory management - natural structures for expressing flow of control - much better support for software maintenance - much better support for software reuse 8-4

Translation Process A single high-level program can be translated to various CPU machine codes, but only if a translator exists for each such machine. Compiler: translates an entire high-level language program into machine code before it is executed. Interpreter: simulates a high-level language program, translating commands to machine code along the way, only as needed. 8-5

Compilers Figure 8.1 Compilation process 8-6

A Compiled Language Figure 8.2 8-7

An Interpreted Language Figure 8.2 8-8

High-Level Languages In designing high-level languages, goal is: maximize expressiveness to aid programmers yet ensure an automated translation process Many, many different high-level languages have been developed, e.g.: Fortran(1954), Lisp(1958), COBOL(1959), Simula(1964), Basic(1964), Smalltalk(1969), Prolog(1970), Pascal(1970), C(1971), ML(1973), Scheme(1975), Ada(1979), C++(1983), Perl(1987), Python(1991), Java(1995), C#(2000), VB.NET(2001) 8-9

Language Examples Our text draws upon four high-level languages for the purpose of demonstration: Ada, VB.NET, C++, Java We will introduce and experiment with one additional language (not discussed in text): Python 8-10

Variables Variables associate an identifying name with a piece of data stored in memory. Python SSCPU age = 25 LDI 25 STO age age DAT 8-11

Data Types Some primitive data types may be handled directly by the CPU (e.g., numbers, boolean values) High-level Languages support additional data types, such as character strings, files, pictures, or other data types designed for particular applications. 8-12

Data Types Many languages require an explicit declaration of the data type associated with a variable name. For example int age; string greeting; In Python, the data type is determined dynamically. age = 25 # stored as integer greeting = "Hello" # stored in ASCII 8-13

Assignment statement Python SSCPU age = 1 + age LDI 1 ADD age STO age the value of the right-hand expression is associated with the left-hand variable 8-14

Arrays and Lists Measurements Might refer to a specific entry, for example as: Measurements[6] 8-15

Output Commands Can evaluate and print any expression. Python SSCPU print age LOD OUT age print "Hello", guest (no equivalency in SSCPU) 8-16

Input Commands In Python, a response can be read from the user using the raw_input( ) command. guest = raw_input("who are you?") The variable is assigned to the string of characters entered by the user. If those characters are intended to represent a number, they must be explicitly converted. age = int(raw_input("how old are you?")) 8-17

Boolean Expressions Boolean expression: a sequence of identifiers, separated by compatible operators, that evaluates to True or False Boolean expression can be A Boolean variable An arithmetic expression followed by a relational operator followed by an arithmetic expression A Boolean expression followed by a Boolean operator followed by a Boolean expression 8-18

Relational, Logical Operators Relationship equal to not equal to less than less than or equal to greater than greater than or equal to Symbol ==!= < <= > >= Logical Operator and or not sample Boolean expressions: xvalue < yvalue name == "Michael" (temp >= 75.0) and (day == "Tues" or month!= "Oct") 8-19

Control Structures Control structure: an instruction that determines the order in which other instructions in a program are executed. These are implemented using the various "jump" commands in SSCPU. We will look at several common control structures: selection statements, looping statements, and subprogram statements 8-20

Selection Statements The if statement allows the program to test the state of affairs using a Boolean expression Python SSCPU if x < 0: x = -x LOD x JNG work JMP rest work LDI 0 SUB x STO x rest 8-21

If/Else Statements Figure 8.3 Flow of control of if statement 8-22

Selection Statements Python if temperature > 70: rating = 5 else: rating = 2 SSCPU LDI 70 SUB temperature JNG warm LDI 2 JMP save warm LDI 5 save STO rating 8-23

Looping Statements The while statement is used to repeat a course of action while boolean expr : loop body rest of program 8-24

While Loop High-Level Construct Low-Level Equivalency while boolean expr : loop body rest of program top [evaluate expression with result in Acc] JZR exit [body] JMP top exit [rest of program] 8-25

While loop example Python total = 0 val = int(raw_input( )) while val!= 0: total = total + val val = int(raw_input()) print total SSCPU LDI 0 STO total top INP JZR exit ADD total STO total JMP top exit LOD total OUT 8-26

While loop example Python count = 1 while count <= 5: print count count = count + 1 SSCPU LDI 1 STO count top LDI 5 SUB count JNG exit LOD count OUT ADD one STO count JMP top exit 8-27

Infinite loops, oops! What happens if the loop condition never becomes false? 8-28

Infinite loops, oops! count = 1 while count > 0: print count count = count + 1 8-29

Function Example def greeting(): print "Bonjour" greeting() 8-30

Subprogram/Functions If the language does not already include a particular behavior, we can define one! We give a section of code a name and use that name as a statement in another part of the program When the name is encountered, the processing in the other part of the program halts while the named code is executed 8-31

Subprogram Example Picture yourself in a boat And she s gone Chorus() Follow her down to a bridge and you re gone def Chorus(): Lucy in the sky with diamonds Lucy in the sky with diamonds Ahhh. Chorus() Picture yourself on a train 8-32

Parameters There are times when the calling unit needs to give information to the subprogram to use in its processing A parameter list is a list of the identifiers with which the subprogram is to work. (usually placed in parentheses, often with data type designations) 8-33

Parameter Example My Birthday Celebration Get Cake Place Candles in Cake Light Candles Sing( Michael ) Blow out Candles. Sing(name) Happy Birthday to you. Happy Birthday to you. Happy Birthday dear name Happy Birthday to you. 8-34

Function Example def greeting(person): print "Bonjour", person greeting("pierre") 8-35

Parameter Passing Value parameter: a parameter that expects a copy of its argument to be passed by the calling unit Reference parameter: a parameter that expects the address of its argument to be passed by the calling unit Analog to Machine Language: LDI vs LOD immediate operands vs. direct addressing 8-36

Machine Code Implementation The body of a function is code that can be stored somewhere in memory. A function call is enacted through the use of a JMP command. When the function completes, it must jump back to the context at which it was called. Technically, this requires a form of "jump" with an indirect operand (not supported by SSCPU) 8-37

Nested Subprograms Subprogram A( ) Call B( ) Subprogram B( ) Call C( ) Subprogram C( ) 8-38

Recursion Recursion: the ability of a subprogram to call itself Each recursive solution has at least two cases base case: the one to which we have an answer general case: expresses the solution in terms of a call to itself with a smaller version of the problem For example, the factorial of a number is defined as the number times the product of all the numbers between itself and 0: N! = N * (N 1)! 8-39

Recursion def factorial(n): if n <= 0: return 1 else: return n * factorial(n-1) 8-40