Fundamentals of Programming Languages

Size: px
Start display at page:

Download "Fundamentals of Programming Languages"

Transcription

1 Fundamentals of Programming Languages 1. DEFINITIONS BUILT-IN TYPES AND PRIMITIVE TYPES... 3 TYPE COMPATIBILITY... 9 GENERIC TYPES MONOMORPHIC VERSUS POLYMORPHIC TYPE IMPLEMENTATION MODELS IMPLEMENTATION OF STRUCTURED TYPES SCOPE ROUTINES OVERLOADING A. Bellaachia Page: 1

2 1. Definitions Attributes: o It is a set of properties used to describe a program entity, e.g., variable and function. o Example: Array: Name, Element type, Index type, Index lower bound, Index upper bound, and address. Variable: Name, Type, and Value. o Five Semantic Attributes of Variables In general, the semantics of variables in programming languages is often described in terms of four attributes. Name: It is the name used to refer to the variable. Type: A description of the set of permissible values for a variable. Scope: The region of program text over which a variable is known. l-value (or location): A location in memory associated with the variable. r-value: Typically, an indirect attribute of a variable; the value stored in the memory location associated with a variable. Descriptors: It is where the values of the attributes of an element are stored. Binding: o It is the process of assigning a value to the attribute of an element. o Binding Time: At what time a value is assigned an attribute. A. Bellaachia Page: 2

3 There are two types of binding: Static: o A binding is static if it first occurs before run time and remains unchanged throughout program execution. o Static binding occurs at: Compile time: Implementation time: Range of values for an integer. Language definition: Possible operators on strings: and +. Dynamic: o A binding is dynamic if it first occurs during execution or can change during execution of the program. o Dynamic binding occurs at: Run time: Assign a value to a variable. o Stability: Is the assignment of a value fixed or modifiable? 2. Built-in Types and Primitive Types What is a type? Values Operations A. Bellaachia Page: 3

4 A primitive type mimics hardware units. We call primitive types those types that are not built from other types. Example: Character is a primitive type in C, but String is not. Boolean is not a primitive type in C while it is in Java. Examples: Booleans Integers Reals Characters Benefits: Hides underlying representation Can do type checking at compile time Can resolve overloaded functions at compile time Programmer can specify the accuracy required Data Aggregates and Type Constructors o Definition: An aggregate data type, also called compound object, consists of one or more data type objects. Example: o Arrays: consists of one or more elements of a single data type placed in contiguous locations from first to last. A. Bellaachia Page: 4

5 o Constructors: It is the method used to create an aggregate data type. Examples: o Cartesian Products o Sequences o Etc. o Cartesian Product: A constructor used to create records and structures Definition: Cartesian product of n sets A1, A2, A3,, An is a set whose elements are ordered n-tuples (a1, a2, a3,, an), where each ak belongs to Ak for 1 k n. Example: o Structure in C o Records in Pascal and Ada. o A C example: #include <stdio.h> typedef struct { char name[30]; int age; char ssn[10]; } person; main (){ person myname = {"Bell", 20, " "}; printf("person Info: \n"); printf("\t\t%s\n\t\t%d\n\t\t%s\n", myname.name,myname.age, myname.ssn); A. Bellaachia Page: 5

6 } o Mapping Definition: o A mapping is a function from a set of values (domain) to a set of values (range): F: integer -> real Array Constructor: is a mapping from a set of integers (index) to a set of values (content of the array). Example: o Int myarray[5] ={-2,0,- 3,4,300}; MyArray: 0-2 MyArray: 1 0 MyArray: 2-3 MyArray: 3 4 MyArray: Another Example: enum Colors {red, white, black, green, blue}; The compiler assigns an integer number to each name in the enumerated type starting from zero. A. Bellaachia Page: 6

7 o Union and Discriminated Union Union is a constructor that allows objects to be specified by a disjunctive of fields, e.g., field 1 or field 2 or... or field n. An instance object has only one field: Save space. It is up to the programmer to remember which address is valid Example: o Variant records in Pascal o Union structures in C: union mixed { int i; float f; char c; }; union mixed m; m.i = 10; o Powerset: Powerset(T): This is a constructor that creates a variable whose value is a set of elements of type T. T is called the base type. Example: o set type in Pascal o Java APIs: Sets. A. Bellaachia Page: 7

8 o Sequence: Sequences constructor allows the creation of objects whose number of elements is not specified. Objects will have arbitrary size. Example: sequential files, Vector, List in Java. o Recursion Recursion is a constructor that allows the size of an object to grow dynamically (add or delete elements). Example: Create the structure of a Linked List in C typedef strcut { DoulyLinkedList * previous; Char name[30]; DoulyLinkedList * next; } doublylinkedlist; doublylinkedlist *head; A. Bellaachia Page: 8

9 Type Compatibility o Definitions: Type checking is the activity of ensuring that the operands of an operator are of compatible types Casting or Coercion: A compatible type is one that is either legal for the operator, or is allowed under language rules to be implicitly converted, by compiler-generated code, to a legal type. A type error is the application of an operator to an operand of an inappropriate type. Static type checking: If all type bindings are static. Dynamic type checking: If all type bindings are dynamic. o Strong Typing & Type Checking A type system is said to be strong if it guarantees not to generate type errors. Strongly typed languages: Languages that have strong type systems. Weakly typed languages: languages that are not strongly typed. Coercion rules weakens the value of strong typing Static Type System: The type of each expression must be known at compile time. Requirements of a static type system include: A. Bellaachia Page: 9

10 o Only built-in types can be used o All variables are declared with an associate type. o All operations are specified by stating the types of the required operands and the type of the results. Statically Typed Languages are Strongly Typed Languages. A. Bellaachia Page: 10

11 Compatible Types: o A compatible type is one that is either legal for the operator, or is allowed under language rules to be implicitly converted, by compiler-generated code, to a legal type. o Type compatibility is also called conformance or equivalence. o There are two type compatibility methods: Name compatibility (also called strict compatibility): o Two variables can have compatible types only if they are in either the same declaration or in declarations that use the same type name. o It is highly restrictive. o It is easier to implement. o Ada uses name compatibility. Structure type compatibility: o Two variables have compatible types if their types have identical structures. o It is more flexible. o It is difficult to implement: compare the whole structure instead of just names. o Two types are structurally compatible if: 1. T1 is name compatible with T2; or 2. T1 and T2 are defined by applying the same type constructor to structurally A. Bellaachia Page: 11

12 compatible corresponding type components. o Examples: 1. Two records or structure types compatible if they have same structure but different field names? 2. Two single-dimensioned array types in a Pascal or Ada program are compatible if they have the same element type but have different subscript ranges? 3. C uses structural compatibility except for structures. A. Bellaachia Page: 12

13 Type Conversion: o It is needed when the types of an expression are not compatible. o Some programming languages allow automatic conversions (Also called coercion): What would the following C program output? #include <stdio.h> main(){ char c1 = 'a'; int i = 10; i += c1; printf(" The value of i is:%d\n",i); } o Formally, the conversion of a type T 1 to another type T 2 is defined as follows: func: T 1 T 2 For example: T 1 x 1 ; T 2 x 2 ; x 2 = func(x 1 ); o How to use func to convert from another type T 2 to another type T 2? Requirements: Two new functions t 21 and r 12 : t 12 : T 1 T 2 A. Bellaachia Page: 13

14 r 23 : T 2 T 3 Let x 1 be a variable of type T 1 and y 3 be a variable of type T 3, then apply t 12 to x 1, apply t 23 to the result, and assign it to y 2 : y 3 = t 23 (t 12 ( x 1 ) ) ); Type and Subtype: o A subtype ST of a basic type T (also called parent type or supertype) can be defined as A subset of the values of T Assume that operations of T are inherited by ST o A language supporting subtypes must provide: A way to define subsets of a given type, and Compatibility rules between a subtype and its supertype Example: Ada subtype SUBTYPE Day_Range IS Integer RANGE 0..31; SUBTYPE Year_Range IS Integer RANGE ; SUBTYPE natural IS integer range 0..integer'last; SUBTYPE natural IS integer RANGE 0..integer last; SUBTYPE positive IS integer RANGE 1..integer last; Generic Types o It allows functions and ADT to have generic types o How type-checking is done to guarantee type safety? A. Bellaachia Page: 14

15 o Example: Bind generic types to concrete types at compile-time instantiation. push: stack(t)xt stack(t) pop: stack(t) stack(t)xt length: stack(t) int A. Bellaachia Page: 15

16 Monomorphic versus Polymorphic o Monorphic: It is a strict type system. o Polymorphic: It is the case where an object can have more than one type o Most practical programming languages have some degree of polymorphism. o Languages deviates form strict monomorphic if they include one of the following: Type equivalence Coercion Subtyping Overloading o Polymorphism classification: universal Parametric (Templates) Inclusion (subtypes) polymorphism overloading Ad hoc coercion A. Bellaachia Page: 16

17 Ad hoc : functions work on a finite small set of types and may behave differently for each: Overloading Coercion Universal: work uniformly for an infinite set of types, all of which have common structure Parametric Inclusion A. Bellaachia Page: 17

18 Type Implementation Models o How to represent data objects inside the machine o The implementation of each data object requires two elements: Descriptor: structures used to store the attributes of the data Data object: memory locations to store the actual values o Built-in Primitive types: Integers and reals are supported on most computers They may also provide different sized versions of these types Representations: Descriptor integer sign bit Descriptor real sign bit for mantissa sign bit for exponent k-bit exponent h-bit mantissa A. Bellaachia Page: 18

19 Implementation of Structured Types o Cartesian product: It is a sequential layout of components. The descriptor contains the following: o The Cartesian product type name and o For each field: Name of the selector Type of the field Reference to the data object Example: type another_type is struct{ float a; int b; }; type sample_type is struct{ int x; another_type y; }; sample_type z; Sample_type Struct x int y another_type struct a float b int Integer value Floating point value Integer value A. Bellaachia Page: 19

20 o Finite Mapping Allocate storage units for each element component. The descriptor contains the following: o The mapping type name o The name of the domain type o Values for the upper and lower bounds. o The name of the range type o A reference to the first location of the mapping Example: type x_type is float array[0..10]; x_type x; Type x_type 0 Constructor array 1 Index type int Lower bound 0 Upper bound 10 Range type float Reference 10 A. Bellaachia Page: 20

21 o Union and discriminated union The descriptor of a variable of a union type is the sequence of the descriptors of each component. Example: type x_type = array[0..10] of real; type z_type = record case kind: boolean of true: (a:integer); false: (b:x_type); end; Type Z_type constructor Variant record Selector Kind Type Boolean Case table Boolean value Reference Case table True false Selector b Type X_type Constructor array Selector a Index type Integer Type L. bound 0 reference integer U. bound 10 Range type real Reference A. Bellaachia Page: 21

22 o Powerset Use bit-mapping to represent a set Use AND for Intersection and OR for union Example: S = {1, 3, 10, 16} A. Bellaachia Page: 22

23 3. Scope Definitions: The scope of a variable is the range of statements over which it is visible The scope rules of a language determine how references to names are associated with variables. Example: #include <stdio.h> main( ) { int x, y; printf("please enter a value for x: "); scanf( "%d", &x ); printf("please enter a value for y: "); scanf( "%d", &y ); { // This block used to swap x and y int temp; temp = x; x = y; y = temp; } printf( "x:%d and y:%d\n", x, y ); // printf( "temp:%d\n", temp ); } If you try to execute the last statement in Visual C++, you will get the following error: error C2065: 'temp' : undeclared identifier Non-local variables: The non-local variables of a program unit are those that are visible but not declared in the program. A. Bellaachia Page: 23

24 Example: #include <stdio.h> float increase_factor = 10.5; main() { float x; printf("please enter a value for x: "); scanf( "%f", &x ); printf( "The input value is: %f\n",x); // increase_factor variable is used but not declared in // main function. printf( "The increased value is: %f\n",x * increase_factor); } Searching: Search declarations, first locally, then in increasingly larger enclosing scopes, until one is found for the given name Main A C D B E A. Bellaachia Page: 24

25 Scoping types: Static scope binding: The scope of a variable is defined by examining the program code. You do not need to run the program. Dynamic scope binding: o The scope of a variable is defined at runtime. o Example: MAIN { - declaration of x SUB1 { - declaration of x -... call SUB2... } SUB2 {... - reference to x -... }... call SUB1 } MAIN calls SUB1 SUB1 calls SUB2 SUB2 uses x Static scooping: reference to x is to MAIN's x Dynamic scooping: reference to x is to SUB1's x A. Bellaachia Page: 25

26 4. Routines We will use the term routine to mean: Subprograms: Assembler Subroutines: FORTRAN Procedures: Pascal, Ada Functions: C, LISP Methods: Java, C++ Routine Parts: Declaration: o The Specification of the name, list of formal parameters, and any return type. Body o The list of statements within the definition of the routine. Invocation: o Statement used to call the routine. Routine Attributes: Name Scope: It is similar to variable scope. Type: It is defined by the routine header: Name of the routine, the types of the parameters, and the type of the returned type. L-value: It is the memory area where the body of the routine is stored. R-value: It is the body of the routine. Routine Parameters: Formal parameters: o It is the set of parameters that appear in the routine s definition. Actual parameters: A. Bellaachia Page: 26

27 o It is the set of parameters that appear in the routine s call. Some programming languages have positional method and named for binding actual parameters to formal parameters in routine calls. Routine Signature: This specifies the types of the parameters and the return type. Activation record: o Data objects associated with local variables (including any parameters) o The relative position (offset) of the data object in the activation record. o Return pointer: It is the address where execution must resume in the calling routine. 5. Overloading Overloading: Method overloading is commonly used to create several methods with the same name that perform similar tasks: public int square (int side); public double square(double side) Java enables methods of the same name to be defined as long as they have different signatures. A C++ Example: #include <iostream.h> int max(int x, int y){ return (x>y?x:y); A. Bellaachia Page: 27

28 } float max(float x, float y){ return (x>y?x:y); } void main(){ } float a = 4.5; float b = 3.4; cout << max(3,6) << endl; cout << max(a,b) << endl; A. Bellaachia Page: 28

Binding and Variables

Binding and Variables Binding and Variables 1. DEFINITIONS... 2 2. VARIABLES... 3 3. TYPE... 4 4. SCOPE... 4 5. REFERENCES... 7 6. ROUTINES... 9 7. ALIASING AND OVERLOADING... 10 8. GENERICS AND TEMPLATES... 12 A. Bellaachia

More information

Basic Types & User Defined Types

Basic Types & User Defined Types Basic Types & User Defined Types 1. Objectives... 2 2. Built-in Types and Primitive Types... 2 3. Data Aggregates and Type Constructors... 3 4. Constructors... 3 5. User-defined Types and Abstract Data

More information

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result. Every program uses data, either explicitly or implicitly to arrive at a result. Data in a program is collected into data structures, and is manipulated by algorithms. Algorithms + Data Structures = Programs

More information

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6] 1 Lecture Overview Types 1. Type systems 2. How to think about types 3. The classification of types 4. Type equivalence structural equivalence name equivalence 5. Type compatibility 6. Type inference [Scott,

More information

UNIT II Structuring the Data, Computations and Program. Kainjan Sanghavi

UNIT II Structuring the Data, Computations and Program. Kainjan Sanghavi UNIT II Structuring the Data, Computations and Program B y Kainjan Sanghavi Contents Monomorphic versus polymorphic type systems Case Study- The type structure of C++ and Java Structuring the computation

More information

Data types. Definitions Aggregate constructors User-defined type definitions Types and storage Types and subtypes Type systems and type checking

Data types. Definitions Aggregate constructors User-defined type definitions Types and storage Types and subtypes Type systems and type checking Data types Definitions Aggregate constructors User-defined type definitions Types and storage Types and subtypes Type systems and type checking Ghezzi&Jazayeri: Ch 3 1 Data types Definition: a set of values

More information

Sub- PPL Unit-II Class-SE Comp

Sub- PPL Unit-II Class-SE Comp A] STRUCTURING OF DATA: WHAT IS A TYPE? 1. Programming languages organize data through the concept of type. Types are used as a way to classify data according to different categories. 2. They are more,

More information

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

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms SE352b Software Engineering Design Tools W3: Programming Paradigms Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa SE352b: Roadmap CASE Tools: Introduction System Programming Tools Programming Paradigms

More information

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University G22.2110-001 Programming Languages Spring 2010 Lecture 6 Robert Grimm, New York University 1 Review Last week Function Languages Lambda Calculus SCHEME review 2 Outline Promises, promises, promises Types,

More information

CPSC 3740 Programming Languages University of Lethbridge. Data Types

CPSC 3740 Programming Languages University of Lethbridge. Data Types Data Types A data type defines a collection of data values and a set of predefined operations on those values Some languages allow user to define additional types Useful for error detection through type

More information

Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Names, Bindings, Type Checking, and Scopes 長庚大學資訊工程學系 陳仁暉 助理教授 Tel: (03) 211-8800 Ext: 5990 E-mail: jhchen@mail.cgu.edu.tw URL: http://www.csie.cgu.edu.tw/jhchen All rights reserved. No part

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

Chapter 5 Names, Binding, Type Checking and Scopes

Chapter 5 Names, Binding, Type Checking and Scopes Chapter 5 Names, Binding, Type Checking and Scopes Names - We discuss all user-defined names here - Design issues for names: -Maximum length? - Are connector characters allowed? - Are names case sensitive?

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Structuring the Data. Structuring the Data

Structuring the Data. Structuring the Data 2017-05-12 Structuring the Data Structuring the Data 2017-05-12 Structuring the Data 1 Why Use (Static, Strong) Types? hide machine representation improves programming style and maintainability consistent

More information

Informatica 3 Syntax and Semantics

Informatica 3 Syntax and Semantics Informatica 3 Syntax and Semantics Marcello Restelli 9/15/07 Laurea in Ingegneria Informatica Politecnico di Milano Introduction Introduction to the concepts of syntax and semantics Binding Variables Routines

More information

Type Bindings. Static Type Binding

Type Bindings. Static Type Binding Type Bindings Two key issues in binding (or associating) a type to an identifier: How is type binding specified? When does the type binding take place? N. Meng, S. Arthur 1 Static Type Binding An explicit

More information

Lecture 12: Data Types (and Some Leftover ML)

Lecture 12: Data Types (and Some Leftover ML) Lecture 12: Data Types (and Some Leftover ML) COMP 524 Programming Language Concepts Stephen Olivier March 3, 2009 Based on slides by A. Block, notes by N. Fisher, F. Hernandez-Campos, and D. Stotts Goals

More information

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

9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5 Outline Name, Scope and Binding In Text: Chapter 5 Names Variable Binding Type bindings, type conversion Storage bindings and lifetime Scope Lifetime vs. Scope Referencing Environments N. Meng, S. Arthur

More information

Types. What is a type?

Types. What is a type? Types What is a type? Type checking Type conversion Aggregates: strings, arrays, structures Enumeration types Subtypes Types, CS314 Fall 01 BGRyder 1 What is a type? A set of values and the valid operations

More information

Note 3. Types. Yunheung Paek. Associate Professor Software Optimizations and Restructuring Lab. Seoul National University

Note 3. Types. Yunheung Paek. Associate Professor Software Optimizations and Restructuring Lab. Seoul National University Note 3 Types Yunheung Paek Associate Professor Software Optimizations and Restructuring Lab. Seoul National University Topics Definition of a type Kinds of types Issues on types Type checking Type conversion

More information

Names, Scopes, and Bindings II. Hwansoo Han

Names, Scopes, and Bindings II. Hwansoo Han Names, Scopes, and Bindings II Hwansoo Han Scope Rules A scope is textual region where bindings are active A program section of maximal size Bindings become active at the entry No bindings change in the

More information

Answer: Early binding generally leads to greater efficiency (compilation approach) Late binding general leads to greater flexibility

Answer: Early binding generally leads to greater efficiency (compilation approach) Late binding general leads to greater flexibility Quiz Review Q1. What is the advantage of binding things as early as possible? Is there any advantage to delaying binding? Answer: Early binding generally leads to greater efficiency (compilation approach)

More information

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages 1 / 26 CSE 307: Principles of Programming Languages Names, Scopes, and Bindings R. Sekar 2 / 26 Topics Bindings 1. Bindings Bindings: Names and Attributes Names are a fundamental abstraction in languages

More information

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011 Data Types (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011 Based in part on slides and notes by Bjoern 1 Brandenburg, S. Olivier and A. Block. 1 Data Types Hardware-level:

More information

CSC 533: Organization of Programming Languages. Spring 2005

CSC 533: Organization of Programming Languages. Spring 2005 CSC 533: Organization of Programming Languages Spring 2005 Language features and issues variables & bindings data types primitive complex/structured expressions & assignments control structures subprograms

More information

CSE 431S Type Checking. Washington University Spring 2013

CSE 431S Type Checking. Washington University Spring 2013 CSE 431S Type Checking Washington University Spring 2013 Type Checking When are types checked? Statically at compile time Compiler does type checking during compilation Ideally eliminate runtime checks

More information

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 17: Types and Type-Checking 25 Feb 08 CS 412/413 Spring 2008 Introduction to Compilers 1 What Are Types? Types describe the values possibly

More information

Programming Languages, Summary CSC419; Odelia Schwartz

Programming Languages, Summary CSC419; Odelia Schwartz Programming Languages, Summary CSC419; Odelia Schwartz Chapter 1 Topics Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design

More information

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

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer. The Compiler So Far CSC 4181 Compiler Construction Scanner - Lexical analysis Detects inputs with illegal tokens e.g.: main 5 (); Parser - Syntactic analysis Detects inputs with ill-formed parse trees

More information

22c:111 Programming Language Concepts. Fall Types I

22c:111 Programming Language Concepts. Fall Types I 22c:111 Programming Language Concepts Fall 2008 Types I Copyright 2007-08, The McGraw-Hill Company and Cesare Tinelli. These notes were originally developed by Allen Tucker, Robert Noonan and modified

More information

CSCI312 Principles of Programming Languages!

CSCI312 Principles of Programming Languages! CSCI312 Principles of Programming Languages! Chapter 5 Types Xu Liu! ! 5.1!Type Errors! 5.2!Static and Dynamic Typing! 5.3!Basic Types! 5.4!NonBasic Types! 5.5!Recursive Data Types! 5.6!Functions as Types!

More information

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

Organization of Programming Languages CS320/520N. Lecture 06. Razvan C. Bunescu School of Electrical Engineering and Computer Science Organization of Programming Languages CS320/520N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Data Types A data type defines a collection of data objects and

More information

Implementing Subprograms

Implementing Subprograms Implementing Subprograms 1 Topics The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing Subprograms with Stack-Dynamic Local Variables Nested Subprograms Blocks Implementing

More information

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

SEMANTIC ANALYSIS TYPES AND DECLARATIONS SEMANTIC ANALYSIS CS 403: Type Checking Stefan D. Bruda Winter 2015 Parsing only verifies that the program consists of tokens arranged in a syntactically valid combination now we move to check whether

More information

Lecture 7: Type Systems and Symbol Tables. CS 540 George Mason University

Lecture 7: Type Systems and Symbol Tables. CS 540 George Mason University Lecture 7: Type Systems and Symbol Tables CS 540 George Mason University Static Analysis Compilers examine code to find semantic problems. Easy: undeclared variables, tag matching Difficult: preventing

More information

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1

Object-Oriented Languages and Object-Oriented Design. Ghezzi&Jazayeri: OO Languages 1 Object-Oriented Languages and Object-Oriented Design Ghezzi&Jazayeri: OO Languages 1 What is an OO language? In Ada and Modula 2 one can define objects encapsulate a data structure and relevant operations

More information

Imperative Programming

Imperative Programming Naming, scoping, binding, etc. Instructor: Dr. B. Cheng Fall 2004 1 Imperative Programming The central feature of imperative languages are variables Variables are abstractions for memory cells in a Von

More information

Chapter 1: Object-Oriented Programming Using C++

Chapter 1: Object-Oriented Programming Using C++ Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms

More information

User-Defined Algebraic Data Types

User-Defined Algebraic Data Types 72 Static Semantics User-Defined Types User-Defined Algebraic Data Types An algebraic data type declaration has the general form: data cx T α 1... α k = K 1 τ 11... τ 1k1... K n τ n1... τ nkn introduces

More information

Chapter 5. Names, Bindings, and Scopes

Chapter 5. Names, Bindings, and Scopes Chapter 5 Names, Bindings, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Scope Scope and Lifetime Referencing Environments Named Constants 1-2 Introduction Imperative

More information

Types. Chapter Six Modern Programming Languages, 2nd ed. 1

Types. Chapter Six Modern Programming Languages, 2nd ed. 1 Types Chapter Six Modern Programming Languages, 2nd ed. 1 A Type Is A Set int n; When you declare that a variable has a certain type, you are saying that the values the variable can have are elements of

More information

Fundamentals of Programming Languages. Data Types Lecture 07 sl. dr. ing. Ciprian-Bogdan Chirila

Fundamentals of Programming Languages. Data Types Lecture 07 sl. dr. ing. Ciprian-Bogdan Chirila Fundamentals of Programming Languages Data Types Lecture 07 sl. dr. ing. Ciprian-Bogdan Chirila Predefined types Programmer defined types Scalar types Structured data types Cartesian product Finite projection

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Static Semantics. Winter /3/ Hal Perkins & UW CSE I-1

Static Semantics. Winter /3/ Hal Perkins & UW CSE I-1 CSE 401 Compilers Static Semantics Hal Perkins Winter 2009 2/3/2009 2002-09 Hal Perkins & UW CSE I-1 Agenda Static semantics Types Symbol tables General ideas for now; details later for MiniJava project

More information

Programming Languages

Programming Languages Programming Languages Types CSCI-GA.2110-001 Summer 2011 What is a type? A type consists of a set of values The compiler/interpreter defines a mapping of these values onto the underlying hardware. 2 /

More information

CS349/SE382 A1 C Programming Tutorial

CS349/SE382 A1 C Programming Tutorial CS349/SE382 A1 C Programming Tutorial Erin Lester January 2005 Outline Comments Variable Declarations Objects Dynamic Memory Boolean Type structs, enums and unions Other Differences The Event Loop Comments

More information

NOTE: Answer ANY FOUR of the following 6 sections:

NOTE: Answer ANY FOUR of the following 6 sections: A-PDF MERGER DEMO Philadelphia University Lecturer: Dr. Nadia Y. Yousif Coordinator: Dr. Nadia Y. Yousif Internal Examiner: Dr. Raad Fadhel Examination Paper... Programming Languages Paradigms (750321)

More information

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING 1. Object Oriented Programming Paradigms 2. Comparison of Programming Paradigms 3. Basic Object Oriented Programming

More information

Data Types. Data Types. Introduction. Data Types. Data Types. Data Types. Introduction

Data Types. Data Types. Introduction. Data Types. Data Types. Data Types. Introduction Introduction Primitive Composite Structured Abstract Introduction Introduction Data Type is a Collection of Data Objects Possible r-values for a memory cell Set of operations on those objects Descriptor

More information

Data Types. Outline. In Text: Chapter 6. What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers 5-1. Chapter 6: Data Types 2

Data Types. Outline. In Text: Chapter 6. What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers 5-1. Chapter 6: Data Types 2 Data Types In Text: Chapter 6 1 Outline What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers Chapter 6: Data Types 2 5-1 Data Types Two components: Set of objects in the type (domain

More information

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking CS 430 Spring 2015 Mike Lam, Professor Data Types and Type Checking Type Systems Type system Rules about valid types, type compatibility, and how data values can be used Benefits of a robust type system

More information

Semantic Analysis. How to Ensure Type-Safety. What Are Types? Static vs. Dynamic Typing. Type Checking. Last time: CS412/CS413

Semantic Analysis. How to Ensure Type-Safety. What Are Types? Static vs. Dynamic Typing. Type Checking. Last time: CS412/CS413 CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 13: Types and Type-Checking 19 Feb 07 Semantic Analysis Last time: Semantic errors related to scopes Symbol tables Name resolution This lecture:

More information

TYPES, VALUES AND DECLARATIONS

TYPES, VALUES AND DECLARATIONS COSC 2P90 TYPES, VALUES AND DECLARATIONS (c) S. Thompson, M. Winters 1 Names, References, Values & Types data items have a value and a type type determines set of operations variables Have an identifier

More information

Organization of Programming Languages CS 3200/5200N. Lecture 09

Organization of Programming Languages CS 3200/5200N. Lecture 09 Organization of Programming Languages CS 3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Control Flow Control flow = the flow of control, or execution

More information

Chapter 11. Abstract Data Types and Encapsulation Concepts ISBN

Chapter 11. Abstract Data Types and Encapsulation Concepts ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts ISBN 0-321-49362-1 Chapter 11 Topics The Concept of Abstraction Introduction to Data Abstraction Design Issues for Abstract Data Types Language

More information

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and #include The Use of printf() and scanf() The Use of printf()

More information

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

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking Agenda COMP 181 Type checking October 21, 2009 Next week OOPSLA: Object-oriented Programming Systems Languages and Applications One of the top PL conferences Monday (Oct 26 th ) In-class midterm Review

More information

0. Overview of this standard Design entities and configurations... 5

0. Overview of this standard Design entities and configurations... 5 Contents 0. Overview of this standard... 1 0.1 Intent and scope of this standard... 1 0.2 Structure and terminology of this standard... 1 0.2.1 Syntactic description... 2 0.2.2 Semantic description...

More information

DATA TYPES. CS 403: Types and Classes DATA TYPES (CONT D)

DATA TYPES. CS 403: Types and Classes DATA TYPES (CONT D) DATA TYPES CS 403: Types and Classes Stefan D. Bruda Fall 2017 Algorithms + data structures = programs Abstractions of data entities highly desirable Program semantics embedded in data types Data types

More information

10. Abstract Data Types

10. Abstract Data Types 10. Abstract Data Types 11.1 The Concept of Abstraction The concept of abstraction is fundamental in programming Nearly all programming languages support process abstraction with subprograms Nearly all

More information

Programming Languages Third Edition. Chapter 7 Basic Semantics

Programming Languages Third Edition. Chapter 7 Basic Semantics Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol

More information

Intermediate Code Generation Part II

Intermediate Code Generation Part II Intermediate Code Generation Part II Chapter 6: Type checking, Control Flow Slides adapted from : Robert van Engelen, Florida State University Static versus Dynamic Checking Static checking: the compiler

More information

Subprograms. Copyright 2015 Pearson. All rights reserved. 1-1

Subprograms. Copyright 2015 Pearson. All rights reserved. 1-1 Subprograms Introduction Fundamentals of Subprograms Design Issues for Subprograms Local Referencing Environments Parameter-Passing Methods Parameters That Are Subprograms Calling Subprograms Indirectly

More information

Properties of an identifier (and the object it represents) may be set at

Properties of an identifier (and the object it represents) may be set at Properties of an identifier (and the object it represents) may be set at Compile-time These are static properties as they do not change during execution. Examples include the type of a variable, the value

More information

Data Types In Text: Ch C apter 6 1

Data Types In Text: Ch C apter 6 1 Data Types In Text: Chapter 6 1 Outline What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers 2 Data Types Two components: Set of objects in the type (domain of values) Set of applicable

More information

Organization of Programming Languages CS3200 / 5200N. Lecture 06

Organization of Programming Languages CS3200 / 5200N. Lecture 06 Organization of Programming Languages CS3200 / 5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Data Types A data type defines a collection of data objects

More information

Programming Languages

Programming Languages Programming Languages Types CSCI-GA.2110-003 Fall 2011 What is a type? An interpretation of numbers Consists of a set of values The compiler/interpreter defines a mapping of these values onto the underlying

More information

Chapter 6. Data Types ISBN

Chapter 6. Data Types ISBN Chapter 6 Data Types ISBN 0-321 49362-1 Chapter 6 Topics Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer

More information

CS321 Languages and Compiler Design I Winter 2012 Lecture 13

CS321 Languages and Compiler Design I Winter 2012 Lecture 13 STATIC SEMANTICS Static Semantics are those aspects of a program s meaning that can be studied at at compile time (i.e., without running the program). Contrasts with Dynamic Semantics, which describe how

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 6 Thomas Wies New York University Review Last week Functional Languages Lambda Calculus Scheme Outline Types Sources: PLP, ch. 7 Types What is a type?

More information

Programming Languages: Lecture 11

Programming Languages: Lecture 11 1 Programming Languages: Lecture 11 Chapter 9: Subprograms Jinwoo Kim jwkim@jjay.cuny.edu Chapter 9 Topics 2 Introduction Fundamentals of Subprograms Design Issues for Subprograms Local Referencing Environments

More information

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages 1 / 57 CSE 307: Principles of Programming Languages Course Review R. Sekar Course Topics Introduction and History Syntax Values and types Names, Scopes and Bindings Variables and Constants Expressions

More information

Fundamental Concepts and Definitions

Fundamental Concepts and Definitions Fundamental Concepts and Definitions Identifier / Symbol / Name These terms are synonymous: they refer to the name given to a programming component. Classes, variables, functions, and methods are the most

More information

Programmiersprachen (Programming Languages)

Programmiersprachen (Programming Languages) 2016-05-13 Preface Programmiersprachen (Programming Languages) coordinates: lecturer: web: usable for: requirements: No. 185.208, VU, 3 ECTS Franz Puntigam http://www.complang.tuwien.ac.at/franz/ps.html

More information

Data Abstraction. Hwansoo Han

Data Abstraction. Hwansoo Han Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed

More information

Object-oriented Programming. Object-oriented Programming

Object-oriented Programming. Object-oriented Programming 2014-06-13 Object-oriented Programming Object-oriented Programming 2014-06-13 Object-oriented Programming 1 Object-oriented Languages object-based: language that supports objects class-based: language

More information

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

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline CS 0 Lecture 8 Chapter 5 Louden Outline The symbol table Static scoping vs dynamic scoping Symbol table Dictionary associates names to attributes In general: hash tables, tree and lists (assignment ) can

More information

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

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam Compilers Type checking Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Summary of parsing Parsing A solid foundation: context-free grammars A simple parser: LL(1) A more powerful parser:

More information

Types II. Hwansoo Han

Types II. Hwansoo Han Types II Hwansoo Han Arrays Most common and important composite data types Homogeneous elements, unlike records Fortran77 requires element type be scalar Elements can be any type (Fortran90, etc.) A mapping

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF

More information

CSE P 501 Compilers. Static Semantics Hal Perkins Winter /22/ Hal Perkins & UW CSE I-1

CSE P 501 Compilers. Static Semantics Hal Perkins Winter /22/ Hal Perkins & UW CSE I-1 CSE P 501 Compilers Static Semantics Hal Perkins Winter 2008 1/22/2008 2002-08 Hal Perkins & UW CSE I-1 Agenda Static semantics Types Attribute grammars Representing types Symbol tables Note: this covers

More information

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS Contents Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS 1.1. INTRODUCTION TO COMPUTERS... 1 1.2. HISTORY OF C & C++... 3 1.3. DESIGN, DEVELOPMENT AND EXECUTION OF A PROGRAM... 3 1.4 TESTING OF PROGRAMS...

More information

CS 230 Programming Languages

CS 230 Programming Languages CS 230 Programming Languages 11 / 20 / 2015 Instructor: Michael Eckmann Questions/comments? Chapter 6 Arrays Pointers Today s Topics We all know what arrays are. Design issues Legal types for subscripts

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2016 Lecture 7a Andrew Tolmach Portland State University 1994-2016 Values and Types We divide the universe of values according to types A type is a set of values and a

More information

Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types

Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types Chapter 6 Topics WEEK E FOUR Data Types Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer and Reference

More information

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

Design issues for objectoriented. languages. Objects-only pure language vs mixed. Are subclasses subtypes of the superclass? Encapsulation Encapsulation grouping of subprograms and the data they manipulate Information hiding abstract data types type definition is hidden from the user variables of the type can be declared variables

More information

C-LANGUAGE CURRICULAM

C-LANGUAGE CURRICULAM C-LANGUAGE CURRICULAM Duration: 2 Months. 1. Introducing C 1.1 History of C Origin Standardization C-Based Languages 1.2 Strengths and Weaknesses Of C Strengths Weaknesses Effective Use of C 2. C Fundamentals

More information

Advanced oo concepts Specialization of behaviour? Multiple inheritance - alternatives to. Inner classes Classes

Advanced oo concepts Specialization of behaviour? Multiple inheritance - alternatives to. Inner classes Classes Types and Classes I II From predefined (simple) and user-defined (composite) types via Abstract data types Advanced oo concepts Specialization of behaviour? Multiple inheritance - alternatives to Inner

More information

Polymorphism. Chapter Eight Modern Programming Languages, 2nd ed. 1

Polymorphism. Chapter Eight Modern Programming Languages, 2nd ed. 1 Polymorphism Chapter Eight Modern Programming Languages, 2nd ed. 1 Introduction Compare these function types The ML function is more flexible, since it can be applied to any pair of the same (equality-testable)

More information

Chapter 11. Abstract Data Types and Encapsulation Concepts

Chapter 11. Abstract Data Types and Encapsulation Concepts Chapter 11 Abstract Data Types and Encapsulation Concepts Chapter 11 Topics The Concept of Abstraction Introduction to Data Abstraction Design Issues for Abstract Data Types Language Examples Parameterized

More information

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem:

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem: Expression evaluation CSE 504 Order of evaluation For the abstract syntax tree + + 5 Expression Evaluation, Runtime Environments + + x 3 2 4 the equivalent expression is (x + 3) + (2 + 4) + 5 1 2 (. Contd

More information

Chapter 11. Abstract Data Types and Encapsulation Concepts

Chapter 11. Abstract Data Types and Encapsulation Concepts Chapter 11 Abstract Data Types and Encapsulation Concepts The Concept of Abstraction An abstraction is a view or representation of an entity that includes only the most significant attributes The concept

More information

Chapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc.

Chapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc. Chapter 13 Object Oriented Programming Contents 13.1 Prelude: Abstract Data Types 13.2 The Object Model 13.4 Java 13.1 Prelude: Abstract Data Types Imperative programming paradigm Algorithms + Data Structures

More information

Chapter 4 Defining Classes I

Chapter 4 Defining Classes I Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the

More information

Chapter 9. Subprograms

Chapter 9. Subprograms Chapter 9 Subprograms Chapter 9 Topics Introduction Fundamentals of Subprograms Design Issues for Subprograms Local Referencing Environments Parameter-Passing Methods Parameters That Are Subprograms Calling

More information