lvalues and rvalues
Wait a minute...lvalue column? What's an lvalue? The term lvalue is an old assembly language term that refers to the "location value" of a data item in memory. In other words, an lvalue is the starting memory address of a data item. In the example, variable n had an lvalue of 80,000 because that's where it is located in memory.
Whenever there is an lvalue, there is also an rvalue. The rvalue of a variable is what is actually stored at the variable's memory address (that is, its lvalue). Back in the Dark Ages when assembly language was widely used, it was a common task for programmers to directly manipulate the memory address of a variable and move the appropriate number of bytes into a CPU register. The location value (lvalue) was where you stored the variable in memory and the "register value" (rvalue) was what actually was stored at that memory address. Figure 1 shows how lvalues and rvalues relate to each other after the Dim statement is processed.
In Figure 1, the lvalue is shown as the left leg of the diagram and shows where n is stored in memory80,000 in the example. The right leg of the diagram represents the rvalue and has a value of 0. (The reason why rvalue is 0 is because VBN initializes newly defined numeric data items to 0.)
If you think of variable n as a bucket capable of holding exactly eight bytes, the lvalue tells you where to find the bucket, and the rvalue tells you what is in the bucket. (The diagram also helps explain why some people refer to the lvalue as the "left value" and the rvalue as the "right value".) The Data Type column in the symbol table tells you how big the bucket is.
As I said earlier, it is the presence of an lvalue in the symbol table that determines whether a variable has been defined. This is true for all languagesbe it VBN, C++, C#, Java, or whatever language you wish to mention. As we shall see, it is possible to have data attributes for a variable in the symbol table, but if the lvalue column is empty, it is not a defined variable. If the lvalue is missing for a data item, the host operating system has not provided storage for the data item. This means that the row of attributes in the symbol table simply provides a type description of a data item. Therefore, a symbol table entry that does not have an lvalue must be a data declaration, not a data definition. Always remember that a data declaration is a series of attributes in the symbol table that describe a data item, but for which no storage has yet been allocated.
Figure 1 The lvalue and rvalue for n.
Now return to the next program statement in Listings 1 and 2:
n = 10
In processing the statement, VBN searches for n in the symbol table, looks at its lvalue (that is, 80,000), and takes the numeric value 10 and moves that value to its memory location. Figure 1 would now show the rvalue to be 10 instead of 0.