Data elements and bindings

Size: px
Start display at page:

Download "Data elements and bindings"

Transcription

1 Imperative programming Data elements and bindings Variables and their values Expression (value) evaluation Binding of variables and types static and dynamic binding Lifetime of variables Scopes of variables static and dynamic scoping Lambdas in C++11 TUT Pervasive Computing 1

2 von Neumann Memory (instructions and data) architecture Instructions and data Results of operations CPU Arithmetic and logic unit Control unit Input and output devices Imperative programming variable assignment von Neumannin architecture memory cell transfer (CPU-memory) TUT Pervasive Computing 2

3 Data items (variables) Creating and handling data is based on changing the state (memory content) of the computer Essential operation of the program memory location = space for data item content of the location = value of the data item Pointer/reference type value of a data item is a memory address or a reference to a memory location in most languages identifies a variable equal pointers = same variables A named variable can be either a data item or a reference to it TUT Pervasive Computing 3

4 Variables vs. memory location for a variable value of a variable Characteristics: name address (L-value) value (R-value) type lifetime scope Aliasing Pascal: Fortran: C: X := X + 1; var X: Integer; subroutine SUM ( I, J, K ) integer I, J, K I = J + K return end call SUM ( 1, 2, 3 ) ( f ( a ) + 3 ) -> b [ c ] = 2; TUT Pervasive Computing 4

5 Value vs. reference semantics In some languages (C, C++, ) variables contain the data In other languages (Java, Python, ) variables (=names) are references to objects that contain the data Affects how variables/objects work (e.g. lifetime, memory allocation) A major source of confusion when changing to another language TUT Pervasive Computing

6 Value semantics Variables: named data items (Nameless variables also possible) Assigning to a variable changes the data Pointers/references: variables that refer to another variable p a 3 TUT Pervasive Computing

7 Reference semantics Objects: nameless data items Variables/references/names (term depend on language): named references to objects (Nameless references also possible) Assigning to a variable changes the reference (refer now to another object) Objects and variables separate, variables cannot refer to other variables, only to objects 3 a TUT Pervasive Computing

8 Assignment Changes the state of data L := R Type checking ensures that the memory location referenced by L has room for the value of expression R Indirect referencing e.g. through pointer dereference usually what we want makes compiler optimization harder 0x0804a865 0x0804a008 0x0804a ptr == 0x0804a008 *ptr == 2148 ptr TUT Pervasive Computing 8

9 Variations of assignments Multiple assignment e.g. Python function may return several values (e.g Clu) Compound operations e.g. C (+=, -=) Increment and decrement operations a, b = b, a Triple = proc ( ) returns ( int, int, int ) return ( 1, 2, 3 ) end Triple;... a, b, c: int := Triple ( ) a.b [ i + j ] = a.b [ i + j ] + 2; a.b [ i + j ] += 2; a [ i ++ ] *= 10; TUT Pervasive Computing 9

10 Expression language if ( x = y ) if ( x == y ) Statement has a value C: assignment has a value enables multiple assignments Algol68: begin a := if b < c then d else e; a := begin f ( b ); g ( c ) end; g ( d ); end a = b = 1 a = ( b = 1 ) while ( ( ch = getchar ( ) )!= EOF )... TUT Pervasive Computing 10

11 Expressions Expressions consist of operands e.g. variables, constants, function calls operators e.g. operator symbols, functions a f ( 1, 2 ) * 3 TUT Pervasive Computing 11

12 Operators (1) Different amount of operands: unary (signs, negation, C s ++ and &) binary (arithmetic operators, comparison operators, assignment, ->) ternary (in C) Different layout: a? b : c prefix (many unary operators, e.g. -1,!a, ++i) operators in Scheme postfix (e.g. i++) infix (many binary operators) TUT Pervasive Computing 12

13 Operators (2) Precedence described as precedence levels e.g. binary *-operator usually has a higher precedence (level) than binary +-operator Association applied to operators of the same precedence level operators associated from left to right: e.g. arithmetic operators, C s <<, -> operators associated from right to left: e.g. power raising, C s +=, = TUT Pervasive Computing 13

14 Operator precedences Fortran Pascal C Ada ** *, /, div, mod ++, -- **, abs *, / +, - (all) +, - (unary) *, /, mod, rem +, - (all) *, /, % +, - (unary) +, - (binary) +, - (binary) C-code: Obs! Parentheses are recommended s!= 1 << n + 1; A [ i ] = i = x; (Does not work) a = b << c = d; TUT Pervasive Computing 14

15 Expression evaluation (1) ( a + b ) * ( c d ) Evaluation can be based on an intermediate presentation syntax tree passed in post-order (left subtree, right subtree, root) postfix notation evaluation can be based on stack three-address-code common sub-expressions can be used in optimization memory space needed for temporary variables a b + c d - * + TUT Pervasive Computing 15 * - a b c d t1 = a + b t2 = c d t3 = t1 * t2

16 Expression evaluation (2) Precedence levels and associations do not determine the evaluation order of the whole syntax tree + 3 * ( y 1 ) + 2 * ( x + 3 ) * * Obs: side effects a = 10; b = a + fun ( a ); y 1 x 3 TUT Pervasive Computing 16

17 Expression evaluation (3) Evaluation of logic expressions can be based on Ashort- B short-circuit evaluation A and B Modula-2: IF ( i > 0 ) AND ( i < 11 ) AND ( a [ i ] = b ) THEN... C: if ( p && ( p->item == x ) )... Ada: short-circuit operators: andthen, orelse Example of lazy evaluation which means that expression is evaluated only when its value is needed e.g. passing an expression as a parameter does not require evaluation of the expression TUT Pervasive Computing 17

18 Bindings Binding relation or association e.g. between an object and property/feature e.g. between an operation and its symbol Binding time time, when a binding occurs Static and dynamic binding TUT Pervasive Computing 18

19 Example bindings Set of possible types for count bound at language design time Type of count bound at compile time Set of possible values of count bound at compiler design time Value of count C-code: int count;... count = count * 5; bound at execution time with this statement Set of possible meanings for the operator symbol * bound at language design time Meaning of the operator symbol * in this statement bound at compile time Internal representation of the literal 5 bound at compiler design time TUT Pervasive Computing 19

20 Binding of types Static (compile-time) / dynamic (run-time)? Objects only / objects + references? Can the type of an object change? Can an object have several types at the same time: inheritance (polymorphism) Explicit/implicit typing Type deduction TUT Pervasive Computing

21 Binding of variables and types Static binding before a variable can be referenced, it must be bound to a data type Choices for static binding: explicit declaration implicit declaration Fortran: identifier beginning with I, J, K, L, M, or N => INTEGER other letter as the first letter => REAL Perl beginning with$ => scalar (numeric value or string) beginning with@=> array beginning with%=> hash (associative array) TUT Pervasive Computing 21

22 Explicit declaration Basic rule: declare indentifiers before using them Exceptions for the rule: pointers, mutually recursive subprograms Pascal: type APtr = ^A; A = record next: APtr; data:... end; Ada: type A; type APtr is access A; type A is record next: APtr; data:... end record; TUT Pervasive Computing 22

23 Dynamic binding of types Variable is bound to a type when it is assigned a value at execution time e.g. JavaScript, Python Advantages: flexibility, genericity Disadvantages: JavaScript-code: list = [ 10.2, 3.5 ]... list = 47 missing support for error detection (= errors reported to users, not to programmers) implementation costs TUT Pervasive Computing 23

24 Type deduction (ML, Haskell,..) fun circumf ( r ) = 3.14 * r * r; fun square ( x ) = x * x; fun square ( x ) : int = x * x; suffix x = x ++.jpg square x = x * x auto iter = v.begin ( ) + 2; argument is float, result is float cannot be deduced a hint given by programmer argument is string, result is string deduced only when used C++ TUT Pervasive Computing 24

25 Lifetime Storage bindings (variable bound to memory) reservation of memory space for a variable (allocation) releasing the reserved memory space (deallocation) Variable lifetime time during which the variable is bound to a specific memory location binding between data item (variable declaration) and memory location occurs at execution time (usually) except for persistent variables stored in a database TUT Pervasive Computing 25

26 Variable classification according to lifetime Static variables bound to memory location before program execution binding is preserved through the whole execution Stack-dynamic variables bound to memory location during elaboration of their declaration type is bound statically Explicit heap-dynamic variables bound to memory location according to programmer s instructions variables are referenced via pointers (no name) type is bound statically Implicit heap-dynamic variables bound to memory location when values are assigned global variables static (in C) local variables pointer variables variables in script languages TUT Pervasive Computing 26

27 Garbage collection 1. Separate alive objects from those not in use any more 2. Collect objects not in use Memory management memory allocation memory deallocation can be done automatically, when an object can no longer be reached from the program Triggering garbage collection immediately when garbage may be created size of reserved blocks has grown over some limit a given time limit is reached the system has nothing else to do TUT Pervasive Computing 27

28 Garbage collection methods Reference counts keep track of the number of pointers that refer to the same memory location Mark and sweep before collection all memory allocations are marked as not seen referenced allocation blocks are marked as seen sweep phase sweeps away all allocations that are not seen Stop and copy memory space is split into two parts, and only one of them is used for new object allocations in garbage collection, reachable objects are copied from the allocation space (from-space) to the other, initially empty space (to-space) finally the roles of these two spaces are switched TUT Pervasive Computing 28

29 Pointer problems Lost heap-dynamic variable (garbage) memory is allocated for a dynamic variable via a pointer memory is re-allocated via the same pointer Dangling pointer or dangling reference memory is allocated for a dynamic variable via a pointer the value of the pointer is assigned to another pointer the space is deallocated via one of the above pointers the other pointer references now to the deallocated space New ( p );... New ( p ); Pascalcodes New ( p1 ); p2 = p1; Dispose ( p1 ); TUT Pervasive Computing 29

30 Example pointer problem C-code: char *init_line ( ) { char *line = new char [ 60 ];... return line; } Who (which program structure) owns the pointer? TUT Pervasive Computing 30

31 Solution for dangling pointers: tombstones Each heap-dynamic variable include a special cell (tombstone) that is itself a pointer to a heapdynamic variable Actual pointer variables point only to tombstones When a heap-dynamic variable is deallocated, the tombstone remains but is set to nil delete p; p = nil; if ( p == nil )... new ( ptr1 ); ptr2 := ptr1; free ( ptr1 ); RIP TUT Pervasive Computing 31

32 Solution for dangling pointers: locks and keys Pointer values are associated with an integer (key) Heap-dynamic variables are associated with an integer (lock) In space allocation, the same value is given for both key and lock Upon referencing, the equality of the lock and key is checked Upon deallocation, the value is set invalid new ( ptr1 ); ptr2 := ptr1; free ( ptr1 ); TUT Pervasive Computing 32 0

33 Scope Solves which identifier (where declared) is meant in a reference (usage) Binding between the use of data element and its definition (declaration) Creates a visibility region range of statements in which the variable is visible a variable is visible in statement if it can be referenced in that statement scopes can be nested Static and dynamic scope TUT Pervasive Computing 33

34 Moving between scopes Each subprogram has an own scope Moving to a new scope (e.g. calling a subprogram) elaboration of declarations creating bindings to the local variables of the scope hiding binding of non-local variables of the same name Moving back to the previous scope (e.g. returning from a subprogram) restoring bindings as they were earlier TUT Pervasive Computing 34

35 Scope example Pascal-code: In inner scope, bindings to those outer variables that have same names as inner variables, are not preserved program P; var x, y: Real; procedure P1; var y, z: Integer; begin... y := 2; x := 2.2;... end; begin... x := 1.1; y := 3.3;... end. TUT Pervasive Computing 35

36 Static scoping Bindings (between variable declarations and variable usages) are created at compile time can be detected in the program text Choices for static binding: single global scope Basic both global and local variables Fortran nested subprograms Algol60, Pascal, Ada nested blocks C, Ada Modules and classes determine scopes TUT Pervasive Computing 36

37 Dynamic scoping Bindings depend on control flow and the order of subprogram calls e.g. APL, Snobol, early dialects of Lisp, Perl Rule: latest binding that is created during execution holds Pseudo code: a: integer procedure first a := 1 procedure second a: integer first ( ) a := 2 if read_integer ( ) > 0 second ( ) else first ( ) write_integer ( a ) global declaration local declaration main program TUT Pervasive Computing 37

38 Lifetime and scope Variable lifetime and (static) scope can be closely related e.g. Pascal, nested subprograms Lifetime and scope may not be related e.g. static variables in C e.g. subprogram calls from another subprogram C-code: void printheader ( ) {... } void compute ( ) { int sum;... printheader ( ); } TUT Pervasive Computing 38

39 Lambdas and closures Lambda = lambda expression exists in source code (compile-time feature) definition Closure = lambda s run-time counterpart definition + environment = instantiation environment binds each free variable in lambda expression to a value free variables become closed -> closure cf. class instance of a class = object TUT Pervasive Computing 39

40 Lambda example in C++11 #include <iostream> using namespace std; int main ( ) { auto func = [ ] ( int x, int y ) { return x + y; }; cout << func ( 2, 3 ) << endl; } => 5 TUT Pervasive Computing

41 Lambda example in C++11 #include <iostream> using namespace std; int main ( ) { int n = [ ] ( int x, int y ) { return x + y; } ( 5, 4 ); cout << n << endl; } => 9 TUT Pervasive Computing

42 Captures in C++11 Capture clause = lambda introducer Specify which outside (free) variables are available for the lambda function and how to capture them by value or by reference In other words: how to bind free variables (variables referenced in the body of a lambda) TUT Pervasive Computing

43 Capture choices in C++11 [ ] captures nothing [ = ] captures all outside variables by value [ & ] captures all outside variables by reference [ a, &b ] captures a by value and b by reference [ this ] captures this pointer by value TUT Pervasive Computing

44 Lambda example in C++11 #include <iostream> using namespace std; int main ( ) { int x = 3; int y = 5; auto func = [ x, &y ] { return x + y; }; x = 22; y = 44; cout << func ( ) << endl; } => 47 TUT Pervasive Computing

45 Lambda and STL (for_each) vector<int> v; v.push_back ( 1 ); v.push_back ( 2 ); // for ( auto itr = v.begin ( ), end = v.end ( ); itr!= end; itr++ ) { cout << *itr; } vector<int> v; v.push_back ( 1 ); v.push_back ( 2 ); // for_each ( v.begin ( ), v.end ( ), [ ] ( int val ) { cout << val; } ); TUT Pervasive Computing

Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named

More information

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

Organization of Programming Languages CS320/520N. Lecture 05. Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio. Organization of Programming Languages CS320/520N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Names, Bindings, and Scopes A name is a symbolic identifier used

More information

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage

More information

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

Static vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer Lecture 10: Static Semantics Overview 1 Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces trees Detects & eliminates ill-formed parse trees Static semantic analysis

More information

DATA STRUCTURES USING C

DATA STRUCTURES USING C DATA STRUCTURES USING C QUESTION BANK UNIT I 1. Define data. 2. Define Entity. 3. Define information. 4. Define Array. 5. Define data structure. 6. Give any two applications of data structures. 7. Give

More information

The C Programming Language course syllabus associate level

The C Programming Language course syllabus associate level TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

More information

CSCI 3136 Principles of Programming Languages

CSCI 3136 Principles of Programming Languages CSCI 3136 Principles of Programming Languages Faculty of Computer Science Dalhousie University Winter 2013 CSCI 3136 Principles of Programming Languages Faculty of Computer Science Dalhousie University

More information

Chapter 15 Functional Programming Languages

Chapter 15 Functional Programming Languages Chapter 15 Functional Programming Languages Introduction - The design of the imperative languages is based directly on the von Neumann architecture Efficiency (at least at first) is the primary concern,

More information

Lecture 1: Introduction

Lecture 1: Introduction Programming Languages Lecture 1: Introduction Benjamin J. Keller Department of Computer Science, Virginia Tech Programming Languages Lecture 1 Introduction 2 Lecture Outline Preview History of Programming

More information

Glossary of Object Oriented Terms

Glossary of Object Oriented Terms Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction

More information

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

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6) Semantic Analysis Scoping (Readings 7.1,7.4,7.6) Static Dynamic Parameter passing methods (7.5) Building symbol tables (7.6) How to use them to find multiply-declared and undeclared variables Type checking

More information

Semester Review. CSC 301, Fall 2015

Semester Review. CSC 301, Fall 2015 Semester Review CSC 301, Fall 2015 Programming Language Classes There are many different programming language classes, but four classes or paradigms stand out:! Imperative Languages! assignment and iteration!

More information

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

COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms. COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms 1 Activation Records activation declaration location Recall that an activation

More information

CSC 272 - Software II: Principles of Programming Languages

CSC 272 - Software II: Principles of Programming Languages CSC 272 - Software II: Principles of Programming Languages Lecture 1 - An Introduction What is a Programming Language? A programming language is a notational system for describing computation in machine-readable

More information

Parameter passing in LISP

Parameter passing in LISP Parameter passing in LISP The actual parameters in a function call are always expressions, represented as lists structures. LISP provides two main methods of parameter passing: Pass/Call-by-value. The

More information

An Incomplete C++ Primer. University of Wyoming MA 5310

An Incomplete C++ Primer. University of Wyoming MA 5310 An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages

More information

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

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser) 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

More information

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

KITES TECHNOLOGY COURSE MODULE (C, C++, DS) KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

More information

Chapter 1. Dr. Chris Irwin Davis Email: cid021000@utdallas.edu Phone: (972) 883-3574 Office: ECSS 4.705. CS-4337 Organization of Programming Languages

Chapter 1. Dr. Chris Irwin Davis Email: cid021000@utdallas.edu Phone: (972) 883-3574 Office: ECSS 4.705. CS-4337 Organization of Programming Languages Chapter 1 CS-4337 Organization of Programming Languages Dr. Chris Irwin Davis Email: cid021000@utdallas.edu Phone: (972) 883-3574 Office: ECSS 4.705 Chapter 1 Topics Reasons for Studying Concepts of Programming

More information

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

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures Part 2: Data Structures PD Dr. rer. nat. habil. Ralf-Peter Mundani Computation in Engineering (CiE) Summer Term 2016 Overview general linked lists stacks queues trees 2 2

More information

Object Oriented Software Design II

Object Oriented Software Design II Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

More information

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

Language Evaluation Criteria. Evaluation Criteria: Readability. Evaluation Criteria: Writability. ICOM 4036 Programming Languages ICOM 4036 Programming Languages Preliminaries Dr. Amirhossein Chinaei Dept. of Electrical & Computer Engineering UPRM Spring 2010 Language Evaluation Criteria Readability: the ease with which programs

More information

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages Course Organization Introduction CSE 307: Principles of Programming Languages Spring 2015 R. Sekar Course Organization Introduction 1 / 34 Topics 1. Course Organization Info and Support Course Description

More information

Lecture 9. Semantic Analysis Scoping and Symbol Table

Lecture 9. Semantic Analysis Scoping and Symbol Table Lecture 9. Semantic Analysis Scoping and Symbol Table Wei Le 2015.10 Outline Semantic analysis Scoping The Role of Symbol Table Implementing a Symbol Table Semantic Analysis Parser builds abstract syntax

More information

Functional Programming. Functional Programming Languages. Chapter 14. Introduction

Functional Programming. Functional Programming Languages. Chapter 14. Introduction Functional Programming Languages Chapter 14 Introduction Functional programming paradigm History Features and concepts Examples: Lisp ML 1 2 Functional Programming Functional Programming Languages The

More information

1.1 WHAT IS A PROGRAMMING LANGUAGE?

1.1 WHAT IS A PROGRAMMING LANGUAGE? 1 INTRODUCTION 1.1 What is a Programming Language? 1.2 Abstractions in Programming Languages 1.3 Computational Paradigms 1.4 Language Definition 1.5 Language Translation 1.6 Language Design How we communicate

More information

Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

More information

Semantic Analysis: Types and Type Checking

Semantic Analysis: Types and Type Checking Semantic Analysis Semantic Analysis: Types and Type Checking CS 471 October 10, 2007 Source code Lexical Analysis tokens Syntactic Analysis AST Semantic Analysis AST Intermediate Code Gen lexical errors

More information

1/20/2016 INTRODUCTION

1/20/2016 INTRODUCTION INTRODUCTION 1 Programming languages have common concepts that are seen in all languages This course will discuss and illustrate these common concepts: Syntax Names Types Semantics Memory Management We

More information

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement? 1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members

More information

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C Tutorial#1 Q 1:- Explain the terms data, elementary item, entity, primary key, domain, attribute and information? Also give examples in support of your answer? Q 2:- What is a Data Type? Differentiate

More information

Lecture 18-19 Data Types and Types of a Language

Lecture 18-19 Data Types and Types of a Language Lecture 18-19 Data Types and Types of a Language April 29, 2014 Data Types and Types of a Language Data, Data Types and Types Type: Generalities Type Systems and Type Safety Type Equivalence, Coercion

More information

C++FA 5.1 PRACTICE MID-TERM EXAM

C++FA 5.1 PRACTICE MID-TERM EXAM C++FA 5.1 PRACTICE MID-TERM EXAM This practicemid-term exam covers sections C++FA 1.1 through C++FA 1.4 of C++ with Financial Applications by Ben Van Vliet, available at www.benvanvliet.net. 1.) A pointer

More information

Programming Language Pragmatics

Programming Language Pragmatics Programming Language Pragmatics THIRD EDITION Michael L. Scott Department of Computer Science University of Rochester ^ШШШШШ AMSTERDAM BOSTON HEIDELBERG LONDON, '-*i» ЩЛ< ^ ' m H NEW YORK «OXFORD «PARIS»SAN

More information

Programming Languages

Programming Languages Programming Languages Qing Yi Course web site: www.cs.utsa.edu/~qingyi/cs3723 cs3723 1 A little about myself Qing Yi Ph.D. Rice University, USA. Assistant Professor, Department of Computer Science Office:

More information

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

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London

More information

Chapter 7: Functional Programming Languages

Chapter 7: Functional Programming Languages Chapter 7: Functional Programming Languages Aarne Ranta Slides for the book Implementing Programming Languages. An Introduction to Compilers and Interpreters, College Publications, 2012. Fun: a language

More information

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

More information

Functional Programming

Functional Programming FP 2005 1.1 3 Functional Programming WOLFRAM KAHL kahl@mcmaster.ca Department of Computing and Software McMaster University FP 2005 1.2 4 What Kinds of Programming Languages are There? Imperative telling

More information

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The

More information

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

Parameter Passing. Parameter Passing. Parameter Passing Modes in Fortran. Parameter Passing Modes in C Parameter Passing In this set of notes you will learn about: Parameter passing modes Call by Call by reference Call by sharing Call by result Call by /result Call by name Subroutine closures as parameters

More information

CSE 130 Programming Language Principles & Paradigms

CSE 130 Programming Language Principles & Paradigms CSE 130 Programming Language Principles & Paradigms Thomas A. Powell tpowell@pint.com Housekeeping Syllabus review Direct class page link http://www.pint.com/classes/cse130 Updated syllabus, notes, homework

More information

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is preceded by an equal sign d. its name has undereline 2. Associations

More information

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

Programming Language Features (cont.) CMSC 330: Organization of Programming Languages. Parameter Passing in OCaml. Call-by-Value CMSC 33: Organization of Programming Languages Programming Language Features (cont.) Names & binding Namespaces Static (lexical) scopes Dynamic scopes Polymorphism Parametric Subtype Ad-hoc Parameter Passing

More information

CHAPTER 4 ESSENTIAL DATA STRUCTRURES

CHAPTER 4 ESSENTIAL DATA STRUCTRURES CHAPTER 4 ESSENTIAL DATA STRUCTURES 72 CHAPTER 4 ESSENTIAL DATA STRUCTRURES In every algorithm, there is a need to store data. Ranging from storing a single value in a single variable, to more complex

More information

Compiler Construction

Compiler Construction Compiler Construction Lecture 1 - An Overview 2003 Robert M. Siegfried All rights reserved A few basic definitions Translate - v, a.to turn into one s own language or another. b. to transform or turn from

More information

Chapter 2: Elements of Java

Chapter 2: Elements of Java Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction

More information

Java (12 Weeks) Introduction to Java Programming Language

Java (12 Weeks) Introduction to Java Programming Language Java (12 Weeks) Topic Lecture No. Introduction to Java Programming Language 1 An Introduction to Java o Java as a Programming Platform, The Java "White Paper" Buzzwords, Java and the Internet, A Short

More information

Symbol Tables. Introduction

Symbol Tables. Introduction Symbol Tables Introduction A compiler needs to collect and use information about the names appearing in the source program. This information is entered into a data structure called a symbol table. The

More information

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

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz 2007 03 16 Advanced compiler construction Michel Schinz 2007 03 16 General course information Teacher & assistant Course goals Teacher: Michel Schinz Michel.Schinz@epfl.ch Assistant: Iulian Dragos INR 321, 368 64

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

PL/SQL Overview. Basic Structure and Syntax of PL/SQL

PL/SQL Overview. Basic Structure and Syntax of PL/SQL PL/SQL Overview PL/SQL is Procedural Language extension to SQL. It is loosely based on Ada (a variant of Pascal developed for the US Dept of Defense). PL/SQL was first released in ١٩٩٢ as an optional extension

More information

Comp151. Definitions & Declarations

Comp151. Definitions & Declarations Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const

More information

Programming Languages in Artificial Intelligence

Programming Languages in Artificial Intelligence Programming Languages in Artificial Intelligence Günter Neumann, German Research Center for Artificial Intelligence (LT Lab, DFKI) I. AI programming languages II. Functional programming III. Functional

More information

Chapter 13 Storage classes

Chapter 13 Storage classes Chapter 13 Storage classes 1. Storage classes 2. Storage Class auto 3. Storage Class extern 4. Storage Class static 5. Storage Class register 6. Global and Local Variables 7. Nested Blocks with the Same

More information

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

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority) Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language Simple C++ Programs Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input and Output Basic Functions from

More information

Jonathan Worthington Scarborough Linux User Group

Jonathan Worthington Scarborough Linux User Group Jonathan Worthington Scarborough Linux User Group Introduction What does a Virtual Machine do? Hides away the details of the hardware platform and operating system. Defines a common set of instructions.

More information

Java Application Developer Certificate Program Competencies

Java Application Developer Certificate Program Competencies Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle

More information

I PUC - Computer Science. Practical s Syllabus. Contents

I PUC - Computer Science. Practical s Syllabus. Contents I PUC - Computer Science Practical s Syllabus Contents Topics 1 Overview Of a Computer 1.1 Introduction 1.2 Functional Components of a computer (Working of each unit) 1.3 Evolution Of Computers 1.4 Generations

More information

The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2).

The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2). CHAPTER 5 The Tree Data Model There are many situations in which information has a hierarchical or nested structure like that found in family trees or organization charts. The abstraction that models hierarchical

More information

Stack Allocation. Run-Time Data Structures. Static Structures

Stack Allocation. Run-Time Data Structures. Static Structures Run-Time Data Structures Stack Allocation Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers,

More information

7.1 Our Current Model

7.1 Our Current Model Chapter 7 The Stack In this chapter we examine what is arguably the most important abstract data type in computer science, the stack. We will see that the stack ADT and its implementation are very simple.

More information

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

Compilers. Introduction to Compilers. Lecture 1. Spring term. Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam. Compilers Spring term Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam.es Lecture 1 to Compilers 1 Topic 1: What is a Compiler? 3 What is a Compiler? A compiler is a computer

More information

Announcements FORTRAN ALGOL COBOL. Simula & Smalltalk. Programming Languages

Announcements FORTRAN ALGOL COBOL. Simula & Smalltalk. Programming Languages Announcements Programming Languages! Monday evening GBA section has been shut down " If you were assigned to this section, please find a different section " If you cannot attend a different section, please

More information

Computer Programming I

Computer Programming I Computer Programming I COP 2210 Syllabus Spring Semester 2012 Instructor: Greg Shaw Office: ECS 313 (Engineering and Computer Science Bldg) Office Hours: Tuesday: 2:50 4:50, 7:45 8:30 Thursday: 2:50 4:50,

More information

Class 16: Function Parameters and Polymorphism

Class 16: Function Parameters and Polymorphism Class 16: Function Parameters and Polymorphism SI 413 - Programming Languages and Implementation Dr. Daniel S. Roche United States Naval Academy Fall 2011 Roche (USNA) SI413 - Class 16 Fall 2011 1 / 15

More information

Database Programming with PL/SQL: Learning Objectives

Database Programming with PL/SQL: Learning Objectives Database Programming with PL/SQL: Learning Objectives This course covers PL/SQL, a procedural language extension to SQL. Through an innovative project-based approach, students learn procedural logic constructs

More information

Parameter Passing. Standard mechanisms. Call by value-result Call by name, result

Parameter Passing. Standard mechanisms. Call by value-result Call by name, result Parameter Passing Standard mechanisms Call by value Call by reference Other methods Call by value-result Call by name, result Terms Function definition where the details of the function are presented (type,

More information

1 The Java Virtual Machine

1 The Java Virtual Machine 1 The Java Virtual Machine About the Spec Format This document describes the Java virtual machine and the instruction set. In this introduction, each component of the machine is briefly described. This

More information

Memory Allocation. Static Allocation. Dynamic Allocation. Memory Management. Dynamic Allocation. Dynamic Storage Allocation

Memory Allocation. Static Allocation. Dynamic Allocation. Memory Management. Dynamic Allocation. Dynamic Storage Allocation Dynamic Storage Allocation CS 44 Operating Systems Fall 5 Presented By Vibha Prasad Memory Allocation Static Allocation (fixed in size) Sometimes we create data structures that are fixed and don t need

More information

What is a programming language?

What is a programming language? Overview Introduction Motivation Why study programming languages? Some key concepts What is a programming language? Artificial language" Computers" Programs" Syntax" Semantics" What is a programming language?...there

More information

[Refer Slide Time: 05:10]

[Refer Slide Time: 05:10] Principles of Programming Languages Prof: S. Arun Kumar Department of Computer Science and Engineering Indian Institute of Technology Delhi Lecture no 7 Lecture Title: Syntactic Classes Welcome to lecture

More information

Course Title: Software Development

Course Title: Software Development Course Title: Software Development Unit: Customer Service Content Standard(s) and Depth of 1. Analyze customer software needs and system requirements to design an information technology-based project plan.

More information

Top 72 Perl Interview Questions and Answers

Top 72 Perl Interview Questions and Answers Top 72 Perl Interview Questions and Answers 1. Difference between the variables in which chomp function work? Scalar: It is denoted by $ symbol. Variable can be a number or a string. Array: Denoted by

More information

Principles of Programming Languages Topic: Introduction Professor Louis Steinberg

Principles of Programming Languages Topic: Introduction Professor Louis Steinberg Principles of Programming Languages Topic: Introduction Professor Louis Steinberg CS 314, LS,LTM: L1: Introduction 1 Contacts Prof. Louis Steinberg lou @ cs.rutgers.edu x5-3581 401 Hill TA: to be announced

More information

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

The previous chapter provided a definition of the semantics of a programming Chapter 7 TRANSLATIONAL SEMANTICS The previous chapter provided a definition of the semantics of a programming language in terms of the programming language itself. The primary example was based on a Lisp

More information

UNIT-I Preliminaries

UNIT-I Preliminaries Autonomous UNIT-I Preliminaries Topics 1. Reasons for Studying Concepts of Programming Languages 2. Programming Domains 3. Language Evaluation Criteria 4. Influences on Language Design 5. Language Categories

More information

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

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

Programming Language Theory

Programming Language Theory Programming Language Theory Takashi Hattori January 14, 2016 1 Introduction 1.1 Some questions What is a programming language? Why do we have so many programming languages? Why do you study the theory

More information

C Compiler Targeting the Java Virtual Machine

C Compiler Targeting the Java Virtual Machine C Compiler Targeting the Java Virtual Machine Jack Pien Senior Honors Thesis (Advisor: Javed A. Aslam) Dartmouth College Computer Science Technical Report PCS-TR98-334 May 30, 1998 Abstract One of the

More information

1 Classical Universal Computer 3

1 Classical Universal Computer 3 Chapter 6: Machine Language and Assembler Christian Jacob 1 Classical Universal Computer 3 1.1 Von Neumann Architecture 3 1.2 CPU and RAM 5 1.3 Arithmetic Logical Unit (ALU) 6 1.4 Arithmetic Logical Unit

More information

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

n Introduction n Art of programming language design n Programming language spectrum n Why study programming languages? n Overview of compilation Lecture Outline Programming Languages CSCI-4430 & CSCI-6430, Spring 2016 www.cs.rpi.edu/~milanova/csci4430/ Ana Milanova Lally Hall 314, 518 276-6887 milanova@cs.rpi.edu Office hours: Wednesdays Noon-2pm

More information

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example Operator Overloading Lecture 8 Operator Overloading C++ feature that allows implementer-defined classes to specify class-specific function for operators Benefits allows classes to provide natural semantics

More information

General Introduction

General Introduction Managed Runtime Technology: General Introduction Xiao-Feng Li (xiaofeng.li@gmail.com) 2012-10-10 Agenda Virtual machines Managed runtime systems EE and MM (JIT and GC) Summary 10/10/2012 Managed Runtime

More information

Programming Language Rankings. Lecture 15: Type Inference, polymorphism & Type Classes. Top Combined. Tiobe Index. CSC 131! Fall, 2014!

Programming Language Rankings. Lecture 15: Type Inference, polymorphism & Type Classes. Top Combined. Tiobe Index. CSC 131! Fall, 2014! Programming Language Rankings Lecture 15: Type Inference, polymorphism & Type Classes CSC 131 Fall, 2014 Kim Bruce Top Combined Tiobe Index 1. JavaScript (+1) 2. Java (-1) 3. PHP 4. C# (+2) 5. Python (-1)

More information

C++FA 3.1 OPTIMIZING C++

C++FA 3.1 OPTIMIZING C++ C++FA 3.1 OPTIMIZING C++ Ben Van Vliet Measuring Performance Performance can be measured and judged in different ways execution time, memory usage, error count, ease of use and trade offs usually have

More information

C++ Language Tutorial

C++ Language Tutorial cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain

More information

PES Institute of Technology-BSC QUESTION BANK

PES Institute of Technology-BSC QUESTION BANK PES Institute of Technology-BSC Faculty: Mrs. R.Bharathi CS35: Data Structures Using C QUESTION BANK UNIT I -BASIC CONCEPTS 1. What is an ADT? Briefly explain the categories that classify the functions

More information

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

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists Lecture 11 Doubly Linked Lists & Array of Linked Lists In this lecture Doubly linked lists Array of Linked Lists Creating an Array of Linked Lists Representing a Sparse Matrix Defining a Node for a Sparse

More information

OAMulator. Online One Address Machine emulator and OAMPL compiler. http://myspiders.biz.uiowa.edu/~fil/oam/

OAMulator. Online One Address Machine emulator and OAMPL compiler. http://myspiders.biz.uiowa.edu/~fil/oam/ OAMulator Online One Address Machine emulator and OAMPL compiler http://myspiders.biz.uiowa.edu/~fil/oam/ OAMulator educational goals OAM emulator concepts Von Neumann architecture Registers, ALU, controller

More information

Programming and Software Development CTAG Alignments

Programming and Software Development CTAG Alignments Programming and Software Development CTAG Alignments This document contains information about four Career-Technical Articulation Numbers (CTANs) for Programming and Software Development Career-Technical

More information

Statements and Control Flow

Statements and Control Flow Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10. Introduction to

More information