Question: Consider the following grammar for simple declarations: decl - list decl - list; decl | decl decl simple - decl | structured - decl simple

Consider the following grammar for simple declarations:
decl-list decl-list; decl | decl
decl simple-decl|structured-decl
simple-decl type var-list
structured-decl type var[num] num] means an array whose size is
given by num.val
type integer | real
var-list var, var-list | var
var id
a)(10 marks) Write an attribute grammar to insert the type of the variables in the
symbol table. If it is an array you have to insert its elements type and its size in
addition to indicating that this variable is a structured variable.
(Hint: consider the type field in the symbol table as a structure that has the fields:
category(simple/structured),
element-type which includes simply integer or real in case of a simple
type, and includes the element type of an array (also integer or real) in
case of an array, and
size which includes the size of an array and null in case of simple types
you can also assume that you have the following semantic actions insert-
category, insert-type, insert-size, and insert-link with appropriate parameters.
b)(5 marks) Draw dependency graphs corresponding to each grammar rule for the
attribute grammar of (a) and for the string integer a,b; integer c[5]
 Consider the following grammar for simple declarations: decl-list decl-list; decl |

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!