Java Reference
In-Depth Information
1 Start
Stmt $
2 Stmt
L assign R
3 L
id
4
|
deref R
5 R
L
6
|
num
7
|
addr L
Figure 7.20: Grammar for left and right values.
7.6 AST Structures for Left and Right Values
When an identifier is used in a programming language, it typicallymeans one of
the following: the value associated with the name, or the the location (address)
at which a value is stored. Programming language definitions specify when
an identifier means its value or its location—most often, the meaning depends
on the context in which the identifier is used. For example, the assignment
statement
x = y
references two identifiers, but their location on either side of the assignment
operator significantly changes their meaning:
x = y The identifier y refers to the value of y . Such usage is commonly called a
right value (R-value), from its appearance to the right of the assignment
operator.
Some programming language elements have only right-value forms. A
constant's value can be referenced, but the location of a constant is typ-
ically beyond reference, and languages prohibit changing a constant's
value. An object's self reference (this) is typically available only in
right-value form.
x = y The identifier x refers to the location of x , not its value. Such usage is
called the left value (L-value) of x from its appearance to the left of the
assignment operator.
Some languages provide a mechanism by which any R-value can be
treated as an L-value using a dereference operator. For example, the ex-
pression
e in C allows the R-value of e to serve as an L-value. Other
languages (e.g., Java) carefully limit L-values so as to reduce the possi-
bility of changing storage unintentionally.
For the language defined in Figure 7.14, and in the ASTs generated from that
grammar, the meaning of an identifier in terms of its R-value or L-value is
 
 
Search WWH ::




Custom Search