Lectures Basics in Procedural Programming: Machinery

Similar documents
Lecture Data Types and Types of a Language

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

Semantic Analysis: Types and Type Checking

Chapter 7: Functional Programming Languages

Programming Language Features (cont.) CMSC 330: Organization of Programming Languages. Parameter Passing in OCaml. Call-by-Value

Chapter 5 Names, Bindings, Type Checking, and Scopes

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

CSCI 3136 Principles of Programming Languages

[Refer Slide Time: 05:10]

Parameter Passing in Pascal

C++ INTERVIEW QUESTIONS

Functional Programming

Functional Programming in C++11

1.1 WHAT IS A PROGRAMMING LANGUAGE?

Symbol Tables. Introduction

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

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

Lecture 9. Semantic Analysis Scoping and Symbol Table

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

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

Data Types. Abstract Data Types. ADTs as Design Tool. Abstract Data Types. Integer ADT. Principle of Abstraction

Chapter 15 Functional Programming Languages

2) Write in detail the issues in the design of code generator.

Semester Review. CSC 301, Fall 2015

Parameter passing in LISP

Object-Oriented Software Specification in Programming Language Design and Implementation

Regression Verification: Status Report

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Lab Experience 17. Programming Language Translation

A Memory Model for Static Analysis of C Programs

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

CSC Software II: Principles of Programming Languages

Glossary of Object Oriented Terms

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

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

Tutorial on Writing Modular Programs in Scala

Compiler Construction

Comp151. Definitions & Declarations

Chapter 13 Storage classes

Unit 8: Immutability & Actors

Integrating Formal Models into the Programming Languages Course

Stack Allocation. Run-Time Data Structures. Static Structures

How To Understand The Theory Of Computer Science

Practical Generic Programming with OCaml

The C Programming Language course syllabus associate level

13 Classes & Objects with Constructors/Destructors

Introduction to C++ Introduction to C++ Week 7 Dr Alex Martin 2013 Slide 1

CS143 Handout 18 Summer 2012 July 16 th, 2012 Semantic Analysis

Parameter Passing. Parameter Passing. Parameter Passing Modes in Fortran. Parameter Passing Modes in C

Java Interview Questions and Answers

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example

C++ Programming Language

CSE 307: Principles of Programming Languages

Moving from CS 61A Scheme to CS 61B Java

COSC282 BIG DATA ANALYTICS FALL 2015 LECTURE 2 - SEP 9

Lecture 12: Abstract data types

Quotes from Object-Oriented Software Construction

GENERIC and GIMPLE: A New Tree Representation for Entire Functions

Regular Expressions and Automata using Haskell

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Introduction to Distributed Computing using CORBA

Object Oriented Software Design II

Passing Arguments. A comparison among programming languages. Curtis Bright. April 20, 2011

Habanero Extreme Scale Software Research Project

Recursion vs. Iteration Eliminating Recursion

1. Relational database accesses data in a sequential form. (Figures 7.1, 7.2)

Math Content by Strand 1

Getting Started with the Internet Communications Engine

Class 16: Function Parameters and Polymorphism

Infrastructure that supports (distributed) componentbased application development

Chapter One Introduction to Programming

Chapter 4 OOPS WITH C++ Sahaj Computer Solutions

Course: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1

Low Level Virtual Machine for Glasgow Haskell Compiler

Functional Programming. Functional Programming Languages. Chapter 14. Introduction

AUTOMATED TEST GENERATION FOR SOFTWARE COMPONENTS

CSE 373: Data Structure & Algorithms Lecture 25: Programming Languages. Nicki Dell Spring 2014

Spark: Cluster Computing with Working Sets

Functions and Parameter Passing

C++FA 3.1 OPTIMIZING C++

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Enforcing Security Policies. Rahul Gera

: provid.ir

Lecture 1: Introduction

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays:

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

TOWARDS A GREEN PROGRAMMING PARADIGM FOR MOBILE SOFTWARE DEVELOPMENT

OpenACC 2.0 and the PGI Accelerator Compilers

Tutorial on C Language Programming

Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006

Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding

Lecture 32: The Java Virtual Machine. The Java Virtual Machine

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

An Overview of Java. overview-1

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)

Programming Languages

Programming Languages

Inline Variables. Document Number: N4424 Date: Hal Finkel and Richard Smith

Transcription:

Lectures 3-4-5-6 Basics in Procedural Programming: Machinery February 21, 2014

Basics in Procedural Programming: Machinery Naming and Binding Mutable Values: Denotable, Storable and Expressible Value Env, Store, AR and Blocks: Motivations Blocks: Inline blocks and Procedure/function (body) block Blocks: Static and Dynamic Scope Activation Records: Structure and Implementation Programming Unit Aliasing, Closures, Lambda Lifting Env: Formalization and Implementation Store: Formalization and Implementation

Naming and Binding Naming = Use of identifiers to refer to definitions of programming entities Definition of the entity = Definition results a Denotable Value of the language semantic domain Den final double pigreco = 3.15; /*an example of constant*/ int y = 5; /*an example of variable*/ See next slide, for other examples of definitions. Binding = Association between the name and its definition Bindings of a program are all collected in the semantic structure Env

Mutable and Immutable values Names for Constants and Variables are in common use in the introduction (i.e. declaration) of values Variable = It is synonym of Mutable Value Mutable values are basics in Imperative Languages but they are non incompatible with Descriptive Languages, in principle However, problems arise from the different ways in which such values can be used in the program: Haskell preserves Transparency Property, instead Ocaml does not. Constant = It is an example of Immutable Value Var x: int /*Pascal Declaration of a mutable value*/ Const y:int /*Pascal Declaration of a immutable value*/ int z[] /*C Declaration of an immutable, structured, value with mutable components of type int */ *int y /*C Declaration of an mutable value that it is, in turn, a mutable value yet, namely a pointer*/ label u /*Pascal Declaration of a immutable value, namely a position in program */ void p(...){...} /*Declaration of an immutable value, namely a procedure*/ public class A{...} /*Declaration of an immutable value, namely a class (of Java)*/ struct S{...} /* Declaration of an immutable value, namely a type record (of C) */ type B =... /*Again, declaration, in OCaml, of an immutable value, namely a (concrete) type*/

Mutable and Immutable values: The Equality Property The two classes of values definitely, differ in some form of state that is underlying of mutable values. This is clearly, reflected from the behavior of (almost all) operations of the two classes, and then, from their use in programming. However, what about comparing two values? The Equality Property = Two values are equals only if they can be exchanged with one another, in the program. Each mutable value is equal only to itself Comment the equality predications in the following C++ text:

Mutable and Immutable values: Implementation Skills The two classes of values definitely, differ in some form of state that is underlying of mutable values. This is clearly, reflected from the behavior of (almost all) operations of the two classes, and then, from their use in programming. However, what can we say about the internal representation of such values? Implementation Skills One immuable and one immutable value in two different memory organizations: Memory on the right has a constant pool memory.

Den, Mem, Val: The Value Domains of a Language The Value (semantic) Domains are a fundamental characteristic of a language They highly constrain the way in which algorithms may be written, in the language Val = Domain of the Values that can be involved in the language programs Den = D. of the Values that can be expressed in definitions Mem = D. of the Mutable Values of the language The following hold: (1) Den Val; (2) Mem Val But: Den Mem = Val; Mem Val ; and so on... hold or not depending on the language int A[3] = {3,5,17}; /* define, in C, a mutable value in a binding for A */ A = {3,5,12}; /* is not permitted */ Then: Is {3,5,17} defining a mutable or immutable value? In providing for an answer, compare it with: int B = 3; /* define, in C, a mutable value in a binding for B */ B = 15; /* a common statement in C */ Then: 3 and 15 are immutable integers. What can you say about the other languages that you know?

Expressible Values Expressible Values = Have an explicit, syntactic, presentation in the language; These values are useful for introducing constant values in expressions; Hence, values of common use in the expressions of the language are also expressible value; Integers are expressible values of C Are arrays expressible values of C? Are lists expressible values of Ocaml (Haskell)? Are vectors expressible values of Java? Are functions expressible values of Ocaml (Haskell)? Are methods expressible values of Java?

Env, Store, AR Env = Semantic Structure for collecting the bindings of the program It is quite related to the symbol tables of the front-end of language executors and Compilers Machine Languages do not use naming and do not require Env Store = Semantic Structure for Mutable Values, i.e. Mem Additional Memory components are always present in the implementation machinery, to handle immutable values and the program representation of all languages (including pure Functional ones) AR = Implementation Machinery Component for the computation control It is used to support the program sectioning into parts that: can be executed separately, and, include inline blocks, procedures/functions, modules, monitors, threads,..

Program Sectioning: Blocks Block = It is used for creating sections of program that are: (partially) autonomous in the definitions that may be used, and may exhibit specific functionalities, and may be valid supports in program verification and modification Two main kinds in Procedural Programming: inline blocks procedures and functions

Blocks: Inline vs. Procedures Inline Blocks anonymous contain two parts: Local Definitions and End/Exit Code; may be nested: Execution exits nested blocks in reverse order to the entering Procedures and Functions named contain three parts: Parameter Transmission, Local Definitions and Return/Exit Code; (a) According to the above features, describe the features of the blocks of the compound statements of the language C. (b) Moreover, answer to: in what features the inline blocks of Java differ from the ones described in the slide Suggested Reading: Gabrielli M., S. Martini, Programming Languages: Principles and Paradigms, Springer, 2006 - Chapter 4-4.2