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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 05/06/2011.

Page1 / 7

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

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

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