L123Assg - Assignments cs784(Prasad) L123Assg 1 l-value vs....

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
cs784(Prasad) L123Assg 1 Assignments
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs784(Prasad) L123Assg 2 l-value vs . r-value Pascal/Ada: x := x + 1 C/Java: x = x + 1 l-value = location, address, reference, … r-value = int, real, (sometimes even) address, … Environment binds an identifier to a location. env : ids - locations Store binds a location to a value. store : locations - values assign-op : location x value x store - store
Background image of page 2
cs784(Prasad) L123Assg 3 Sharing Sharing For functional subset, it is sufficient to model env as a function from ids to values . For imperative programming that has both assignment and sharing, separating and store is necessary. E.g., sharing/aliasing Point p =    new Point();         Point q = p; E.g., call by reference void f(Point p){};            f(q);
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs784(Prasad) L123Assg 4 Side-effect causing Scheme primitives Initialize variable: (define <var>  <exp>) Update variable: (set!   <var>  <exp>) Other ops:     display, write,  set-car!, set-cdr!,. .. (set! x y) denotes location denotes value Sequencing:      (begin   <exp1> <exp2> … <expn>)
Background image of page 4
cs784(Prasad) L123Assg 5 Extending object ( not meta-) language and the interpreter to support variable assignment
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs784(Prasad) L123Assg 6 Modifying environment and the interpreter An identifier denotes the address of a mutable data structure that holds a value (that is, it models a memory location). This address is called a reference , and the contents of these references are modified by a variable assignment. Variable reference   ( var-exp (id)            (deref (apply-env-ref env var)) )
Background image of page 6
cs784(Prasad) L123Assg 7 Introduction of variable assignment Syntax    <expression> ::=     set  <identifier> = <expression> Abstract Syntax varassign-exp (id rhs-exp) Semantics    ( varassign-exp (var exp)         (apply-env-ref env id)                    (eval-expression rhs-exp    env) )  )     l-value                   r-value
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs784(Prasad) L123Assg 8 Simulating letrec using let and assignment (   ((var1 exp1) (var2 exp2))              exp )      (* exp1 and exp2 are lambda -forms *) (   ((var1 ’*) (var2 ’*))             ( set!  var1  exp1)             (  var2  exp2)                    )
Background image of page 8
cs784(Prasad) L123Assg 9 Simulating Objects and Classes
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs784(Prasad) L123Assg 10 Defining a stack object   (define empty?  ' ())         (define push!   ' ())       (define  pop!   ' ())         (define  top    ' ())  (let  ( ( stk stk  ' ()) )      (set! empty? (lambda() (null?  stk stk)))      (set! push! (lambda(x)                       (set!  stk stk (cons x  stk
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/02/2011 for the course CS cs784 taught by Professor Tkprasad during the Spring '11 term at New York Institute of Technology-Westbury.

Page1 / 31

L123Assg - Assignments cs784(Prasad) L123Assg 1 l-value vs....

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online