Questions? Static Semantics. Static Semantics. Static Semantics. Next week on Wednesday (5 th of October) no
|
|
- Thomas Lloyd
- 5 years ago
- Views:
Transcription
1 Questions? First exercise is online: Deadline 17 th of October Next week on Wednesday (5 th of October) no lectures!!! Primitive types Primitive value can not be decomposed into simpler values Primitive type is a type of which the values are primitive Booleans = { true, false } Integer = {, -2, -1, 0, 1, 2, } / Faculteit Wiskunde en Informatica PAGE 0 / Faculteit Wiskunde en Informatica PAGE 1 Defining primitive types It is possible to define new types via enumeration of values, so-called enumeration type example: type Month is (jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec); signature: enum(name, Values) -> Type Composite types: Composite value is composed of simpler values Composite type is a type of which the values are composite Restricted number of structuring concepts: Cartesian products (tuples, records) mappings (arrays, functions) recursive types (lists, trees) / Faculteit Wiskunde en Informatica PAGE 2 / Faculteit Wiskunde en Informatica PAGE 3
2 Composite types Cartesian products Values of different types are grouped into tuples, classes, or records Basic operations: construction selection Mappings Mapping from one set to another m : S T Formally S T = {m x S m(x) T} Functions implements mapping A mapping S T that takes a value of type S and maps it to type T bool iseven (int n) { return (n % 2 == 0); } Functions with multiple parameters implement mappings S 1 S 2 S n T float power (float b, int n) { } Signature: function(heading, Body) -> Function / Faculteit Wiskunde en Informatica PAGE 4 / Faculteit Wiskunde en Informatica PAGE 5 Recursive types A recursive type is defined in terms of itself Lists: sequence of values: homogeneous or heterogeneous operations: length emptiness test t head selection tail selection concatenation For example: data IntList = Nil Cons Int IntList Type systems A type system of a (programming) language groups values into types Prevents illegal operations, like multiplication of strings by booleans: type error Statically typed language: each variable and expression has a fixed type all operands can be type-checked at compile-time Dynamically typed language: values have fixed type, but variables and expressions have no fixed type. operands can be only type-checked at run-time / Faculteit Wiskunde en Informatica PAGE 6 / Faculteit Wiskunde en Informatica PAGE 7
3 Type equivalence Determining the whether 2 composite types are the same T 1 T 2 Structural equivalence Name equivalence Type equivalence: T 1 T 2 Structural equivalence: T 1 T 2 if and only if T 1 and T 2 have the same set of values if T 1 and T 2 are both primitive and identical, then T 1 T 2 if T 1 = A 1 B 1 and T 2 = A 2 B 2, then T 1 T 2 if and only if A 1 A 2 and B 1 B 2 if T 1 = A 1 B 1 and T 2 = A 2 B 2, then T 1 T 2 if and only if A 1 A 2 and B 1 B 2 if T 1 = A 1 + B 1 and T 2 = A 2 + B 2, then T 1 T 2 if and only if A 1 A 2 and B 1 B 2 otherwise T 1 / T 2 / Faculteit Wiskunde en Informatica PAGE 8 / Faculteit Wiskunde en Informatica PAGE 9 Type equivalence: T 1 T 2 Name equivalence: T 1 T 2 if and only if T 1 and T 2 are defined in the same place! struct Position {int x, y; }; struct Position pos; struct Date {int x, y; }; struct Date today; void show (struct Date d); Lifetime of a variable is the time between creation (allocation) and destruction (deallocation) Global variable s lifetime is the program s run-time Local variable s lifetime is an activation of a block Heap variable s lifetime is arbitrary, but maximum is program s run-time Persistent variable s lifetime is arbitrary and not restricted to program s run-time show(today); passes type checking using both structural and name equivalence, show(pos); only passes using structural equivalence / Faculteit Wiskunde en Informatica PAGE 10 / Faculteit Wiskunde en Informatica PAGE 11
4 A global variable is a variable that can be used any where in a program A local variable is only available within the block where it is declared A block is a program construct that includes local declarations An activation of a block is the time interval that the block is executed Bindings and environments If identifiers occur in an expression, such an expression cannot be understood in isolation: its meaning depends on the declarations of these identifiers elsewhere in the program A binding is an association between an identifier and an entity such as value, variable or procedure An environment (or name space) is a set of bindings: Consider the type environment in PICO / Faculteit Wiskunde en Informatica PAGE 12 / Faculteit Wiskunde en Informatica PAGE 13 The scope of a declaration is the part of the program where the declaration is effective A block is a language construct that delimits the scope of declarations within it monolithic block structure, e.g. Cobol flat block structure, e.g. Fortran nested block structure, e.g. Algol-like language, C, Java Blocks: A block command is a form of command that contains a local declaration D and a subcommand C In C/C++ and Java: { D C } if (x > y) {int z = x; x = y; y = z;} A block expression is a form of expression that contains a local declaration D and a subexpression E Haskell provides block expressions: let D in E / Faculteit Wiskunde en Informatica PAGE 14 / Faculteit Wiskunde en Informatica PAGE 15
5 Scope and visibility A binding occurrence of identifier I is an occurrence where I is bound to some entity X An applied occurrence of I is an occurrence where use is made of the entity X to which I is bound Each applied occurrence of I should correspond to exactly one binding occurrence of I An identifier I may be defined in multiple blocks Nested blocks, some outer block contains a declaration of I: If inner block does not contain a declaration of I, then declaration is visible throughout outer and inner blocks If inner block contains a declaration of I, then the inner block declaration hides the outer block declaration Static vs dynamic scoping A language is statically scoped if the body of a procedure is executed in the environment of the procedure s definition compile-time binding of identifiers A language is dynamically scoped if the body of a procedure is executed in the environment of the procedure call run-time binding of identifiers Nearly all programming languages (C, C++, Java, etc.) are statically scoped / Faculteit Wiskunde en Informatica PAGE 16 / Faculteit Wiskunde en Informatica PAGE 17 Questions? First exercise is online: Deadline 17 th of October Next week on Wednesday (5 th of October) no lectures!!! Static vs dynamic scoping Consider: const int s = 2; int f(int x) { return s * x;} void p(int y) { print(f(y));} (1) void q(int z) { const int s = 3; print(f(z));} (2) What tis the value printed at t(1) and d(2)? / Faculteit Wiskunde en Informatica PAGE 18 / Faculteit Wiskunde en Informatica PAGE 19
6 A declaration is a language construct to produce a binding Types of simple declarations: type constant variable procedure A procedure definition binds an identifier to a procedure function procedure A function definition: bool even(int n) {return (n % 2 == 0);} A procedure definition: void double(int& n) { n *= 2; } / Faculteit Wiskunde en Informatica PAGE 20 / Faculteit Wiskunde en Informatica PAGE 21 A function/procedure is an entity that embodies a computation a function embodies an expression to be evaluated a procedure embodies a command to be executed Methods in OO languages g are procedures but closely related to classes A function evaluates an expression and yields a value as result T I (FPD 1,, FPD n ) B where: T is result type I is function s identifier FPD i are formal parameter declarations B is a block command (also called body), B contains at tleast one statement t tof fthe form return E Call via I(AP 1,, AP n ) where: AP i are actual parameters / Faculteit Wiskunde en Informatica PAGE 22 / Faculteit Wiskunde en Informatica PAGE 23
7 A procedure embodies a command to be executed and will update variables void I(FPD 1,, FPD n ) B where: I is function s identifier FPD i are formal parameter declarations B is a block command (also called body) Call via I(AP 1,, AP n ) where: AP i are actual parameters Parameters and arguments An argument is a value or other entity that is passed to a procedure An actual parameter is an expression that yields an argument A formal parameter is an identifier through which a procedure can access an argument Association between formal parameter and argument is called parameter mechanism two basic concepts: copy parameter mechanism reference parameter mechanism / Faculteit Wiskunde en Informatica PAGE 24 / Faculteit Wiskunde en Informatica PAGE 25 Copy parameter mechanism allows the transfer of values to and from a procedure A formal parameter FP denotes a local variable of the procedure A reference parameter allows for the formal parameter FP to be bound directly to the argument An identifier is overloaded of it denotes two or more distinct procedures in the same scope In older programming languages operators for certain built-in functions are overloaded - operator: integer negation (Integer Integer) floating-point negation (Float Float) integer subtraction (Integer Integer Integer) floating-point subtraction (Float Float Float) / Faculteit Wiskunde en Informatica PAGE 26 / Faculteit Wiskunde en Informatica PAGE 27
8 Identifier F denotes function (f 1 ) of type S 1 T 1 function (f 2 ) of type S 2 T 2 context-independent overloading requires S 1 and S 2 are nonequivalent if actual parameter E of F(E) is of type S 1 then F denotes f 1 if E is of type S 2 then F denotes f 2 with context-independent overloading the function can be uniquely identified by the type of the actual parameter Identifier F denotes function (f 1 ) of type S 1 T 1 function (f 2 ) of type S 2 T 2 context-dependent overloading requires S 1 and S 2 are nonequivalent or T 1 and T 2 are non-equivalent if S 1 and S 2 are non-equivalent, see previous slide if S 1 and S 2 are equivalent, but T 1 and T 2 are non-equivalent the context t must be taken into consideration if the context F(E) is of type T 1 then F denotes f 1 if the context is of type T 2 then F denotes f 2 with context-dependent overloading, it is possible to formulate expressions which cannot be uniquely identified / Faculteit Wiskunde en Informatica PAGE 28 / Faculteit Wiskunde en Informatica PAGE 29 Polymorphism Monomorphic procedures can only operate on arguments of a fixed type Polymorphic procedures can operate uniformly on arguments of a family of types A type variable is an identifier that stands for a family of types monomorphic second(x : Int, y : Int) = y polymorphic second(x : δ, y : τ) = y A polytype derives a family of similar types δ τ τ includes Integer Boolean Boolean String String String but not Boolean Integer Boolean Integer Integer / Faculteit Wiskunde en Informatica PAGE 30 / Faculteit Wiskunde en Informatica PAGE 31
9 Statically type programming languages insist on explicit declaration of the type of entity in programs integer I := E In some languages we can write a definition I = E where type of I is not explicitly stated, but inferred from E Type inference is a process where the type of a declared entity is inferred instead of explicitly stated monotype, if strong clues, e.g., if a monomorphic operator is used polytype in case of polymorphic operators even n = (n mod 2 = 0) type of even is: Integer Integer Integer id x = x type of id is: τ τ f. g = \x -> f(g(x)) types of f and g are β γ and α β, respectively variable x must be of type α subexpression f(g(x)) is of type γ expression \x -> f(g(x)) is of type α γ. is of type (β γ) (α β) (α γ) / Faculteit Wiskunde en Informatica PAGE 32 / Faculteit Wiskunde en Informatica PAGE 33 Further reading Pierce, B.C. (2002), Types and Programming Languages. MIT Press Brand, M.G.J. van den, Meer, A.P. van der & Serebrenik, A. (2009). Type checking evolving languages with MSOS. In J. Palsberg (Ed.), Semantics and Algebraic Specification. (pp ) 226) Berlin: Springer Keiren, J.J.A. & Reniers, M.A. (2011). Type checking mcrl2. Computer Science Report No , 11, Eindhoven: Technische Universiteit Eindhoven / Faculteit Wiskunde en Informatica PAGE 34
CA341 - Comparative Programming Languages
CA341 - Comparative Programming Languages and David Sinclair Data, Values and Types In 1976 Niklaus Wirth (inventor of Pascal, Modula, Oberon, etc) wrote a book called Algorithms + Data Structures = Programs
More informationChapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures
Chapter 5: Procedural abstraction Proper procedures and function procedures Abstraction in programming enables distinction: What a program unit does How a program unit works This enables separation of
More information4 Bindings and Scope. Bindings and environments. Scope, block structure, and visibility. Declarations. Blocks. 2004, D.A. Watt, University of Glasgow
4 Bindings and Scope Bindings and environments. Scope, block structure, and visibility. Declarations. Blocks. 2004, D.A. Watt, University of Glasgow 1 Bindings and environments PL expressions and commands
More informationCh. 7: Generic abstraction. Generic units and instantiation. Generic units and instantiation. Generic units and instantiation
Ch. 7: Generic abstraction Generic units and instantiation Reusable program units are applicable in a variety of applications stack queue list set such program units are generic wrt the data the process
More informationCSE 307: Principles of Programming Languages
1 / 26 CSE 307: Principles of Programming Languages Names, Scopes, and Bindings R. Sekar 2 / 26 Topics Bindings 1. Bindings Bindings: Names and Attributes Names are a fundamental abstraction in languages
More informationExample: Haskell algebraic data types (1)
Example: Haskell algebraic data types (1) Type declaration: data Number = Exact Int Inexact Float Set of values: Each Number value consists of a tag, together with either an Integer variant (if the tag
More informationLecture #23: Conversion and Type Inference
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). Last modified: Fri Oct 20 10:46:40 2006 CS164:
More informationConversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). In Java, this is legal: Object x = "Hello";
More informationLecture 16: Static Semantics Overview 1
Lecture 16: 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 informationCS558 Programming Languages. Winter 2013 Lecture 3
CS558 Programming Languages Winter 2013 Lecture 3 1 NAMES AND BINDING One essential part of being a high-level language is having convenient names for things: variables constants types functions etc. classes
More informationStorage. Outline. Variables and Updating. Composite Variables. Storables Lifetime : Programming Languages. Course slides - Storage
Storage 1 Variables and Updating Outline Composite Variables Total and selective updating Array variables Storables Lifetime Local and global variables Heap variables Persistent variables Garbage collection
More informationPrinciples of Programming Languages
Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp- 14/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 23! Type systems Type safety Type checking Equivalence,
More informationStatic Semantics. Lecture 15. (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1
Static Semantics Lecture 15 (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1 Current Status Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing
More informationData Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011
Data Types (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011 Based in part on slides and notes by Bjoern 1 Brandenburg, S. Olivier and A. Block. 1 Data Types Hardware-level:
More informationLecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]
1 Lecture Overview Types 1. Type systems 2. How to think about types 3. The classification of types 4. Type equivalence structural equivalence name equivalence 5. Type compatibility 6. Type inference [Scott,
More informationSMURF Language Reference Manual Serial MUsic Represented as Functions
SMURF Language Reference Manual Serial MUsic Represented as Functions Richard Townsend, Lianne Lairmore, Lindsay Neubauer, Van Bui, Kuangya Zhai {rt2515, lel2143, lan2135, vb2363, kz2219}@columbia.edu
More informationCMSC 330: Organization of Programming Languages. Lets, Tuples, Records
CMSC 330: Organization of Programming Languages Lets, Tuples, Records CMSC330 Spring 2018 1 Let Expressions Enable binding variables in other expressions These are different from the let definitions we
More informationNote 3. Types. Yunheung Paek. Associate Professor Software Optimizations and Restructuring Lab. Seoul National University
Note 3 Types Yunheung Paek Associate Professor Software Optimizations and Restructuring Lab. Seoul National University Topics Definition of a type Kinds of types Issues on types Type checking Type conversion
More informationProperties 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 informationCS558 Programming Languages
CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and
More informationShort 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 informationLecture #13: Type Inference and Unification. Typing In the Language ML. Type Inference. Doing Type Inference
Lecture #13: Type Inference and Unification Typing In the Language ML Examples from the language ML: fun map f [] = [] map f (a :: y) = (f a) :: (map f y) fun reduce f init [] = init reduce f init (a ::
More informationCS201 - 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 informationCOSE212: Programming Languages. Lecture 3 Functional Programming in OCaml
COSE212: Programming Languages Lecture 3 Functional Programming in OCaml Hakjoo Oh 2017 Fall Hakjoo Oh COSE212 2017 Fall, Lecture 3 September 18, 2017 1 / 44 Why learn ML? Learning ML is a good way of
More informationProgrammiersprachen (Programming Languages)
2016-05-13 Preface Programmiersprachen (Programming Languages) coordinates: lecturer: web: usable for: requirements: No. 185.208, VU, 3 ECTS Franz Puntigam http://www.complang.tuwien.ac.at/franz/ps.html
More informationCOMP 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 informationSEMANTIC 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 informationCS 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 informationTypes and Type Inference
CS 242 2012 Types and Type Inference Notes modified from John Mitchell and Kathleen Fisher Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on Web!! Outline General discussion of
More informationProgramming Languages, Summary CSC419; Odelia Schwartz
Programming Languages, Summary CSC419; Odelia Schwartz Chapter 1 Topics Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design
More informationCS 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 informationChapter 5. Names, Bindings, and Scopes
Chapter 5 Names, Bindings, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Scope Scope and Lifetime Referencing Environments Named Constants 1-2 Introduction Imperative
More informationCSCE 314 Programming Languages. Type System
CSCE 314 Programming Languages Type System Dr. Hyunyoung Lee 1 Names Names refer to different kinds of entities in programs, such as variables, functions, classes, templates, modules,.... Names can be
More informationCS321 Languages and Compiler Design I Winter 2012 Lecture 13
STATIC SEMANTICS Static Semantics are those aspects of a program s meaning that can be studied at at compile time (i.e., without running the program). Contrasts with Dynamic Semantics, which describe how
More informationFundamentals of Programming Languages
Fundamentals of Programming Languages 1. DEFINITIONS... 2 2. BUILT-IN TYPES AND PRIMITIVE TYPES... 3 TYPE COMPATIBILITY... 9 GENERIC TYPES... 14 MONOMORPHIC VERSUS POLYMORPHIC... 16 TYPE IMPLEMENTATION
More informationConcepts of programming languages
Concepts of programming languages Lecture 2 Wouter Swierstra 1 Last time: programming languages In the first lecture I tried to motivate why we might consider programming languages themselves as interesting
More informationUser-Defined Algebraic Data Types
72 Static Semantics User-Defined Types User-Defined Algebraic Data Types An algebraic data type declaration has the general form: data cx T α 1... α k = K 1 τ 11... τ 1k1... K n τ n1... τ nkn introduces
More informationInformal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility
Informal Semantics of Data semantic specification names (identifiers) attributes binding declarations scope rules visibility 1 Ways to Specify Semantics Standards Documents (Language Definition) Language
More informationLexical 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 informationLecture 7: Type Systems and Symbol Tables. CS 540 George Mason University
Lecture 7: Type Systems and Symbol Tables CS 540 George Mason University Static Analysis Compilers examine code to find semantic problems. Easy: undeclared variables, tag matching Difficult: preventing
More information1 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 informationStorage. Outline. Variables and updating. Copy vs. Ref semantics Lifetime. Dangling References Garbage collection
Storage 1 Variables and updating Outline Copy vs. Ref semantics Lifetime Local and global variables Heap variables Persistent variables Dangling References Garbage collection 2 Variables and Updating Variable:
More informationHaskell 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 informationCPSC 3740 Programming Languages University of Lethbridge. Data Types
Data Types A data type defines a collection of data values and a set of predefined operations on those values Some languages allow user to define additional types Useful for error detection through type
More informationHANDLING NONLOCAL REFERENCES
SYMBOL TABLE A symbol table is a data structure kept by a translator that allows it to keep track of each declared name and its binding. Assume for now that each name is unique within its local scope.
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing
More informationSE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms
SE352b Software Engineering Design Tools W3: Programming Paradigms Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa SE352b: Roadmap CASE Tools: Introduction System Programming Tools Programming Paradigms
More informationSpecial Topics: Programming Languages
Lecture #15 0 V22.0490.001 Special Topics: Programming Languages B. Mishra New York University. Lecture # 15 Lecture #15 1 Slide 1 Scope Issues Those features which describe and control the use of named
More informationFunctional Programming. Lecture 2: Algebra
Functional Programming by Łukasz Stafiniak Email: lukstafi@gmail.com, lukstafi@ii.uni.wroc.pl Web: www.ii.uni.wroc.pl/~lukstafi Lecture 2: Algebra Algebraic Data Types and some curious analogies 1 A Glimpse
More informationCompilers. 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 informationTypes. What is a type?
Types What is a type? Type checking Type conversion Aggregates: strings, arrays, structures Enumeration types Subtypes Types, CS314 Fall 01 BGRyder 1 What is a type? A set of values and the valid operations
More information1 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 informationType 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 informationA 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 information22c:111 Programming Language Concepts. Fall Types I
22c:111 Programming Language Concepts Fall 2008 Types I Copyright 2007-08, The McGraw-Hill Company and Cesare Tinelli. These notes were originally developed by Allen Tucker, Robert Noonan and modified
More informationCS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find
CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS
More informationSymbol Tables Symbol Table: In computer science, a symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is
More informationSML A F unctional Functional Language Language Lecture 19
SML A Functional Language Lecture 19 Introduction to SML SML is a functional programming language and acronym for Standard d Meta Language. SML has basic data objects as expressions, functions and list
More informationProgramming Languages Third Edition. Chapter 7 Basic Semantics
Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol
More informationTypes and Programming Languages. Lecture 5. Extensions of simple types
Types and Programming Languages Lecture 5. Extensions of simple types Xiaojuan Cai cxj@sjtu.edu.cn BASICS Lab, Shanghai Jiao Tong University Fall, 2016 Coming soon Simply typed λ-calculus has enough structure
More informationOrganization of Programming Languages CS3200/5200N. Lecture 11
Organization of Programming Languages CS3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Functional vs. Imperative The design of the imperative languages
More informationTail 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 informationPierce 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 informationInformatica 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 informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Type Systems, Names and Binding CMSC 330 - Spring 2013 1 Topics Covered Thus Far! Programming languages Ruby OCaml! Syntax specification Regular expressions
More informationG 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 informationType-indexed functions in Generic Haskell
Type-indexed functions in Generic Haskell Johan Jeuring September 15, 2004 Introduction Today I will talk about: a Types of polymorphism. b Type-indexed functions. c Dependencies. Read about b, and c in
More informationChapter 3 Linear Structures: Lists
Plan Chapter 3 Linear Structures: Lists 1. Two constructors for lists... 3.2 2. Lists... 3.3 3. Basic operations... 3.5 4. Constructors and pattern matching... 3.6 5. Simple operations on lists... 3.9
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2016 Lecture 3a Andrew Tolmach Portland State University 1994-2016 Formal Semantics Goal: rigorous and unambiguous definition in terms of a wellunderstood formalism (e.g.
More informationThe Design of Core C++ (Notes)
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
More informationProgramming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC http://courses.engr.illinois.edu/cs421 Based in part on slides by Mattox Beckman, as updated by Vikram Adve and Gul Agha 10/3/17
More informationData Types. Every program uses data, either explicitly or implicitly to arrive at a result.
Every program uses data, either explicitly or implicitly to arrive at a result. Data in a program is collected into data structures, and is manipulated by algorithms. Algorithms + Data Structures = Programs
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 2 Thomas Wies New York University Review Last week Programming Languages Overview Syntax and Semantics Grammars and Regular Expressions High-level
More informationTopics 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 informationLexical 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 informationCS558 Programming Languages
CS558 Programming Languages Fall 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Type Inference Some statically typed languages, like ML (and to a lesser extent Scala), offer alternative
More informationIEEE LANGUAGE REFERENCE MANUAL Std P1076a /D3
LANGUAGE REFERENCE MANUAL Std P1076a-1999 2000/D3 Clause 10 Scope and visibility The rules defining the scope of declarations and the rules defining which identifiers are visible at various points in the
More informationThe 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 informationNames, Scope, and Bindings
Names, Scope, and Bindings COMS W4115 Prof. Stephen A. Edwards Fall 2007 Columbia University Department of Computer Science What s In a Name? Name: way to refer to something else variables, functions,
More informationCSCI312 Principles of Programming Languages!
CSCI312 Principles of Programming Languages! Chapter 5 Types Xu Liu! ! 5.1!Type Errors! 5.2!Static and Dynamic Typing! 5.3!Basic Types! 5.4!NonBasic Types! 5.5!Recursive Data Types! 5.6!Functions as Types!
More informationFunctional Languages. CSE 307 Principles of Programming Languages Stony Brook University
Functional Languages CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Historical Origins 2 The imperative and functional models grew out of work
More informationArray. Prepared By - Rifat Shahriyar
Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types
More informationTypes and Type Inference
Types and Type Inference Mooly Sagiv Slides by Kathleen Fisher and John Mitchell Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on the course homepage Outline General discussion
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2017 Lecture 3a Andrew Tolmach Portland State University 1994-2017 Binding, Scope, Storage Part of being a high-level language is letting the programmer name things: variables
More informationProgramming Language Concepts, cs2104 Lecture 04 ( )
Programming Language Concepts, cs2104 Lecture 04 (2003-08-29) Seif Haridi Department of Computer Science, NUS haridi@comp.nus.edu.sg 2003-09-05 S. Haridi, CS2104, L04 (slides: C. Schulte, S. Haridi) 1
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques () Lecture 20 February 28, 2018 Transition to Java Announcements HW05: GUI programming Due: THURSDAY!! at 11:59:59pm Lots of TA office hours today Thursday See Piazza
More informationChapter 3 Linear Structures: Lists
Plan Chapter 3 Linear Structures: Lists 1. Lists... 3.2 2. Basic operations... 3.4 3. Constructors and pattern matching... 3.5 4. Polymorphism... 3.8 5. Simple operations on lists... 3.11 6. Application:
More informationCSC 533: Organization of Programming Languages. Spring 2005
CSC 533: Organization of Programming Languages Spring 2005 Language features and issues variables & bindings data types primitive complex/structured expressions & assignments control structures subprograms
More informationCS558 Programming Languages
CS558 Programming Languages Winter 2018 Lecture 7b Andrew Tolmach Portland State University 1994-2018 Dynamic Type Checking Static type checking offers the great advantage of catching errors early And
More informationTypes II. Hwansoo Han
Types II Hwansoo Han Arrays Most common and important composite data types Homogeneous elements, unlike records Fortran77 requires element type be scalar Elements can be any type (Fortran90, etc.) A mapping
More informationData Types. Data Types. Introduction. Data Types. Data Types. Data Types. Introduction
Introduction Primitive Composite Structured Abstract Introduction Introduction Data Type is a Collection of Data Objects Possible r-values for a memory cell Set of operations on those objects Descriptor
More informationOrganization of Programming Languages CS320/520N. Lecture 06. Razvan C. Bunescu School of Electrical Engineering and Computer Science
Organization of Programming Languages CS320/520N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Data Types A data type defines a collection of data objects and
More informationIndex. 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 informationNames, Scope, and Bindings
Names, Scope, and Bindings COMS W4115 Prof. Stephen A. Edwards Spring 2007 Columbia University Department of Computer Science What s In a Name? Name: way to refer to something else variables, functions,
More informationCSCI-GA Scripting Languages
CSCI-GA.3033.003 Scripting Languages 12/02/2013 OCaml 1 Acknowledgement The material on these slides is based on notes provided by Dexter Kozen. 2 About OCaml A functional programming language All computation
More informationAttributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes,
Chapter 5 Basic Semantics Attributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes, and the Environment Variables
More informationProgramming Languages
CSE 230: Winter 2008 Principles of Programming Languages Ocaml/HW #3 Q-A Session Push deadline = Mar 10 Session Mon 3pm? Lecture 15: Type Systems Ranjit Jhala UC San Diego Why Typed Languages? Development
More informationChapter 5 Names, Binding, Type Checking and Scopes
Chapter 5 Names, Binding, Type Checking and Scopes Names - We discuss all user-defined names here - Design issues for names: -Maximum length? - Are connector characters allowed? - Are names case sensitive?
More informationReview of the C Programming Language
Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the
More informationCS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08
CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 17: Types and Type-Checking 25 Feb 08 CS 412/413 Spring 2008 Introduction to Compilers 1 What Are Types? Types describe the values possibly
More information