E e 1 e 2 E e 1 E e 2 Obvious but different from compiler evaluation using

E e 1 e 2 e e 1 e e 2 obvious but different from

This preview shows page 8 - 17 out of 30 pages.

E [[ e 1 +e 2 ]] = E [[ e 1 ]] + E [[ e 2 ]] Obvious, but different from compiler evaluation using registers, etc. This is a simple machine-independent characterization ...
Image of page 8
Second Example: Expressions w/vars Syntax d ::= 0 | 1 | 2 | … | 9 n ::= d | nd e ::= x | n | e + e Semantics value E : exp x state -> numbers state s : vars -> numbers E [[ x ]] s = s(x) E [[ 0 ]] s = 0 E [[ 1 ]] s = 1 E [[ nd ]] s = 10* E [[ n ]] s + E [[ d ]] s E [[ e 1 + e 2 ]] s = E [[ e 1 ]] s + E [[ e 2 ]] s
Image of page 9
Semantics of Imperative Programs Syntax P ::= x:=e | if B then P else P | P;P | while B do P Semantics C : Programs (State State) State = Variables Values would be locations values if we wanted to model aliasing Every imperative program can be translated into a functional program in a relatively simple, syntax-directed way.
Image of page 10
Semantics of Assignment C[[ x:= e ]] is a function states states C[[ x:= e ]] s = s’ where s’ : variables values is identical to s except s’(x) = E [[ e ]] s gives the value of e in state s
Image of page 11
Semantics of Conditional C[[ if B then P else Q ]] is a function states states C[[ if B then P else Q ]] s = C[[ P ]] s if E [[ B ]] s is true C[[ Q ]] s if E [[ B ]] s is false Simplification: assume B cannot diverge or have side effects
Image of page 12
Semantics of Iteration C[[ while B do P ]] is a function states states C[[ while B do P ]] = the function f such that f(s) = s if E [[ B ]] s is false f(s) = f( C[[ P ]](s) ) if E [[ B ]] s is true Mathematics of denotational semantics: prove that there is such a function and that it is uniquely determined. “Beyond scope of this course.”
Image of page 13
Perspective Denotational semantics Assign mathematical meanings to programs in a structured, principled way Imperative programs define mathematical functions Can write semantics using lambda calculus, extended with operators like modify : (state var value) state Impact Influential theory Applications via abstract interpretation, type theory, …
Image of page 14
Functional vs Imperative Programs Denotational semantics shows Every imperative program can be written as a functional program, using a data structure to represent machine states This is a theoretical result I guess “theoretical” means “it’s really true” (?) What are the practical implications? Can we use functional programming languages for practical applications? Compilers, graphical user interfaces, network routers, ….
Image of page 15
What is a functional language ?
Image of page 16
Image of page 17

You've reached the end of your free preview.

Want to read all 30 pages?

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors