Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008.

Similar documents
CSI32 Object-Oriented Programming

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

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

Operational Semantics. One-Slide Summary. Lecture Outline

CS152 Programming Language Paradigms Prof. Tom Austin, Fall Syntax & Semantics, and Language Design Criteria

CS101 Introduction to Programming Languages and Compilers

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

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Lecture 13. Notation. The rules. Evaluation Rules So Far

Semantic Analysis. Lecture 9. February 7, 2018

Principles of Programming Languages. Lecture Outline

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Compiler Theory. (Semantic Analysis and Run-Time Environments)

Compilers. Prerequisites

The role of semantic analysis in a compiler

A Tour of Language Implementation

A Simple Syntax-Directed Translator

Concepts of Programming Languages

Introduction to Lexical Analysis

Programmiersprachen (Programming Languages)

CMSC 330: Organization of Programming Languages. Operational Semantics

Crafting a Compiler with C (II) Compiler V. S. Interpreter

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

Syntax. A. Bellaachia Page: 1

Formal Specification and Verification

Context Free Grammars, Parsing, and Amibuity. CS154 Chris Pollett Feb 28, 2007.

Operational Semantics of Cool

Software Engineering using Formal Methods

Chapter 1. Preliminaries

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

Programming Languages, Summary CSC419; Odelia Schwartz

CSc 372. Comparative Programming Languages. 2 : Functional Programming. Department of Computer Science University of Arizona

Lecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Notation. The rules. Evaluation Rules So Far.

CSE 12 Abstract Syntax Trees

A simple syntax-directed

Functional Programming. Big Picture. Design of Programming Languages

Programming Languages Third Edition. Chapter 7 Basic Semantics

Software Engineering using Formal Methods

Programming Languages Third Edition

Introduction to Scheme

Intermediate Code Generation

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking

Syntactic Analysis. CS345H: Programming Languages. Lecture 3: Lexical Analysis. Outline. Lexical Analysis. What is a Token? Tokens

MIDTERM EXAM (Solutions)

Intermediate Code Generation

CS4215 Programming Language Implementation

Com S 541. Programming Languages I

1. In waterfall model, output of one phase is input to next phase. True or false.

Compiler construction

Programming in C. main. Level 2. Level 2 Level 2. Level 3 Level 3

CS323 Lecture - Specifying Syntax and Semantics Last revised 1/16/09

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS

Decaf Language Reference Manual

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output

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

CS 415 Midterm Exam Spring SOLUTION

8/27/17. CS-3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES

Page # Expression Evaluation: Outline. CSCI: 4500/6500 Programming Languages. Expression Evaluation: Precedence

Programming Language Concepts, cs2104 Lecture 04 ( )

PROGRAMMING LANGUAGE PARADIGMS & THE MAIN PRINCIPLES OF OBJECT-ORIENTED PROGRAMMING

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

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

Outline. Introduction to Programming (in C++) Introduction. First program in C++ Programming examples

2.2 Syntax Definition

Introduction to Parsing. Lecture 8

Chapter 1 Preliminaries

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

Intermediate Code Generation

ECE251 Midterm practice questions, Fall 2010

CS 242. Fundamentals. Reading: See last slide

Introduction. Compiler Design CSE Overview. 2 Syntax-Directed Translation. 3 Phases of Translation

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

CS 3360 Design and Implementation of Programming Languages. Exam 1

Programming Languages 2nd edition Tucker and Noonan"

Intro to semantics; Small-step semantics Lecture 1 Tuesday, January 29, 2013

CS112 Lecture: Working with Numbers

Operational Semantics

CS321 Languages and Compiler Design I. Winter 2012 Lecture 1

CS558 Programming Languages

CSCE 314 Programming Languages

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres

Defining Program Syntax. Chapter Two Modern Programming Languages, 2nd ed. 1

COMP 102: Computers and Computing

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

CS558 Programming Languages. Winter 2013 Lecture 3

1 Lexical Considerations

CS 415 Midterm Exam Spring 2002

CSCI 3136 Principles of Programming Languages

Introduction to Parsing. Lecture 5

MIDTERM EXAMINATION - CS130 - Spring 2005

UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi

UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi

9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5

Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

G Programming Languages - Fall 2012

Structure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler.

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1

Chapter 4 Defining Classes I

CS 4120 and 5120 are really the same course. CS 4121 (5121) is required! Outline CS 4120 / 4121 CS 5120/ = 5 & 0 = 1. Course Information

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Transcription:

Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008.

Outline. Abstractions for telling a computer how to do things. Computational Paradigms. Language Definition, Translation.

Recall. Last day, we said: A programming language is a notational system for describing computation in a machine readable and in a human readable form. We explored what we meant by computation and what we meant by machine readable. Today, we begin by looking at some of the more common abstraction used by humans to tell machines what to do.

Abstractions for Programming Languages. The ways we describe what we d like a machine to do can be characterized in a couple different ways: Data abstractions versus control abstraction: the former is how we describe the data such as strings, numbers, etc we want the computer to manipulate, the later is how we describe the sequence of operation the machine should take, like loops, if-statements etc. Levels of abstraction such as Basic, Structured, or Unit Abstraction: these go from local machine information, to more global structure of the program, to entire components of the program. Let s look at some example of Data abstractions and control abstractions at each of these levels.

Data Abstractions. Basic Abstraction Examples: Rather than refer to how an integer is actually stored as bits in memory we might have a data type which acts as an integer and hides these details. For example, int x; in Java, C, etc. Rather than have to refer to memory location to talk about a particular integer, we instead have variables. Structured Abstraction Examples: A data structure is a tool for collecting related datatypes together. The most common example of such a structure is the notion of array that many languages support. Such an array might be declared with a line like: int a[10]; //in Java or C or INTEGER a(10) in Fortran. You might also have type declarations like. typedef int Intarray[10]; Unit Abstractions Examples: Here we might want to collect all the code related to a data structure in one place. For instance, we might want to data encapsulate the code for a List in a class, and we might want to hides it internals from users of this code (information hiding).

Control Abstractions. Basic Abstraction Examples: Typically a basic control abstraction combines a few machine code operations into one statement. For example, variable assignments such as: x =x +3; Another example, might be the GOTO assignment which abstracts the jump operations of the machine code. Ex: goto label; label: //do something. Structure Abstraction Examples: Break the code into groups of instructions together with tests that govern their execution. For example, if-statements, or case-statements (generally called selection statements). While, for, do, repeat. Function calls. These structure abstraction can often be nested such as have nested if s or a while outside an if, etc. Unit Abstraction: A stand-alone unit such a C library which collects together related procedures. Threads, processes, tasks.

Computational Paradigms. Sometimes the architecture of having a single processor executing instruction one at a time from memory using only a fixed number of other memory locations is called the von Neumann Architecture. Many common programming languages today such as C, abstract away the low-level messiness but otherwise map directly to this architecture. That is, one has a list of commands one executes in sequence. These languages are generally called imperative languages. The term procedural is also used. This is not the only framework (paradigm) for doing things. In some situation, such as in retrieving data from databases, parallel programming, etc other paradigms provide a more natural fit. We will now look at a few of these

Object-Oriented Programming. This paradigm is based on the notion of object. An object collects together a collections related properties, data structure, and the functions used to manipulate them.

Functional Programming. A functional programming language is based on the notion of function and applications of functions to known values. (Sometimes also called an applicative language). Scheme is an example of such a language. The definition of the gcd function in scheme might look like: (define (gcd u v) (if (= v 0) u (gcd v modulo(u v)))). We could then execute this with (gcd 6 3).

Logic Programming. Logic programming is based on using symbolic logic to declare what things are known. (hence, also called declarative programming). And then using unification and resolution to figure out wha the person wants. For example, gcd might be defined as: gcd(u, V, U) :- V = 0. gcd(u,v, X) :- not (V =0), Y is U mod V, gcd (V,Y,X).

Language Definition. There are several different ways one can define a programming language. One way is to write a compiler and say that the language is specified by how the compiler outputs your code. This is called creating a reference implementation. Some languages like PHP, Perl only do this. Another way to create a standard specification for the language is some English (or other human language) reference manual. To do this one needs to specify two things: Language Syntax: this describes what strings constitute programs in the given languages. A spec for the syntax might be to give a context free grammar. Such a grammar might have rules like: <if-statement> ::== if(<expression>) <statement> [else <statement>]. String like if and else in the above are called tokens. Their description form the lexical structure of the language. Language Semantics: a specification of this must describe how a given syntactic structure should be implemented on the computer. This can be English, or using one of a few common formal semantics such as: operational semantics, denotational semantics, or axiomatic semantics.

Language Translation. To be useful a programming language needs to have a translator. This is a program which either translates instances of the language into machine code, which can then be executes (compiler); or which takes instances of the languages and executes them as it read them (interpreter).