hw3 - CS 6353 Compiler Construction, Homework #3 1....

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 6353 Compiler Construction, Homework #3 1. Consider the following grammar which defines the syntax for a simple array reference (e.g., temp[2,3]). A id [ L ] L int, L L int (a) Write an attributed grammar to compute the address of the array reference. You need to know the base address of the array. It can be obtained by the function address( name ), where name is the array name. Also, you need the size of each dimension of the array. It can be obtained by the function size( name , dim ), where name is the array name and dim is the specific array dimension. Assume that array indices are defined as that in C, starting from 0 for each dimension. Furthermore, you will need to get the value of the actual int and string of the actual id (which is the array name), and we assume that int.value and id.string give you these needed information. In your attributed grammar, you will need three attributes, addr , dim , and name , where addr is used to keep the information in address computation, dim is to keep track of the dimension currently being considered, and name is used to keep track of the array name. Please put the attribute actions next to the production rules above. Try not to use additional attributes and definitely not global variables. Just write the attributed grammar without considering additional techniques. If you need to index the symbols in a production, please do so in the production above. If a production does not need any action, just leave it empty.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

hw3 - CS 6353 Compiler Construction, Homework #3 1....

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online