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:
decllist decllist; decl decl
decl simpledeclstructureddecl
simpledecl type varlist
structureddecl type varnum num means an array whose size is
given by num.val
type integer real
varlist var, varlist var
var
a 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:
categorysimplestructured
elementtype 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, inserttype, insertsize, and insertlink with appropriate parameters.
b marks Draw dependency graphs corresponding to each grammar rule for the
attribute grammar of a and for the string integer ab; integer c
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
