L8Proc - Procedures cs784(Prasad) L8Proc 1 Primitive...

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

View Full Document Right Arrow Icon
cs784(Prasad) L8Proc 1 Procedures
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) L8Proc 2 Primitive procedures +, -, , etc User-defined procedures Naming a sequence of operations triple  =  proc  (x) +(x,+(x,x)) Recursive definitions   exp   =   (x, i)                  if  (i = 0)   then   1              else  
Background image of page 2
cs784(Prasad) L8Proc 3 User-defined procedures Concrete Syntax <expression> ::= … |  <expression> +  )    proc  <idlist> <expression>  <idlist>  ::=  ()    (  <identifier>  { ,  <identifier>}*  ) Abstract Syntax proc-exp (ids body) app-exp  (rator rands) Examples proc (y,z) * (y,5) (f x 5)
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) L8Proc 4 proc main(); int x := 5;      proc q();       {  x  + 1;}             proc r();      { int x := 0;              q();      } { r();       print( x ); }. Scoping : Free (non-local) Variables Static scoping x  ->  x output : 6 Dynamic scoping x   ->  x output : 5
Background image of page 4
cs784(Prasad) L8Proc 5 let                 )             +   (f) Static Scoping x  ->  x 30 Dynamic Scoping x  ->  x 23 x  ->  x
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) L8Proc 6 Informal Semantics of Procedures Procedure Definition Store formal parameters and body Procedure Invocation Evaluate body in an environment that binds formals to actual argument values Interpretation of free -variables Use env. at proc. creation ( static scoping ) Use env. at proc. call ( dynamic scoping )
Background image of page 6
cs784(Prasad) L8Proc 7
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
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 / 17

L8Proc - Procedures cs784(Prasad) L8Proc 1 Primitive...

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

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