{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

4expression-eval

# 4expression-eval - Other Issues Concerning Structured Flow...

This preview shows pages 1–3. Sign up to view the full content.

CSci 5106: Programming Languages Implementing Expression Evaluation Gopalan Nadathur Department of Computer Science and Engineering University of Minnesota Lectures in Fall 2010 Gopalan Nadathur Structured Flow Constructs Other Issues Concerning Structured Flow Constructs Here are some of the other questions that are of interest concerning the structured flow language: What is the concrete syntax of the constructs? Language dependent, can be found in the manuals What is the meaning of the constructs at an informal level? Given by flow charts already at the level where we can use it to reason about programs? Will consider this through axiomatic semantics How might these constructs be implemented? Here the essential issue turns out to be the treatment of expressions Gopalan Nadathur Structured Flow Constructs Assignment Statement The syntax in C: E 1 = E 2 , where E 1 and E 2 are expressions Restriction on the Expressions E 1 must yield the name of a cell; will assume a simple variable or indexed access For E 2 we will assume simple arithmetic and boolean expressions An Important Issue Concerning Meaning Cells, determined by names or computed addresses, are treated differently on the right and left side of assignment In particular, on the right we get a value from a cell, on the left we use the address of the cell This distinction leads to the terminology l-value and r-value In C, assignment also yields a value Gopalan Nadathur Structured Flow Constructs Implementing Assignment Statements The only real issue is expression evaluation In an assignment statement of the form A = E once we know how to evaluate A and E, the rest is easy In considering the evaluation of expressions, we will work from abstract syntax Gopalan Nadathur Structured Flow Constructs

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

View Full Document
Evaluating Expressions (Interpretive Form) We assume (initially) that the expressions are all of the name , number or op(E1,E2) Then the evaluation scheme can be described as follows: if the expression is a number , then return the number if it is a name , look it up in the environment if it is of the form op(E1,E2) then evaluate E1 and E2 using the same process lookup the procedure corresponding to op apply the procedure to the values found for E1 and E2 Note that expression evaluation is taking place relative to an environment Note also that looking up is relevant both to names and to operators We are implicitly assuming eager evaluation here; can be done differently too Gopalan Nadathur Structured Flow Constructs A Recursive Evaluator for Expressions We can (almost) write this as a Scheme or ML function eval(Exp,Env) = if Exp is a name then return lookup(Exp,Env) else if Exp is a constant then return Exp else let Exp be of the form op(E1,E2) V1 = eval(E1,Env) V2 = eval(E2,Env) actualop = lookup(op,Env) in return actualop(V1,V2) It would be interesting to write this program as an exercise If you try it, experiment also with more interesting evaluation strategies and different kinds of operators Gopalan Nadathur Structured Flow Constructs
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

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