Lectures Basics in Procedural Programming: Machinery

Size: px
Start display at page:

Download "Lectures Basics in Procedural Programming: Machinery"

Transcription

1 Lectures Basics in Procedural Programming: Machinery February 21-28, :04:07 1/48 Lecture3-6E-2014.pdf (#21)

2 Basics in Procedural Programming: Machinery Naming and Binding Mutable Values: Denotable, Storable and Expressible Value Env, Store, AR and Blocks: Motivations Blocks: Inline blocks and Procedure/function (body) block Blocks: Static and Dynamic Scope Activation Records: Structure and Implementation Programming Unit Aliasing, Closures, Lambda Lifting Env: Formalization and Implementation Store: Formalization and Implementation :04:08 2/48 Lecture3-6E-2014.pdf (2/48)

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

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

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

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

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

8 Expressible Values Expressible Values = Have an explicit, syntactic, presentation in the language; These values are useful for introducing constant values in expressions; Hence, values of common use in the expressions of the language are also expressible value; Integers are expressible values of C Are arrays expressible values of C? Are lists expressible values of Ocaml (Haskell)? Are vectors expressible values of Java? Are functions expressible values of Ocaml (Haskell)? Are methods expressible values of Java? :04:08 8/48 Lecture3-6E-2014.pdf (8/48)

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

10 Program Sectioning: Blocks Block = It is used for creating sections of program that are: (partially) autonomous in the definitions that may be used, and may exhibit specific functionalities, and may be valid supports in program verification and modification Two main kinds in Procedural Programming: inline blocks procedures and functions :04:08 10/48 Lecture3-6E-2014.pdf (10/48)

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

12 Blocks: Inline vs. Procedures - Exercises (a) According to the above features, describe the features of the blocks of the compound statements of C. (b) Moreover, answer to: in what features the inline blocks of Java differ from the ones described in the slide (a) Answer. anonymous; contains two parts: 1. Local Definitions: But without procedure/functions 2. Code: Any sequence of statements including jump stms. (break, return, continue, goto) may be nested: Execution exits depend on the Code stms. (b) Answer. anonymous; contains two parts: 1. Local Definitions (including classes, hence methods) 2. Code: Any sequence of statements including jump stms. (break, return, continue, goto) may be nested: Execution exits depend on the Code stms :04:08 12/48 Lecture3-6E-2014.pdf (12/48)

13 Blocks: Scope of Identifier definitions Scope. Let I be an identifier defined with the value d in a block A, of a program P, i.e.binding(a,i)=d in P. Then, Scope(I,A) is the set Z of sections of P that must use the value d when they refer to the identifier I: Scope(I,A)={B binding(b,i)=binding(a,i)} Definition of Scope depends from the language; Two kinds of Scope (and correspondingly, two classes of languages): Scope is static (Hence, Languages with static Scope) Scope is dynamic (Hence, Languages with dynamic Scope) :04:08 13/48 Lecture3-6E-2014.pdf (13/48)

14 Blocks: Static and Dynamic Scope Scope(I,A)={B binding(b,i)=binding(a,i)} Static Scope: S-Scope Z includes A; Z includes also, any block B which is: (defined) within A and it is such that its section Local Definitions does not contain a new definition for I in this case, I is also, called a non-local of B. Dynamic Scope: D-Scope Z includes A; Z includes also, any block B which is: executed during the execution of the Code of A and it is such that its section Local Definitions does not contain a new definition for I in this case, I is also called a non-local of B :04:09 14/48 Lecture3-6E-2014.pdf (14/48)

15 Blocks: Static and Dynamic Scope/2 They differ only on the non-locals of procedures and functions Give names to inline blocks by using capital letters, in alphabetic order, from A that is assigned to the outermost, topmost, block; 1 List the block in the program; 2 Compute the function Scope of each defined identifiers; 3 Compute the static, S-Scope, and dynamic, D-Scope, scope of each defined identifiers; 4 Show printed values when static, respectively dynamic, scope is used A:{int x = 0; void pippo(int n){x=n+x;} pippo(3); print(x); printer: 3 3 B:{int x = 0; pippo(3); print(x); printer: 0 3 } print(x); printer: 6 3 } (1) The program blocks are: {A,pippo, B}; (2) Scope(A,x)={A,pippo}; Scope(B,x)={B,pippo}; Scope(pippo,n)={pippo} (3) S-Scope(A,x)={A,pippo}; S-Scope(B,x)={B}; S-Scope(pippo,n)={pippo} D-Scope(A,x)={A,pippo}; D-Scope(B,x)={B,pippo}; D-Scope(pippo,n)={pippo} :04:09 15/48 Lecture3-6E-2014.pdf (15/48)

16 Static vs. Dynamic Scope: Motivations Two kinds of Scope (and correspondingly, two classes of languages): Scope is static (Almost all languages) Also called, lexical scope (Symbol-Tables of front-ends) The binding of a non-local is localized near to its use The binding of a non-local in a block is the same in all block executions (during each program execution) Allow a better sectioning of the program; Allow a better programming approach (programming methodologies) Implementation is efficient but a bit heavy. Scope is dynamic (Lisp-like languages) Avoid the use of non-locals is recommended in the use of languages with dynamic scope (lambda-lifting). Implementation is not efficient but very easy to do :04:09 16/48 Lecture3-6E-2014.pdf (16/48)

17 Blocks: Different Notions In some languages (including Java) inline blocks cannot re-define a non-local variable (i.e.the shadowing of local variables is forbidden) In some languages blocks are not always, enclosed by delimiters (non ANSI C), or declarations may occur everywhere in a block (JavaScripts) {int x = 5;... {int y = 0; x+1;... int x = 10; This declaration may be considered: y = x+y; (a) either, the beginning of a new block, ending at the end of its outer block (non ANSI C) } (b) or, to be moved to the beginning of the block in which it is declared (JavaScript).... } How many blocks here? {int x = 4; {int x = 4; while(x > 0){ while(x > 0){ --x; int x; int x; - -x; print(x); print(x); } }...}...} What is while supposed to compute accor- Provide a re-phrasing in ANSI C of the code and ding to the two readings, (a) and (b) above? show the first 10 printed rows and comment them :04:09 17/48 Lecture3-6E-2014.pdf (17/48)

18 Activation Record: Implementation for inline blocks Activation Records: Support the execution of the code of a block (i.e. program section) Support the control transfer among different blocks Have different structure depending on: inline block: Env (called frame) Program Counter (pc) Memory Section for Expression Intermediate Results (ri) Dynamic Chain pointer (cd) :04:09 18/48 Lecture3-6E-2014.pdf (18/48)

19 Activation Record: Implementation for procedure blocks Activation Records: inline block:... procedure block: Env (called frame) Program Counter (pc) Memory Section for Expression Intermediate Results (ri) Dynamic Chain pointer (cd) Static Chain pointer (cs) only for static scope Return Address (ret) Result Value Address (val) :04:09 19/48 Lecture3-6E-2014.pdf (19/48)

20 Finding the Right Binding: The Simple Approach Q: How can we finding the right binding of an identifier (during program execution)? A: By using the active AR in a backward visit of the AR frames along: (Static Scope) the Static Chain (cs if procedures / cd if inline) (Dynamic Scope) the Dynamic Chain (cd) and stopping when a binding for the identifier is found. the found binding, if any, is the right binding of the identifier :04:09 20/48 Lecture3-6E-2014.pdf (20/48)

21 Finding the Right Binding: Le Blank - Cook Approach The simple approach requires O(n*p) accesses and comparisons (for n-sized frames / p-sized chain lenghts) Le Blank - Cook (1983) is only for Static Scope It reduces the finding cost to O(p) (and by using, display vector to O(1)) It consits in: To each identifier I that is used in a block B it associates a pair [l,p]: l=iscalledstatic Chain Link and is equal to the number of nestings of B w.r. to the block A containing the binding of I. l=0 means the 0-nesting( level)s Noting that, procedure blocks that are declared in a block are considered as nested in such a block. p=iscalledposition and is equal to the position, from the top, in the frame of A (above), of the binding of I. It replaces, identifiers, everywhere are used, with their pair [l,p], above :04:09 21/48 Lecture3-6E-2014.pdf (21/48)

22 Le Blank - Cook (1983): s Le Blank - Cook is only for Static Scope It reduces the finding cost to O(p) (and by using, display vector to O(1)) It replaces, identifiers, everywhere are used, with their pair [l,p], above :04:09 22/48 Lecture3-6E-2014.pdf (22/48)

23 Le Blank - Cook (1983): s/2 Noting the use of display vectors, in red lines/boxes, in the image on the right side :04:09 23/48 Lecture3-6E-2014.pdf (23/48)

24 Programming Units Programming Units = Each Section that is able to completely describe one (or more) functionalities of the algorithm that the program expresses. procedure, function, inline block, module, package, abstraction, class... are candidates for Programming Units but each of them is or not, a P.U. depending on various factors, including the way in which bindings are used We must write a program for an algorithm A which: -First,itreadsasequenceofstudentapplications:Todoitforinstance,A suggests the use of an algorithm N that reads the anagraphic data and a different one, let us say M, thatreadstheacademicdata; -Then,itsortsthecollecteddata:Again,todoit(thealgorithmor)theprogrammer suggests to use of a sorting algorithm B that requires some suitable representation conversion algorithms, let us say N and M ; -Then,...butwestopherethehistory :04:09 24/48 Lecture3-6E-2014.pdf (24/48)

25 Programming Units: Apply them We must write a program for an algorithm A which: -First,itreadsasequenceofstudentapplications:Todoitforinstance,A suggests the use of an algorithm N that reads the anagraphic data and a different one, let us say M, thatreadstheacademicdata; -Then,itsortsthecollecteddata:Again,todoit(thealgorithmor)theprogrammer suggests to use of a sorting algorithm B that requires some suitable representation conversion algorithms, let us say N and M ; -Then,...butwestopherethehistory :04:09 25/48 Lecture3-6E-2014.pdf (25/48)

26 Sectioning and Scope in C: A Case Study Procedures of C may contain only non-locals that must be globals of the module Q: How can such a constraint be imposed in C? What about its implications in: Q: Programming? A: Procedures are not Programming Units, in C Q: Implementation? A: Static Chain is ever pointing to the module global frame :04:09 26/48 Lecture3-6E-2014.pdf (26/48)

27 Sectioning and Scope in C: A Case Study/2 Procedures of C may contain non-locals that must be globals of the module Q: How can such a constraint be imposed in C? A: Blocks (included procedures) cannot introduce naming for local procedures What about its implications in: Q: Programming? A: Procedures are not Programming Units, in C Q: Implementation? A: Static Chain is ever pointing to the module global frame Hence: pointer cs can be dropped from AR s of C Hence: pairs [l,p], in the code of C procedures, have l equals to either 0 (for local) or -1 (for global) :04:10 27/48 Lecture3-6E-2014.pdf (27/48)

28 Env: Aliasing Env: It is at the basis of the mechanism of Naming Naming: It allows Use of name instead of Den(otable) Values Sharing of Den(otable) Values, i.e. Aliasing Aliasing = Different Names for the same Den Value Constructs introducing Aliasing are: Parameter Transmission: By Reference Alias: x = alias y (unix Bash) :04:10 28/48 Lecture3-6E-2014.pdf (28/48)

29 Lambda Lifting and Dynamic Scope Dynamic Scope = It may be overcome by using LL LL = Technique for the Elimination of the free variables [i.e. non-local parameters] in (functional) L.P. with Dynamic Scope The non-locals become additional parameters of the procedures Transmission of non-locals is By Reference, or by using Pointers (as in the C example, below) :04:10 29/48 Lecture3-6E-2014.pdf (29/48)

30 Lambda Lifting and Dynamic Scope/2 The C program, on right side, has been obtained by lambda lifting: Hence its procedures do not contain non-locals computes as the program on the left side but according to dynamic scope. Can you give the same but according to static scope? The answer is NO (in C, it cannot be done), but :04:10 30/48 Lecture3-6E-2014.pdf (30/48)

31 Lambda Lifting and Dynamic Scope/3 Can you give the same but according to static scope? The answer is NO (in C, it cannot be done), but it can be done in Ocaml, below :04:10 31/48 Lecture3-6E-2014.pdf (31/48)

32 Closures Closure = Code enclosing its Non-local Bindings Semantic View: pair <code,non-locals bindings> Syntactic View: functions returned as values from functions :04:10 32/48 Lecture3-6E-2014.pdf (32/48)

33 Env: Formalization and Implementation Formalization. Env = Structure defined by the following operations bind: Ide x Den x Env Env abstract view: bind(i,d,e) = λu. if (u=i) then d else e(u) a function concrete view: bind(i,d,e) = (i,d)::e a pair list find: Ide x Env (Den + Ide) abstract view: find(i,e) =e(i) a function application concrete view: find(i,e) = match e with [] i (u,d j )::er if (u=i) then d else find(i,er) empty: () Env abstract view: empty() = λ u. u identity concrete view: empty() = [] empty list Implementation. A frame similar to the one used in AR :04:10 33/48 Lecture3-6E-2014.pdf (33/48)

34 Env: Formalization and Implementation in Summary Formalization. Env = Structure defined by the following operations bind: Ide x Den x Env Env find: Ide x Env (Den + Ide) empty: () Env Implementation is a frame similar to the one used in AR Apictorialrepresentationisbelow :04:10 34/48 Lecture3-6E-2014.pdf (34/48)

35 Store: Formalization and Implementation Formalization. Store = Structure defined by the following operations new: Mem x Store Loc x Store allocation operations are possibly, more than one according to language store features upd: Loc x Mem x Store Store abstract view:... look: Loc x Store Mem abstract view:... Implementation. 3 different main kinds of store: Static: The Standard Store of Machine Languages Stack: The supporting store of block based Programming Languages (with recursive procedures) Dynamic: In almost all today Programming Languages :04:10 35/48 Lecture3-6E-2014.pdf (35/48)

36 Stack: Implementation/1 It is built on a section of (contiguous words of) static memory Pointer Start is pointing to the first word of the section Pointer Top is pointing to the Stack Top, (in case of AR Stack) Pointer Access is pointing to the Access Point of the AR in the top :04:10 36/48 Lecture3-6E-2014.pdf (36/48)

37 Stack: Implementation/2 The role of the Stack for Intermediate Results in a program for JVM :04:10 37/48 Lecture3-6E-2014.pdf (37/48)

38 Heap: Implementation It is built on a section of (contiguous words of) static store Two kinds of Heap: Homogeneous Heap: Blocks of one only size Variable Heap: Blocks of different sizes Allocation may reserve only contiguous blocks :04:10 38/48 Lecture3-6E-2014.pdf (38/48)

39 Heap: Implementation/2 It is built on a section of (contiguous words of) static store Two kinds of Heap: Homogeneous Heap: All blocks have fixed size k (words) Memory is sectioned in blocks of k+1 The additional word is for pointing the next free block Pointer LL is always pointing to the first block that is free for allocation :04:11 39/48 Lecture3-6E-2014.pdf (39/48)

40 Heap: Fragmentation/1 Two kinds of Heap: Homogeneous Heap: All blocks have fixed size k (words) Variable Heap: (see later on) Fragmentation: A problem in Unused Memory Internal Fragmentation: Cannot be avoided External Fragmentation: Of dramatic relevance :04:11 40/48 Lecture3-6E-2014.pdf (40/48)

41 Heap: Fragmentation/2 Two kinds of Heap: Homogeneous Heap: All blocks have fixed size k (words) Variable Heap: (see later on) Fragmentation: A problem in Unused Memory Internal Fragmentation: Cannot be avoided External Fragmentation: Of dramatic relevance in both kind of Heaps :04:11 41/48 Lecture3-6E-2014.pdf (41/48)

42 Heap: Implementation/3 It is built on a section of (contiguous words of) static store Two kinds of Heap: Homogeneous Heap: (see previous slides) Variable Heap: Blocks of different sizes. Two main structures: Single list: e.g. Best Fit allocation Multiple List: Buddy or Fibonacci allocation :04:11 42/48 Lecture3-6E-2014.pdf (42/48)

43 Heap: Implementation/4 (Best Fit) Best Fit allocation: The Free (Single) List is scanned for finding the minimum size free block larger than the section to be allocated Compaction may merge contiguous blocks into one block :04:11 43/48 Lecture3-6E-2014.pdf (43/48)

44 Heap: Implementation/5 (Multiple Lists) Multiple (Homo-)lists: [k 1 ],[k 2 ],...,[k n ] = n homo-lists of different sizes k 1 <k 2 <...<k n Section of size k is allocated in list [k i ]suchthat: k i 1 <k<k i Directly: If [k i ]hasafreeblock Through list [k i+j ]: If [k i+j ]hasafreeblockandk i+j is such that: Let p=i+j-1, then (m1,...,mp) exists: m1*k i +...+mp*k p =k i+j One block B of [k i+j ]isthenbrokenin(m1,m2,...,mp)blocks of the right sizes Lists [k i ],...,[k p ]areextendedwiththenewblocks Allocation of Section of size k then applies Block B is re-built once: m1 blocks of list [k i ],..., mp blocks of list [k p ] are become free. Critical is: The choice of the block size in the lists Buddy: k 1 <k 2 <...<k n are (contiguous) powers of 2 Fibonacci: k 1 <k 2 <...<k n are (contiguous) Fibonacci s numbers :04:11 44/48 Lecture3-6E-2014.pdf (44/48)

45 Heap: Implementation/6 Buddy: k 1 <k 2 <...<k n are (contiguous) powers of 2 Fibonacci: k 1 <k 2 <...<k n are (contiguous) Fibonacci s numbers :04:11 45/48 Lecture3-6E-2014.pdf (45/48)

46 Heap: Compaction - An Exercise/7 Compaction is an Heap operation for allowing that contiguous, free blocks may be allocated at once. In programming languages with pointers as values, the operation is acting on a rearrangement of the free list and in no case, it moves values that are in use, in a block, into a different block. a. Discuss the reasons of it and show an example that illustrates such points. b. Using the example in (a), discuss the problem in Languages which have not pointers as values b. Discuss an algorithm (or write a program) for the re-arrangement of the free list in a homo-heap Answer (a): Moving memory that contains absolute values does not present any problem. In contrast, when the memory contains relocatable values, to move memory it is needed to know (and bring along, the relocation base). Consider the code below and suppose that x is allocated in a block X and Y is allocated in a block Y.... x = malloc(k*sizeof(int)); y = malloc(k*sizeof(int)); z = x > y?x:y;... What is the value of z if X and Y are relocated immediately after the assignment of z? Can You say that the relocation of X and Y is not affecting the behavior of the program? :04:11 46/48 Lecture3-6E-2014.pdf (46/48)

47 Comparison Table Environment and Memory in: Fortran, C, Pascal, Caml, Java, Prolog :04:11 47/48 Lecture3-6E-2014.pdf (47/48)

48 Things To Do STUDY in deeper way, the content of the slides. You can read in addition, the chapters 4 and 5 of the book by Gabrielli and Martini before mentioned, and use the bibliographic references in the chapter for additional readings. PROGRAMMING check the installation of the tools for the use of following languages: C, Java, Caml, Prolog (Use the first 3 in giving a program for the computation of factorial) EXERCISES: verify, complete and extend all the examples and/or exercises included in the slides by using the right tools (programs and languages) consider the exercises included in the chapters 4 and 5 of the book by Gabrielli and Martini :04:11 48/48 Lecture3-6E-2014.pdf (48/48)

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter

More information

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming Closures Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming Summary 1. Predictive Parsing 2. Large Step Operational Semantics (Natural) 3. Small Step Operational Semantics

More information

Programmiersprachen (Programming Languages)

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

More information

Functional Programming. Pure Functional Programming

Functional Programming. Pure Functional Programming Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).

More information

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

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University G22.2110-001 Programming Languages Spring 2010 Lecture 4 Robert Grimm, New York University 1 Review Last week Control Structures Selection Loops 2 Outline Subprograms Calling Sequences Parameter Passing

More information

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming Closures Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming t ::= x x. t t t Call-by-value big-step Operational Semantics terms variable v ::= values abstraction x.

More information

Weeks 6&7: Procedures and Parameter Passing

Weeks 6&7: Procedures and Parameter Passing CS320 Principles of Programming Languages Weeks 6&7: Procedures and Parameter Passing Jingke Li Portland State University Fall 2017 PSU CS320 Fall 17 Weeks 6&7: Procedures and Parameter Passing 1 / 45

More information

Programming Languages

Programming Languages Programming Languages Tevfik Koşar Lecture - VIII February 9 th, 2006 1 Roadmap Allocation techniques Static Allocation Stack-based Allocation Heap-based Allocation Scope Rules Static Scopes Dynamic Scopes

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

CSE 307: Principles of Programming Languages

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

More information

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments Programming Languages Third Edition Chapter 10 Control II Procedures and Environments Objectives Understand the nature of procedure definition and activation Understand procedure semantics Learn parameter-passing

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

NOTE: Answer ANY FOUR of the following 6 sections:

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

More information

CS 314 Principles of Programming Languages. Lecture 13

CS 314 Principles of Programming Languages. Lecture 13 CS 314 Principles of Programming Languages Lecture 13 Zheng Zhang Department of Computer Science Rutgers University Wednesday 19 th October, 2016 Zheng Zhang 1 CS@Rutgers University Class Information Reminder:

More information

CS558 Programming Languages

CS558 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 information

Today's Topics. CISC 458 Winter J.R. Cordy

Today's Topics. CISC 458 Winter J.R. Cordy Today's Topics Last Time Semantics - the meaning of program structures Stack model of expression evaluation, the Expression Stack (ES) Stack model of automatic storage, the Run Stack (RS) Today Managing

More information

Programming Languages Third Edition. Chapter 7 Basic Semantics

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

More information

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004 Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004 CS 314, LS,BR,LTM: Scope and Memory 1 Review Functions as first-class objects What can you do with an integer?

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages CS 314 Principles of Programming Languages Lecture 15: Review and Functional Programming Zheng (Eddy) Zhang Rutgers University March 19, 2018 Class Information Midterm exam forum open in Sakai. HW4 and

More information

Chapter 13: Reference. Why reference Typing Evaluation Store Typings Safety Notes

Chapter 13: Reference. Why reference Typing Evaluation Store Typings Safety Notes Chapter 13: Reference Why reference Typing Evaluation Store Typings Safety Notes References Computational Effects Also known as side effects. A function or expression is said to have a side effect if,

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 4a Andrew Tolmach Portland State University 1994-2017 Semantics and Erroneous Programs Important part of language specification is distinguishing valid from

More information

Functional Programming and Haskell

Functional Programming and Haskell Functional Programming and Haskell Tim Dawborn University of Sydney, Australia School of Information Technologies Tim Dawborn Functional Programming and Haskell 1/22 What are Programming Paradigms? A programming

More information

CS558 Programming Languages. Winter 2013 Lecture 3

CS558 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 information

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

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

More information

Concepts Introduced in Chapter 7

Concepts Introduced in Chapter 7 Concepts Introduced in Chapter 7 Storage Allocation Strategies Static Stack Heap Activation Records Access to Nonlocal Names Access links followed by Fig. 7.1 EECS 665 Compiler Construction 1 Activation

More information

Chapter 5. Names, Bindings, and Scopes

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

More information

Scope, Functions, and Storage Management

Scope, Functions, and Storage Management Scope, Functions, and Storage Management Implementing Functions and Blocks cs3723 1 Simplified Machine Model (Compare To List Abstract Machine) Registers Code Data Program Counter (current instruction)

More information

Implementing Subprograms

Implementing Subprograms 1 Implementing Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University CS315 Programming Languages Pinar Duygulu The General Semantics of Calls and Returns 2 The subprogram call and return

More information

Informal 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 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 information

names names identifiers variables subroutines constants

names names identifiers variables subroutines constants names (source: Louden, "Programming Languages, Principles and Practices", 2nd Edition, Ch. 5, pp. 125-134)!p. 126: "A fundamental abstraction mechanism in a programming language is the use of names, or

More information

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. 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 information

Static 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 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 information

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA. R13 SET - 1 III B. Tech I Semester Regular Examinations, November - 2015 1 a) What constitutes a programming environment? [3M] b) What mixed-mode assignments are allowed in C and Java? [4M] c) What is

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

CS558 Programming Languages

CS558 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 information

Separate compilation. Topic 6: Runtime Environments p.1/21. CS 526 Topic 6: Runtime Environments The linkage convention

Separate compilation. Topic 6: Runtime Environments p.1/21. CS 526 Topic 6: Runtime Environments The linkage convention Runtime Environment The Procedure Abstraction and Separate Compilation Topics we will cover The procedure abstraction and linkage conventions Runtime storage convention Non-local data access (brief) These

More information

Reasoning About Imperative Programs. COS 441 Slides 10

Reasoning About Imperative Programs. COS 441 Slides 10 Reasoning About Imperative Programs COS 441 Slides 10 The last few weeks Agenda reasoning about functional programming It s very simple and very uniform: substitution of equal expressions for equal expressions

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques () Lecture 13 February 12, 2018 Mutable State & Abstract Stack Machine Chapters 14 &15 Homework 4 Announcements due on February 20. Out this morning Midterm results

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

Test 1 Summer 2014 Multiple Choice. Write your answer to the LEFT of each problem. 5 points each 1. Preprocessor macros are associated with: A. C B.

Test 1 Summer 2014 Multiple Choice. Write your answer to the LEFT of each problem. 5 points each 1. Preprocessor macros are associated with: A. C B. CSE 3302 Test 1 1. Preprocessor macros are associated with: A. C B. Java C. JavaScript D. Pascal 2. (define x (lambda (y z) (+ y z))) is an example of: A. Applying an anonymous function B. Defining a function

More information

Chapter 5 Names, Binding, Type Checking and Scopes

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

More information

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) CSE 413 Languages & Implementation Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) 1 Goals Representing programs as data Racket structs as a better way to represent

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

Compilers. 8. Run-time Support. Laszlo Böszörmenyi Compilers Run-time - 1

Compilers. 8. Run-time Support. Laszlo Böszörmenyi Compilers Run-time - 1 Compilers 8. Run-time Support Laszlo Böszörmenyi Compilers Run-time - 1 Run-Time Environment A compiler needs an abstract model of the runtime environment of the compiled code It must generate code for

More information

CS 415 Midterm Exam Spring 2002

CS 415 Midterm Exam Spring 2002 CS 415 Midterm Exam Spring 2002 Name KEY Email Address Student ID # Pledge: This exam is closed note, closed book. Good Luck! Score Fortran Algol 60 Compilation Names, Bindings, Scope Functional Programming

More information

The basic operations defined on a symbol table include: free to remove all entries and free the storage of a symbol table

The basic operations defined on a symbol table include: free to remove all entries and free the storage of a symbol table SYMBOL TABLE: 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 associated with information relating

More information

G Programming Languages - Fall 2012

G 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 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

Attributes, Bindings, and Semantic Functions Declarations, Blocks, Scope, and the Symbol Table Name Resolution and Overloading Allocation, Lifetimes,

Attributes, 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 information

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018 CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2018 Typical workflow concrete syntax (string) "(fn x => x + x) 4" Parsing Possible errors / warnings

More information

Run-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13

Run-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13 Run-time Environments Lecture 13 by Prof. Vijay Ganesh) Lecture 13 1 What have we covered so far? We have covered the front-end phases Lexical analysis (Lexer, regular expressions,...) Parsing (CFG, Top-down,

More information

Names, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University

Names, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University Names, Scopes, and Bindings CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Names, Scopes, and Bindings Names are identifiers (mnemonic character

More information

Names, Bindings, Scopes

Names, Bindings, Scopes Names, Bindings, Scopes Variables In imperative l Language: abstractions of von Neumann machine Variables: abstraction of memory cell or cells Sometimes close to machine (e.g., integers), sometimes not

More information

INF 212 ANALYSIS OF PROG. LANGS ELEMENTS OF IMPERATIVE PROGRAMMING STYLE. Instructors: Crista Lopes Copyright Instructors.

INF 212 ANALYSIS OF PROG. LANGS ELEMENTS OF IMPERATIVE PROGRAMMING STYLE. Instructors: Crista Lopes Copyright Instructors. INF 212 ANALYSIS OF PROG. LANGS ELEMENTS OF IMPERATIVE PROGRAMMING STYLE Instructors: Crista Lopes Copyright Instructors. Objectives Level up on things that you may already know Machine model of imperative

More information

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

More information

CSC 533: Organization of Programming Languages. Spring 2005

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

More information

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8 Subroutines and Control Abstraction Textbook, Chapter 8 1 Subroutines and Control Abstraction Mechanisms for process abstraction Single entry (except FORTRAN, PL/I) Caller is suspended Control returns

More information

Special Topics: Programming Languages

Special 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 information

Names, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University

Names, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University Names, Scopes, and Bindings CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Names, Scopes, and Bindings Names are identifiers (mnemonic character

More information

The role of semantic analysis in a compiler

The role of semantic analysis in a compiler Semantic Analysis Outline The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

More information

Programming Languages: Lecture 12

Programming Languages: Lecture 12 1 Programming Languages: Lecture 12 Chapter 10: Implementing Subprograms Jinwoo Kim jwkim@jjay.cuny.edu Chapter 10 Topics 2 The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing

More information

Announcements. Scope, Function Calls and Storage Management. Block Structured Languages. Topics. Examples. Simplified Machine Model.

Announcements. Scope, Function Calls and Storage Management. Block Structured Languages. Topics. Examples. Simplified Machine Model. CS 242 2007 Scope, Function Calls and Storage Management John Mitchell Announcements Homework Returned in class Wed; afterwards in 4 th Floor Gates Cabinet SCPD students: attach routing slip, will be returned

More information

Run-time Environments - 2

Run-time Environments - 2 Run-time Environments - 2 Y.N. Srikant Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler Design Outline of the Lecture n What is run-time

More information

CMSC 330: Organization of Programming Languages

CMSC 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 information

CS 242. Fundamentals. Reading: See last slide

CS 242. Fundamentals. Reading: See last slide CS 242 Fundamentals Reading: See last slide Syntax and Semantics of Programs Syntax The symbols used to write a program Semantics The actions that occur when a program is executed Programming language

More information

COMP 524 Spring 2018 Midterm Thursday, March 1

COMP 524 Spring 2018 Midterm Thursday, March 1 Name PID COMP 524 Spring 2018 Midterm Thursday, March 1 This exam is open note, open book and open computer. It is not open people. You are to submit this exam through gradescope. Resubmissions have been

More information

Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008.

Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008. Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008. Outline. Abstractions for telling a computer how to do things. Computational Paradigms. Language Definition, Translation.

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages CS 314 Principles of Programming Languages Lecture 13: Names, Scopes and Bindings Zheng (Eddy) Zhang Rutgers University February 28, 2018 Review: Names, Scopes and Binding What s in a name? Each name means

More information

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

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

More information

Programming Languages, Summary CSC419; Odelia Schwartz

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

More information

G Programming Languages - Fall 2012

G 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 information

Intermediate Representations & Symbol Tables

Intermediate Representations & Symbol Tables Intermediate Representations & Symbol Tables Copyright 2014, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California have explicit permission

More information

Compiler Construction

Compiler Construction Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-17/cc/ Generation of Intermediate Code Outline of Lecture 15 Generation

More information

LECTURE 18. Control Flow

LECTURE 18. Control Flow LECTURE 18 Control Flow CONTROL FLOW Sequencing: the execution of statements and evaluation of expressions is usually in the order in which they appear in a program text. Selection (or alternation): a

More information

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson 6.184 Lecture 4 Interpretation Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson 1 Interpretation Parts of an interpreter Arithmetic calculator

More information

Lecture 15 CIS 341: COMPILERS

Lecture 15 CIS 341: COMPILERS Lecture 15 CIS 341: COMPILERS Announcements HW4: OAT v. 1.0 Parsing & basic code generation Due: March 28 th No lecture on Thursday, March 22 Dr. Z will be away Zdancewic CIS 341: Compilers 2 Adding Integers

More information

Control in Sequential Languages

Control in Sequential Languages CS 242 2012 Control in Sequential Languages Reading: Chapter 8, Sections 8.1 8.3 (only) Section 7.3 of The Haskell 98 Report, Exception Handling in the I/O Monad, http://www.haskell.org/onlinelibrary/io-13.html

More information

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

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

More information

Administration CS 412/413. Advanced Language Support. First-class vs. Second-class. First-class functions. Function Types

Administration CS 412/413. Advanced Language Support. First-class vs. Second-class. First-class functions. Function Types Administration CS 412/413 Introduction to Compilers and Translators Andrew Myers Cornell University Lecture 33: First-class functions 21 April 00 Programming Assignment 6 handed out today register allocation

More information

CS422 - Programming Language Design

CS422 - Programming Language Design 1 CS422 - Programming Language Design Elements of Functional Programming Grigore Roşu Department of Computer Science University of Illinois at Urbana-Champaign 2 The two languages that we defined so far

More information

Run-Time Environments

Run-Time Environments CS308 Run-Time Environments Li Jiang Department of Computer Science and Engineering Shanghai Jiao Tong University Current Progress Source Language Lexical Analyzer Syntax Analyzer Semantic Analyzer Intermediate

More information

Functions - Lecture 7. Nested functions. Another example. A Nested Function. Josef Svenningsson

Functions - Lecture 7. Nested functions. Another example. A Nested Function. Josef Svenningsson Functions - Lecture 7 Josef Svenningsson Nested functions A Nested Function Suppose we extended Javalette with nested functions. double hypsq(double a, double b) { double square(double d) { return d *

More information

Programmin Languages/Variables and Storage

Programmin Languages/Variables and Storage Programmin Languages/Variables and Storage Onur Tolga Şehitoğlu Computer Engineering 4 Mart 2007 Outline 1 Storage Array Variables 2 Semantics of Assignment 3 Variable Lifetime Global Lifetime Local Lifetime

More information

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered

More information

CS 415 Midterm Exam Spring SOLUTION

CS 415 Midterm Exam Spring SOLUTION CS 415 Midterm Exam Spring 2005 - SOLUTION Name Email Address Student ID # Pledge: This exam is closed note, closed book. Questions will be graded on quality of answer. Please supply the best answer you

More information

Lecture08: Scope and Lexical Address

Lecture08: Scope and Lexical Address Lecture08: Scope and Lexical Address Free and Bound Variables (EOPL 1.3.1) Given an expression E, does a particular variable reference x appear free or bound in that expression? Definition: A variable

More information

Compiler Construction

Compiler Construction Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ws-1819/cc/ Generation of Intermediate Code Outline of Lecture 15

More information

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures Dan Grossman Fall 2014 Hi! I m not Hal J I love this stuff and have taught

More information

6. Names, Scopes, and Bindings

6. Names, Scopes, and Bindings Copyright (C) R.A. van Engelen, FSU Department of Computer Science, 2000-2004 6. Names, Scopes, and Bindings Overview Names Binding time Object lifetime Object storage management Static allocation Stack

More information

5. Semantic Analysis!

5. Semantic Analysis! 5. Semantic Analysis! Prof. O. Nierstrasz! Thanks to Jens Palsberg and Tony Hosking for their kind permission to reuse and adapt the CS132 and CS502 lecture notes.! http://www.cs.ucla.edu/~palsberg/! http://www.cs.purdue.edu/homes/hosking/!

More information

CS4215 Programming Language Implementation. Martin Henz

CS4215 Programming Language Implementation. Martin Henz CS4215 Programming Language Implementation Martin Henz Thursday 15 March, 2012 2 Chapter 11 impl: A Simple Imperative Language 11.1 Introduction So far, we considered only languages, in which an identifier

More information

5. Semantic Analysis. Mircea Lungu Oscar Nierstrasz

5. Semantic Analysis. Mircea Lungu Oscar Nierstrasz 5. Semantic Analysis Mircea Lungu Oscar Nierstrasz Thanks to Jens Palsberg and Tony Hosking for their kind permission to reuse and adapt the CS132 and CS502 lecture notes. http://www.cs.ucla.edu/~palsberg/

More information

The Environment Model. Nate Foster Spring 2018

The Environment Model. Nate Foster Spring 2018 The Environment Model Nate Foster Spring 2018 Review Previously in 3110: Interpreters: ASTs, evaluation, parsing Formal syntax: BNF Formal semantics: dynamic: small-step substitution model static semantics

More information

Chapter 13: Reference. Why reference Typing Evaluation Store Typings Safety Notes

Chapter 13: Reference. Why reference Typing Evaluation Store Typings Safety Notes Chapter 13: Reference Why reference Typing Evaluation Store Typings Safety Notes References Mutability So far, what we discussed does not include computational effects (also known as side effects). In

More information

n Closed book n You are allowed 5 cheat pages n Practice problems available in Course Materials n Check grades in Rainbow grades

n Closed book n You are allowed 5 cheat pages n Practice problems available in Course Materials n Check grades in Rainbow grades Announcements Announcements n HW12: Transaction server n Due today at 2pm n You can use up to 2 late days, as always n Final Exam, December 17, 3-6pm, in DCC 308 and 318 n Closed book n You are allowed

More information

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

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

More information

Compiler Construction

Compiler Construction Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-17/cc/ Generation of Intermediate Code Conceptual Structure of

More information

Outline. Programming Languages 1/16/18 PROGRAMMING LANGUAGE FOUNDATIONS AND HISTORY. Current

Outline. Programming Languages 1/16/18 PROGRAMMING LANGUAGE FOUNDATIONS AND HISTORY. Current PROGRAMMING LANGUAGE FOUNDATIONS AND HISTORY Dr. John Georgas, Northern Arizona University Copyright John Georgas All Rights Reserved Outline Current Programming languages Compiled and interpreted implementations

More information

Chapter 10. Implementing Subprograms ISBN

Chapter 10. Implementing Subprograms ISBN Chapter 10 Implementing Subprograms ISBN 0-321-33025-0 Chapter 10 Topics The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing Subprograms with Stack-Dynamic Local Variables

More information

CSE 3302 Notes 5: Memory Management

CSE 3302 Notes 5: Memory Management CSE 0 Notes 5: Memory Management (Last updated 10/7/15 1:6 PM) References: Gabbrielli-Martini: 5 Wirth: 4 5.1. IMPLEMENTING SIMPLE SUBPROGRAMS Historical FORTRAN and COBOL Simple = no recursion static

More information