The Design of Core C++ (Notes)

Size: px
Start display at page:

Download "The Design of Core C++ (Notes)"

Transcription

1 The Design of Core C++ (Notes) Uday Reddy May 13, 1994 This note is to define a small formal language called Core C++ which reflects the essential structure of C++. As the name implies, the design only captures the core language, not the bells and whistles. Moreover, Core C++ deviates from the real C++ in certain ways in order to streamline the design as well as to disambiguate the semantics. Some of these deviations are only formal in that they are useful for describing the semantics, but they may not be reflected concretely in the real language. 1 Type Structure of C The type structure of C seems to be a three-layered system: Data types are types of values that can be stored in variables (denoted by schematic variable δ), Storage types are types of storage objects (denoted by schematic variable S), and Types in general (denoted by schematic variable T). Data types only appear as parts of other types. On the other hand, storage types and general types occur in declarations. Typically, the former occur in storage declarations and the latter in parameter declarations. Data types The data types are defined by δ ::= int T void int is representative of the plethora of data types found in C (short, float etc.). T stands for pointers to T-typed values. Note that the destination of a pointer can be of any type, not only a data type. Finally, void is a paradoxical type of no value. Storage types A good sample of storage types is given by S ::= δ var S[ ] struct {S 1 x 1 ;...S n x n ; The storage type δ var stands for δ-typed variables, but var is usually not written, i.e., δ var as a storage type is simply written δ. (More on this below.) 1

2 The storage type S[ ] stands for arrays of S-typed storage. (This type has no relation to pointers.) struct {S 1 x 1 ;...S n x n ; stands for structures with components x 1,...,x n of storage types S 1,...,S n respectively. Types General types are given by the syntax T ::= δ val S S const δ(t 1,...,T n ) δ val is the type of values of type δ. The suffix val is for disambiguation. It is never written in concrete C. Every storage type S is a type. S suffixed with const is the type of constant structures of type S. This is a promise by the programmer to never assign to any component of the storage structure. δ(t 1,...,T n ) stands for functions that take arguments of types T 1,...,T n (for n 0) and return results of type δ val. It is significant that the arguments can be of any type, but the result can only be a data value. We are keeping with the C philosophy of being a low-level language [1, pp. 1-2]. In practice, this is not a serious limitation because T is a data type for any type T. One might wonder if functions can return arbitrary typed results (instead of only data values). In general, this would involve heap storage with garbage collection. In my opinion, this would be a radical extension of C. Remarks 1. An important idea in the above treatment is that variables are primitive storage objects and other storage structures are built from them. For example, the storage declaration int a[10]; declares a to be an array consisting of 10 integer variables, not an array variable with an array value of 10 integers. The same remark applies to structs. Storage structures of this kind cannot be passed by value basically because there is no such thing as the value of an array or a struct. Warning: Real C does not agree with this view for structs, though it agrees for arrays. 2. A function taking a parmeter of a storage type takes the entire storage structure. In other words, it corresponds to call by reference. 1 Parameters of type δ val, however, are passed by value. 3. This three-layered type system is in contrast to the two-layered system of data and phrase types advocated by Reynolds for Algol-like languages [2]. The reason for the additional layer of storage types is that values of these types have automatic storage creation mechanisms. This is not the case for functions. 1 This is not strictly C, but C++. In C, function types are of the form δ(δ 1,..., δ n), i.e., arguments can only be data values. 2

3 4. Note that general types occur in only two places: (i) as parameter types of functions and (ii) as destination types of pointers. 5. The convention of abbreviating both δ var and δ val as simply δ leads, not surprisingly, to an ambiguity. All real-life versions of C use the following convention: in a function-parameter position, δ means δ val and, in a pointer destination position, δ means δ var. (Note that these are the only two places where general types are used.) In Standard C, the effect of δ var parameters is obtained by address-and-pointer mechanism. In C++, however, a notion of references is introduced to circumvent the ambiguity (and then arbitrarily generalized). The effect of δ val is obtained by δ const (which is really δ var const a rather circumlocutary expression!) Type compatibility Type compatibility for struct types is by name and, for others, it is by structure. By name means that struct types are given names by unique type definitions of the form struct t {S 1 x 1 ;...S n x n ; Then, two struct types are considered equal if only if they have the same name. Type compatibility is not strictly equality. It is governed by a subtype relation. Primitive data types have a standard subtype relation, e.g., int <: float. For pointer types, we have T <: T iff T <: T. Storage types have trivial subtype relation, i.e., a storage type is only a subtype of itself. For general types, we have a subtype relation given by the following rules: 2 Enhancements of C++ C++ extends structs as follows: δ <: δ δ val <: δ val S <: S const δ <: δ T 1 <: T 1... T n <: T n δ(t 1,...,T n ) <: δ (T 1,...,T n) S ::=... struct : t {T 1 x 1 ;...T n x n ; This notation extends C structs in two ways. First, the struct-type is declared as a subtype of another struct-type t. Therefore, one has a subtype relation: struct : t {T 1 x 1 ;...;T n x n ; <: t Second, the members of the struct are allowed to be of any type (including function types). The functions in a struct are called member functions or methods. They are deemed to have an implicit parameter t this where t is the name of the struct type. As usual, structs are always introduced via definitions. Such definitions are expected to give bindings for all the non-storage members (values, constants and function members). For example, a counter class is defined as 3

4 struct counter { int x = 0; int inc() { return (++ this->x); An equivalent definition is struct counter { int x = 0; let int inc() = counter inc int counter inc(counter *this) { return (++ this->x); 3 Declarations There are two kinds of declarations: binding declarations (also called definitions) declare an identifier and bind it to a specific value; type declarations simply declare the type of an identifier. There are no declarations for δ val type. (It would be ambiguous as noted above.) For the other three kinds of types, the two declarations have the syntax S x = P; extern S x; S const x = P; extern S const x; δ f(t 1 x 1,...,T n x n ) {C δ f(t 1,...,T n ); The declaration S x = P means create a storage object of type S with name x and initialize it with the value denoted by P. This kind of a definition is a statement as well as a binding. It is a statement in that it must be executed to create storage. It is a binding in that it binds the name x to the newly created storage. The scope of the name is the remainder of the program text delimited only by braces. For example, in {...;S x = P;...; the scope of x is the text following the declaration. If there are no braces delimiting the scope, the scope would consist of the entire following text. In contrast, a function declaration is not a statement. It can only appear at the top level. Generic let binding In addition to these, we introduce a generic binding mechanism of the form let T x = P. This is illustrated by the following examples: let int val small = 255; /* integer constant */ let int var a = p.x; /* alias to p.x */ let int sqr(int) = {(int x) return x*x; /* function by a block expression */ let type matrix = float[][] /* type definition */ Member declarations In a struct definition, the declarations of member fields have the status of a binding declaration. So, they can have initializers, function definitions and let bindings. In addition, the definition of a derived struct (in C++) can redefine the members of the parent. 4

5 4 Module system Even though C++ does not have a module system, we define one because it solves many problems which are otherwise treated in an arbitrary fashion in C++. Specifically, we want a module system with the following objectives: integrate header files into the language, provide representation hiding for types as well as for classes, provide parametric polymorphism. Our module system is a direct take off from that of Standard ML. A module is a named collection of binding declarations. This is similar to a struct definition except that it may also have type definitions. Modules in turn have large types that are called signatures. Examples A signature for items in a binary search tree may be defined as follows: signature CMP { type T; bool operator==(t, T); bool operator<(t, T); Then a specific module of this signature might be: CMP module StringCmp { let type T = char[]; bool operator==(t s, T t){ return (strcmp(s,t) == 0); bool operator<(t s, T t){ return (strcmp(s,t) < 0); A simpler module for searching in a linked list can be defined as follows: signature EQ { type T; bool operator==(t, T); let EQ module StringEq = StringCmp; The signature of a searching module can be defined thus: signature TABLE { type item; struct tableops { bool member(item); void insert(item); struct table <: tableops; The structtable has been declared to be some unknown subtype oftableops. Here are two sample searching modules: 5

6 TABLE module SlowTable(EQ module Elem) { let type item = Elem.T; import List(Elem); /* imports list, member, cons etc. */ struct table: tableops { list elems; bool member(item x) {return member(x, this->elems); void insert(item x) {this->elems = cons(x, this->elems); TABLE module SearchTree(CMP module Elem) { let type item = Elem.T; struct table: tableops { item root; table *left, *right; bool member(item x) {... void insert(item x) {... Notice that the data members of the table struct have been made private by declaring the module to have signature TABLE. Moreover, we achieve polymorphism by module parameterization. Thus, the use of parameterized modules is a powerful mechanism that solves several problems at once. Signatures A signature named Σ is defined in the following fashion: signature Σ {D 1 ;...D n ; where each D i is a declaration. It may be one of the following: extern T x type t struct t <: t type t = T struct t {S 1 x 1 ;... Σ module M include Σ type declaration of a name declaration of an opaque type declaration of an opaque subtype definition of a type definition of a struct type declaration of a module inclusion of another signature Type compatibility for signatures is by structure, not by name. For example, CMP <: EQ above. Modules The definition of a module has the syntax: Σ module M{B 1 ;...;B n ; where each B i is a binding declaration. In addition to the binding declarations already mentioned, modules provide a new one: import M Its effect is to include in the current context all the bindings of the module M as constrained by its signature. 6

7 5 Phrases Phrases are terms that one writes in the language. These are not to be confused with expressions (arithmetic or other) which yield data values. A phrase always has a phrase type. Phrase types include all types T mentioned in Sec. 1 and, in addition, two special types: S init for initializers of S-typed storage objects, and δ stmt for statements which might return δ-typed values. The phrase type stmt is used for statements which do not return. They may be deemed to be δ stmts for any δ. These types are special in that they are only used for describing terms. They are not included in regular types. So, there are no parameters, identifiers or member fields of these special types. A phrase often has free identifiers each of which is of a specific type. Let x 1 : T 1,...,x n : T n be a list of such distinct identifiers (with order assumed insignificant). To say that P is a phrase of phrase type τ in such a context, we write x 1 : T 1,...,x n : T n P : τ Greek letters Γ,,...are used to stand for lists of free identifiers. We write Γ[x : T] to mean the context Γ with the entry for x (if any) replaced by x : T. 5.1 General phrases An identifier of type T is always a phrase of type T: Γ x : T The type of a phrase is convertible by subtyping: 5.2 Expressions if x : T is in Γ Γ P : T Γ P : T if T <: T A phrase of type δ val is called an expression. Note that expressions can only denote data values. int Examples: Γ 0 : int val Γ E 1 : int val Γ E 2 : int val Γ E 1 + E 2 : int val pointers A pointer is created by new and used by the dereferencing operator: Γ NULL : T val Γ P : T init Γ new T P : T val Γ E : T val Γ E : T Γ E : T val Γ delete E : stmt The initializer for a new function must always be top-level function name (to avoid dangling references). Note that we do not support the address operator &. This would lead to dangling references. 7

8 5.3 Statements We use braces { as parentheses for grouping statements. They can be dropped wherever unnecessary. The three basic operations are empty statement, sequencing and return: Γ { : stmt Γ return : void stmt Γ C 1 : δ stmt Γ C 2 : δ stmt Γ {C 1 ; C 2 : δ stmt Γ E : δ val Γ return E : δ stmt A non-returning statement can be deemed to return a result of any type: Γ C : stmt Γ C : δ stmt The infamous expression statement is in Core C++: 5.4 Objects Γ E : δ val Γ E : stmt A storage object is created by a binding declaration: Γ P : S init Γ[x : S] C : δ stmt Γ {Sx = P; C : δ stmt Γ P : S init Γ[x : S const] C : δ stmt Γ {S const x = P; C : δ stmt Variables Variables can be dereferenced and assigned: Γ X : δ var Γ X : δ val Γ X : δ var Γ E : δ val Γ X = E : δ val Γ X : δ var const Γ X : δ val Arrays Arrays are subscripted: Γ X : S[ ] Γ E : int val Γ X[E] : S Γ X : S[ ] const Γ E : int val Γ X[E] : S const Structures Structures have field selection Γ X : struct{...;tx;... Γ X.x : T Γ X : struct{...;tx;... const Γ X.x : T const Initializers Variable initializers are just expressions: Γ E : δ val Γ E : δ var init Array and structure initializers are suitable collections. They are omitted in this summary. 8

9 5.5 Functions A function is applied in the usual fashion: A function is built by a block expression: Γ P : δ(t 1,...,T n ) Γ Q 1 : T 1... Γ Q n : T n Γ P(Q 1,...,Q n ) : δ val Γ[x 1 : T n,...,x n : T n ] C : δ stmt Γ {(T 1 x 1,...,T n x n ) C : δ(t 1,...,T n ) Note that block expressions can be used to create downward closures. 6 Conclusion I hope this brief design notes has convinced the reader that the core of C and C++ are quite solid. The essential concepts can be repackaged in a coherent fashion. Let me mention some open issues which I haven t touched upon: 1. A formal semantics of the language must be defined and a coherence theorem must be proved stating that every type derivation gives the same meaning. For C++ this theorem is alleged not to be true. 2. All member functions are automatically virtual. Is this implementable efficiently? What about multiple inheritance? 3. We have ignored the issue of constructors and destructors. Do we need them? Can they be added cleanly? 4. Should functions return larger values? Other than garbage collection, what problems are there? How do expressions and phrases get reconciled? References [1] B. W. Kernighan and D. M. Ritchie. The C Programming Language, Second Edition. Prentice Hall, [2] J. C. Reynolds. The essence of Algol. In J. W. de Bakker and J. C. van Vliet, editors, Algorithmic Languages, pages North-Holland,

CSCI 3155: Principles of Programming Languages Exam preparation #1 2007

CSCI 3155: Principles of Programming Languages Exam preparation #1 2007 CSCI 3155: Principles of Programming Languages Exam preparation #1 2007 Exercise 1. Consider the if-then-else construct of Pascal, as in the following example: IF 1 = 2 THEN PRINT X ELSE PRINT Y (a) Assume

More information

Motivation was to facilitate development of systems software, especially OS development.

Motivation was to facilitate development of systems software, especially OS development. A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.

More information

Motivation was to facilitate development of systems software, especially OS development.

Motivation was to facilitate development of systems software, especially OS development. A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy

Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy 06-02552 Princ. of Progr. Languages (and Extended ) The University of Birmingham Spring Semester 2016-17 School of Computer Science c Uday Reddy2016-17 Handout 6: Polymorphic Type Systems 1. Polymorphic

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

Haskell 98 in short! CPSC 449 Principles of Programming Languages

Haskell 98 in short! CPSC 449 Principles of Programming Languages Haskell 98 in short! n Syntax and type inferencing similar to ML! n Strongly typed! n Allows for pattern matching in definitions! n Uses lazy evaluation" F definition of infinite lists possible! n Has

More information

Java Primer 1: Types, Classes and Operators

Java Primer 1: Types, Classes and Operators Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,

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

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

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

Handout 10: Imperative programs and the Lambda Calculus

Handout 10: Imperative programs and the Lambda Calculus 06-02552 Princ of Progr Languages (and Extended ) The University of Birmingham Spring Semester 2016-17 School of Computer Science c Uday Reddy2016-17 Handout 10: Imperative programs and the Lambda Calculus

More information

by Pearson Education, Inc. All Rights Reserved.

by Pearson Education, Inc. All Rights Reserved. Let s improve the bubble sort program of Fig. 6.15 to use two functions bubblesort and swap. Function bubblesort sorts the array. It calls function swap (line 51) to exchange the array elements array[j]

More information

Type Checking and Type Inference

Type Checking and Type Inference Type Checking and Type Inference Principles of Programming Languages CSE 307 1 Types in Programming Languages 2 Static Type Checking 3 Polymorphic Type Inference Version: 1.8 17:20:56 2014/08/25 Compiled

More information

1 Introduction. 3 Syntax

1 Introduction. 3 Syntax CS 6110 S18 Lecture 19 Typed λ-calculus 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic semantics,

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

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

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

CPSC 427a: Object-Oriented Programming

CPSC 427a: Object-Oriented Programming CPSC 427a: Object-Oriented Programming Michael J. Fischer Lecture 5 September 15, 2011 CPSC 427a, Lecture 5 1/35 Functions and Methods Parameters Choosing Parameter Types The Implicit Argument Simple Variables

More information

CS4120/4121/5120/5121 Spring 2018 Xi Type System Specification Cornell University Version of February 18, 2018

CS4120/4121/5120/5121 Spring 2018 Xi Type System Specification Cornell University Version of February 18, 2018 CS4120/4121/5120/5121 Spring 2018 Xi Type System Specification Cornell University Version of February 18, 2018 0 Changes 2/16: Added typing rule for empty blocks 1 Types The Xi type system uses a somewhat

More information

Some instance messages and methods

Some instance messages and methods Some instance messages and methods x ^x y ^y movedx: dx Dy: dy x

More information

Lecture Notes on Aggregate Data Structures

Lecture Notes on Aggregate Data Structures Lecture Notes on Aggregate Data Structures 15-312: Foundations of Programming Languages Frank Pfenning Lecture 8 September 23, 2004 In this lecture we discuss various language extensions which make MinML

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

A declaration may appear wherever a statement or expression is allowed. Limited scopes enhance readability.

A declaration may appear wherever a statement or expression is allowed. Limited scopes enhance readability. Scope vs. Lifetime It is usually required that the lifetime of a run-time object at least cover the scope of the identifier. That is, whenever you can access an identifier, the run-time object it denotes

More information

Computer Programming

Computer Programming Computer Programming Introduction Marius Minea marius@cs.upt.ro http://cs.upt.ro/ marius/curs/cp/ 26 September 2017 Course goals Learn programming fundamentals no prior knowledge needed for those who know,

More information

Questions? Static Semantics. Static Semantics. Static Semantics. Next week on Wednesday (5 th of October) no

Questions? Static Semantics. Static Semantics. Static Semantics. Next week on Wednesday (5 th of October) no Questions? First exercise is online: http://www.win.tue.nl/~mvdbrand/courses/glt/1112/ Deadline 17 th of October Next week on Wednesday (5 th of October) no lectures!!! Primitive types Primitive value

More information

Modular implicits for OCaml how to assert success. Gallium Seminar,

Modular implicits for OCaml how to assert success. Gallium Seminar, Modular implicits for OCaml how to assert success Jacques Garrigue Nagoya University Frédéric Bour Sponsored by Jane Street LLC Gallium Seminar, 14-03-2016 Garrigue & Bour Mdular implicits and success

More information

Program construction in C++ for Scientific Computing

Program construction in C++ for Scientific Computing 1 (26) School of Engineering Sciences Program construction in C++ for Scientific Computing 2 (26) Outline 1 2 3 4 5 6 3 (26) Our Point class is a model for the vector space R 2. In this space, operations

More information

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011 CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic

More information

Data Types The ML Type System

Data Types The ML Type System 7 Data Types 7.2.4 The ML Type System The following is an ML version of the tail-recursive Fibonacci function introduced Fibonacci function in ML in Section 6.6.1: EXAMPLE 7.96 1. fun fib (n) = 2. let

More information

Imperative Functional Programming

Imperative Functional Programming Imperative Functional Programming Uday S. Reddy Department of Computer Science The University of Illinois at Urbana-Champaign Urbana, Illinois 61801 reddy@cs.uiuc.edu Our intuitive idea of a function is

More information

Harvard School of Engineering and Applied Sciences Computer Science 152

Harvard School of Engineering and Applied Sciences Computer Science 152 Harvard School of Engineering and Applied Sciences Computer Science 152 Lecture 17 Tuesday, March 30, 2010 1 Polymorph means many forms. Polymorphism is the ability of code to be used on values of different

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

(Refer Slide Time: 4:00)

(Refer Slide Time: 4:00) Principles of Programming Languages Dr. S. Arun Kumar Department of Computer Science & Engineering Indian Institute of Technology, Delhi Lecture - 38 Meanings Let us look at abstracts namely functional

More information

Concepts of Programming Languages

Concepts of Programming Languages Concepts of Programming Languages Lecture 10 - Object-Oriented Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages

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

CS4215 Programming Language Implementation. Martin Henz

CS4215 Programming Language Implementation. Martin Henz CS4215 Programming Language Implementation Martin Henz Thursday 26 January, 2012 2 Chapter 4 The Language simpl In this chapter, we are exting the language epl in order to provide a more powerful programming

More information

Kakadu and Java. David Taubman, UNSW June 3, 2003

Kakadu and Java. David Taubman, UNSW June 3, 2003 Kakadu and Java David Taubman, UNSW June 3, 2003 1 Brief Summary The Kakadu software framework is implemented in C++ using a fairly rigorous object oriented design strategy. All classes which are intended

More information

Dialects of ML. CMSC 330: Organization of Programming Languages. Dialects of ML (cont.) Features of ML. Functional Languages. Features of ML (cont.

Dialects of ML. CMSC 330: Organization of Programming Languages. Dialects of ML (cont.) Features of ML. Functional Languages. Features of ML (cont. CMSC 330: Organization of Programming Languages OCaml 1 Functional Programming Dialects of ML ML (Meta Language) Univ. of Edinburgh,1973 Part of a theorem proving system LCF The Logic of Computable Functions

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

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE? 1. Describe History of C++? The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity

More information

Typed Racket: Racket with Static Types

Typed Racket: Racket with Static Types Typed Racket: Racket with Static Types Version 5.0.2 Sam Tobin-Hochstadt November 6, 2010 Typed Racket is a family of languages, each of which enforce that programs written in the language obey a type

More information

Types-2. Polymorphism

Types-2. Polymorphism Types-2 Polymorphism Type reconstruction (type inference) for a simple PL Typing functions Coercion, conversion, reconstruction Rich area of programming language research as people try to provide safety

More information

3.7 Denotational Semantics

3.7 Denotational Semantics 3.7 Denotational Semantics Denotational semantics, also known as fixed-point semantics, associates to each programming language construct a well-defined and rigorously understood mathematical object. These

More information

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309 A Arithmetic operation floating-point arithmetic, 11 12 integer numbers, 9 11 Arrays, 97 copying, 59 60 creation, 48 elements, 48 empty arrays and vectors, 57 58 executable program, 49 expressions, 48

More information

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Quiz Start Time: 09:34 PM Time Left 82 sec(s) Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability

More information

Variables. Substitution

Variables. Substitution Variables Elements of Programming Languages Lecture 4: Variables, binding and substitution James Cheney University of Edinburgh October 6, 2015 A variable is a symbol that can stand for another expression.

More information

(Not Quite) Minijava

(Not Quite) Minijava (Not Quite) Minijava CMCS22620, Spring 2004 April 5, 2004 1 Syntax program mainclass classdecl mainclass class identifier { public static void main ( String [] identifier ) block } classdecl class identifier

More information

CS201 Latest Solved MCQs

CS201 Latest Solved MCQs Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability

More information

Instantiation of Template class

Instantiation of Template class Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double

More information

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010 IPCoreL Programming Language Reference Manual Phillip Duane Douglas, Jr. 11/3/2010 The IPCoreL Programming Language Reference Manual provides concise information about the grammar, syntax, semantics, and

More information

Object-Oriented Principles and Practice / C++

Object-Oriented Principles and Practice / C++ Object-Oriented Principles and Practice / C++ Alice E. Fischer April 20, 2015 OOPP / C++ Lecture 3... 1/23 New Things in C++ Object vs. Pointer to Object Optional Parameters Enumerations Using an enum

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

These notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without

These notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without These notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without previous written authorization. 1 2 The simplest way to create

More information

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are: LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

More information

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d) CMSC 330: Organization of Programming Languages Tail Calls A tail call is a function call that is the last thing a function does before it returns let add x y = x + y let f z = add z z (* tail call *)

More information

Decaf Language Reference Manual

Decaf Language Reference Manual Decaf Language Reference Manual C. R. Ramakrishnan Department of Computer Science SUNY at Stony Brook Stony Brook, NY 11794-4400 cram@cs.stonybrook.edu February 12, 2012 Decaf is a small object oriented

More information

The Decaf Language. 1 Lexical considerations

The Decaf Language. 1 Lexical considerations The Decaf Language In this course, we will write a compiler for a simple object-oriented programming language called Decaf. Decaf is a strongly-typed, object-oriented language with support for inheritance

More information

Basic concepts. Chapter Toplevel loop

Basic concepts. Chapter Toplevel loop Chapter 3 Basic concepts We examine in this chapter some fundamental concepts which we will use and study in the following chapters. Some of them are specific to the interface with the Caml language (toplevel,

More information

Handout 9: Imperative Programs and State

Handout 9: Imperative Programs and State 06-02552 Princ. of Progr. Languages (and Extended ) The University of Birmingham Spring Semester 2016-17 School of Computer Science c Uday Reddy2016-17 Handout 9: Imperative Programs and State Imperative

More information

Introduction. Programming in C++ Pointers and arrays. Pointers in C and C++ Session 5 - Pointers and Arrays Iterators

Introduction. Programming in C++ Pointers and arrays. Pointers in C and C++ Session 5 - Pointers and Arrays Iterators Session 5 - Pointers and Arrays Iterators Dr Christos Kloukinas City, UoL http://staff.city.ac.uk/c.kloukinas/cpp (slides originally produced by Dr Ross Paterson) Introduction Pointers and arrays: vestiges

More information

Compiler construction 2009

Compiler construction 2009 Compiler construction 2009 Lecture 6 Some project extensions. Pointers and heap allocation. Object-oriented languages. Module systems. Memory structure Javalette restrictions Only local variables and parameters

More information

This book is licensed under a Creative Commons Attribution 3.0 License

This book is licensed under a Creative Commons Attribution 3.0 License 6. Syntax Learning objectives: syntax and semantics syntax diagrams and EBNF describe context-free grammars terminal and nonterminal symbols productions definition of EBNF by itself parse tree grammars

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

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

Wrapping a complex C++ library for Eiffel. FINAL REPORT July 1 st, 2005

Wrapping a complex C++ library for Eiffel. FINAL REPORT July 1 st, 2005 Wrapping a complex C++ library for Eiffel FINAL REPORT July 1 st, 2005 Semester project Student: Supervising Assistant: Supervising Professor: Simon Reinhard simonrei@student.ethz.ch Bernd Schoeller Bertrand

More information

Application: Programming Language Semantics

Application: Programming Language Semantics Chapter 8 Application: Programming Language Semantics Prof. Dr. K. Madlener: Specification and Verification in Higher Order Logic 527 Introduction to Programming Language Semantics Programming Language

More information

Chapter 6 Introduction to Defining Classes

Chapter 6 Introduction to Defining Classes Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of

More information

Lecture Notes on Programming Languages

Lecture Notes on Programming Languages Lecture Notes on Programming Languages 85 Lecture 09: Support for Object-Oriented Programming This lecture discusses how programming languages support object-oriented programming. Topics to be covered

More information

Lecture 18 Tao Wang 1

Lecture 18 Tao Wang 1 Lecture 18 Tao Wang 1 Abstract Data Types in C++ (Classes) A procedural program consists of one or more algorithms that have been written in computerreadable language Input and display of program output

More information

Specifying Syntax. An English Grammar. Components of a Grammar. Language Specification. Types of Grammars. 1. Terminal symbols or terminals, Σ

Specifying Syntax. An English Grammar. Components of a Grammar. Language Specification. Types of Grammars. 1. Terminal symbols or terminals, Σ Specifying Syntax Language Specification Components of a Grammar 1. Terminal symbols or terminals, Σ Syntax Form of phrases Physical arrangement of symbols 2. Nonterminal symbols or syntactic categories,

More information

The New C Standard (Excerpted material)

The New C Standard (Excerpted material) The New C Standard (Excerpted material) An Economic and Cultural Derek M. Jones derek@knosof.co.uk Copyright 2002-2008 Derek M. Jones. All rights reserved. 1378 type specifier type-specifier: void char

More information

A brief introduction to C programming for Java programmers

A brief introduction to C programming for Java programmers A brief introduction to C programming for Java programmers Sven Gestegård Robertz September 2017 There are many similarities between Java and C. The syntax in Java is basically

More information

Auxiliary class interfaces

Auxiliary class interfaces Doc No: SC22/WG21/ N1742=04-0182 Project: Programming Language C++ Date: Sunday, November 07, 2004 Author: Francis Glassborow email: francis@robinton.demon.co.uk Auxiliary class interfaces (This is a replacement

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

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

Programming Languages 2nd edition Tucker and Noonan"

Programming Languages 2nd edition Tucker and Noonan Programming Languages 2nd edition Tucker and Noonan" Chapter 13 Object-Oriented Programming I am surprised that ancient and Modern writers have not attributed greater importance to the laws of inheritance..."

More information

RSL Reference Manual

RSL Reference Manual RSL Reference Manual Part No.: Date: April 6, 1990 Original Authors: Klaus Havelund, Anne Haxthausen Copyright c 1990 Computer Resources International A/S This document is issued on a restricted basis

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

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages CSE 307: Principles of Programming Languages Classes and Inheritance R. Sekar 1 / 52 Topics 1. OOP Introduction 2. Type & Subtype 3. Inheritance 4. Overloading and Overriding 2 / 52 Section 1 OOP Introduction

More information

Objects, Subclassing, Subtyping, and Inheritance

Objects, Subclassing, Subtyping, and Inheritance Objects, Subclassing, Subtyping, and Inheritance Brigitte Pientka School of Computer Science McGill University Montreal, Canada In these notes we will examine four basic concepts which play an important

More information

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings 19/10/2017 CE221 Part 2 1 Variables and References 1 In Java a variable of primitive type is associated with a memory location

More information

Pierce Ch. 3, 8, 11, 15. Type Systems

Pierce Ch. 3, 8, 11, 15. Type Systems Pierce Ch. 3, 8, 11, 15 Type Systems Goals Define the simple language of expressions A small subset of Lisp, with minor modifications Define the type system of this language Mathematical definition using

More information

A Short Summary of Javali

A Short Summary of Javali A Short Summary of Javali October 15, 2015 1 Introduction Javali is a simple language based on ideas found in languages like C++ or Java. Its purpose is to serve as the source language for a simple compiler

More information

Agenda. CS301 Session 11. Common type constructors. Things we could add to Impcore. Discussion: midterm exam - take-home or inclass?

Agenda. CS301 Session 11. Common type constructors. Things we could add to Impcore. Discussion: midterm exam - take-home or inclass? Agenda CS301 Session 11 Discussion: midterm exam - take-home or inclass? Interlude: common type constructors Type soundness 1 2 Things we could add to Impcore Common type constructors Array is a type constructor,

More information

Lecture 2: SML Basics

Lecture 2: SML Basics 15-150 Lecture 2: SML Basics Lecture by Dan Licata January 19, 2012 I d like to start off by talking about someone named Alfred North Whitehead. With someone named Bertrand Russell, Whitehead wrote Principia

More information

The Decaf language 1

The Decaf language 1 The Decaf language 1 In this course, we will write a compiler for a simple object-oriented programming language called Decaf. Decaf is a strongly-typed, object-oriented language with support for inheritance

More information

Typescript on LLVM Language Reference Manual

Typescript on LLVM Language Reference Manual Typescript on LLVM Language Reference Manual Ratheet Pandya UNI: rp2707 COMS 4115 H01 (CVN) 1. Introduction 2. Lexical Conventions 2.1 Tokens 2.2 Comments 2.3 Identifiers 2.4 Reserved Keywords 2.5 String

More information

QUIZ. How could we disable the automatic creation of copyconstructors

QUIZ. How could we disable the automatic creation of copyconstructors QUIZ How could we disable the automatic creation of copyconstructors pre-c++11? What syntax feature did C++11 introduce to make the disabling clearer and more permanent? Give a code example. Ch. 14: Inheritance

More information

Advanced Systems Programming

Advanced Systems Programming Advanced Systems Programming Introduction to C++ Martin Küttler September 19, 2017 1 / 18 About this presentation This presentation is not about learning programming or every C++ feature. It is a short

More information

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity. OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

More information

SOFTWARE ENGINEERING DESIGN I

SOFTWARE ENGINEERING DESIGN I 2 SOFTWARE ENGINEERING DESIGN I 3. Schemas and Theories The aim of this course is to learn how to write formal specifications of computer systems, using classical logic. The key descriptional technique

More information

+2 Volume II OBJECT TECHNOLOGY OBJECTIVE QUESTIONS R.Sreenivasan SanThome HSS, Chennai-4. Chapter -1

+2 Volume II OBJECT TECHNOLOGY OBJECTIVE QUESTIONS R.Sreenivasan SanThome HSS, Chennai-4. Chapter -1 Chapter -1 1. Object Oriented programming is a way of problem solving by combining data and operation 2.The group of data and operation are termed as object. 3.An object is a group of related function

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming 1. What is object-oriented programming (OOP)? OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object

More information

XC Specification. 1 Lexical Conventions. 1.1 Tokens. The specification given in this document describes version 1.0 of XC.

XC Specification. 1 Lexical Conventions. 1.1 Tokens. The specification given in this document describes version 1.0 of XC. XC Specification IN THIS DOCUMENT Lexical Conventions Syntax Notation Meaning of Identifiers Objects and Lvalues Conversions Expressions Declarations Statements External Declarations Scope and Linkage

More information

Compiler Construction I

Compiler Construction I TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Compiler Construction I Dr. Michael Petter, Dr. Axel Simon SoSe 2014 1 / 30 Topic: Semantic Analysis 2 / 30 Semantic Analysis Chapter 1: Type Checking

More information

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited CMSC 330: Organization of Programming Languages Type Systems, Names & Binding Topics Covered Thus Far Programming languages Syntax specification Regular expressions Context free grammars Implementation

More information

Lists. Michael P. Fourman. February 2, 2010

Lists. Michael P. Fourman. February 2, 2010 Lists Michael P. Fourman February 2, 2010 1 Introduction The list is a fundamental datatype in most functional languages. ML is no exception; list is a built-in ML type constructor. However, to introduce

More information

1 Terminology. 2 Environments and Static Scoping. P. N. Hilfinger. Fall Static Analysis: Scope and Types

1 Terminology. 2 Environments and Static Scoping. P. N. Hilfinger. Fall Static Analysis: Scope and Types and Computer Sciences Computer Science Division CS 164 Fall 2006 P. N. Hilfinger Static Analysis: Scope and Types 1 Terminology Programs, in general, are simply collections of definitions of terms, which

More information