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

• 30

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 ...
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
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.
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
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
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.”
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, …
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, ….
What is a functional language ?

#### You've reached the end of your free preview.

Want to read all 30 pages?

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern