6.0 Introduction

6.1 Static Checking

6.2 Attribute Grammars

6.3 Translation to an IR

6.4 Semantic Analyzer Generators

6.5 More on Attribute Grammars

6.6 Attribute Evaluation

6.7 Summary

Web References

Exercises

6.3.5 Arrays

Array references are often translated to intermediate code with an array operator and two children. The left child is the name of the array, and the right child is the subscript expression.

Thus,

    Temp = L[i]

as an abstract syntax tree would be

and as quadruples would be

    T1 = List[i]
    Temp = T1

Using the notation, the code generator would have to compute the array offset for machines which do not have an indexing addressing mode. The alternative is to expand the intermediate representation.

Using "( )" to mean "contents of" and "addr" to mean "address of," the quadruples for "Temp = List[i]" would be:


        T1 = addr(List) 
        T2 = T1 + i
        Temp = (T2)


Similarly, if the array reference is on the left-hand side of an assignment statement as in "List[i] = Temp", low-level quadruples would be:


        T1 = addr(List) 
        T2 = T1 + i
        (T2) = Temp 


Even if a machine has an indexing addressing mode, translating array references into their low-level format may allow optimizations (for example, if the array subscript were a common subexpression).

Send questions and comments to: Karen Lemone