Java Reference
In-Depth Information
1 Start
Stmt ast $
return ( ast )
2 Stmt result
L target assign R source
result ← make
F
amily
( assign
, target , source )
3 L result
id name
result ← make
N
ode
( name )
4
|
deref R val
result val
25
5 R result
L val
result ← make
F
amily
( deref
, val )
26
6
|
num val
result ← make
N
ode
( val )
7
|
addr L val
result val
27
Figure 7.21: Semantic actions to create ASTs for the grammar in
Figure 7.20.
clear: an L-value appears only as the left child of an assignment operator; all
other uses of identifiers refer to their R-values.
Di
cult for languages
like C that contain explicit syntax for treating R-values as L-values and vica
versa:
ff
erentiating left and right values can be more di
p =
, p would be treated as an L-value, and the assignment
would set p to 0. With the
0 Without the
, p is treated as an R-value, and the value
stored at p becomes an L-value. Thus, the assignment stores 0 where p
points.
x =
& p Without the & , p would be treated as an R-value, and the assignment
would copy the value from p to x .W ththe&, p is treated as an L-
value, and the resulting address is then treated as an R-value. Thus, the
assignment sets x to the address of p .
Given the location of an identifier, we can always find the value stored there
by indirection; but we cannot find an identifier's location from its value. For
our AST representation of names, we will therefore always regard an identifier
as representing that name's location. Explicit deref nodes will be placed in the
AST to show exactly where indirection (dereferencing) occurs to obtain the
value of a name from its location.
Search WWH ::




Custom Search