Programming Languages (CSC-302 98S)
Outline of Class 13: Expressions, Variables, and Assignments
Held: Monday, February 16, 1998
- I'm doing a horrible job of emailing out the end-of-class questions, so
we won't go over the most recent one.
- Don't forget today's brown-bag lunch; it looks to be interesting
(it's on Multimedia on the Ethernet, or some such).
- I've heard some concerns about the length of
assignment three and
would be happy to discuss those concerns.
- There seems to be some question as to when compilers will be offered
next year. As far as I can tell, there's little doubt that it will
be offered in the fall. If you'll be away in the fall, you may want
to chat with me about a guided reading for next Spring.
- Through our past discussions, we've often made reference to the
concept of a variable.
- How might we define "variable"? Is a variable most like a
- Storage location
- Named value
- Function parameter
- Something else ...
- In most imperative languages, a variables is a container in which
we can store values.
- Different languages allow us to store different kinds of values in
containers. What are the different kinds of values?
- Values with primitive types.
- Values with compound types.
- Locations of other containers (i.e., pointers).
- Functions or locations of functions.
- How do we store values in containers?
- With assignment statements.
- For parameters (which are pretty much like variables), with function
- In many languages, there is some conflict/confusion between the name of
a container and the contents of the container.
- For example, if you've stored the value 3 in the container named X,
what does it mean when you see "X"? Does it mean "the container" or
"the value". It often depends on the
- If the name appears as something to be assigned to, it typically
means "the container". Most typically, this is when it appears
on the left-hand-side of an assignment.
- If the name appears as a value to be assigned, it typically means
"the value". Typically, this happens when the variable appears
on the right-hand-side of an assignment.
- To help clarify matters, language researchers often refer to the
l-value (container) and r-value (contents) of
- This makes it easier to describe assignment. For example, if
X and Y are integer variables, "X gets Y" means "Store the
r-value of Y in the container corresponding to the l-value of X".
- However, our choice of whether to use l- or r-values may depend on
the types of X and Y. What if each is
- A container for basic values.
- A container for references to containers for basic values.
- A container for references to containers for rereferences to basic
- Yes, there are languages that let you be that specific about
- If we don't know the types of X and Y in "X gets Y", what are some
- Place the r-value of Y in the container given by the l-value of X.
- Place the l-value of Y in the container given by the l-value of X.
- Place the r-value of Y in the container given by the r-value of X?
- Note also that different names are used differently. For example,
constants are also named, but you usually don't want to give programmers
access to l-values of constants.