CSC447

Concepts of Programming Languages

L-Values

Instructor: James Riely

Variables

  • Given declarations such as:
    
    int x = 0;
                  
    
    var x:Int = 0
                  
    
    (define x 0)
                  
  • What does x mean in?
    
    x = x + 1;
                  
    
    (set! x (+ x 1))
                  

R-Mode and L-Mode

L-Values

  • Expression for which l-mode evaluation succeeds
  • Effectively, has an address
  • In C, take the address of l-values
    
    int x = 5;
    int y = 6;
    int *p = &x;
    int *q = &y;
    int **r = &p;
    r = &q;
    q = p;
    **r = 7;
                  

Not L-Values

  • L-mode evaluation sometimes disallowed
  • In C
    
    int x = 5;
    int y = 6;
    int *p = &(x + y); /* not allowed */
    (x + y) = 7;       /* not allowed */
                  
  • (x + y) not an l-value
    • although it might be stored temporarily

Further L-Values

  • L-values may require r-mode evaluation
  • Array access in C, Java, etc.
    
    arr[n + 2] = 7;
                  
  • Field access in Java, Scala, etc.
    
    obj.f1 = 7
                  
  • Combinations (including method calls) in Java, etc.
    
    obj.m1 ().f1[n + 2].m2 ().f2 = 7
                  

C / C++