Answered step by step
Verified Expert Solution
Question
1 Approved Answer
( 4 0 pt ) Consider the C - style switch statement. ( a ) ( 2 5 pt ) Write an S - attributed
pt Consider the Cstyle switch statement.
apt Write an Sattributed LL grammar that generates Cstyle switch statements and checks
that all labels of the arms of the switch instructions are distinct. In order to do that, the starting
nonterminal, will have an attribute dup that will store all the duplicate values. There are no
duplicate values on the arms of the switch statement if and only if Therefore, your
grammar is required to eventually compute the attribute dup of
For simplicity, assume that the conditional expression of the switch statement and the constant
expressions labelling the arms are expr tokens and that each arm has a statement that is a stmt
token; the break and default parts are omitted as their role is irrelevant for our problem. Each
expr has an attribute val provided by the scanner that gives the value of the expression.
Explain why your grammar works as required. For LL you can use jflap to compute the parse
table and show there is no conflict; include the jflap answer whole window in your answer.
bpt Using the above attributed grammar, draw a decorated parse tree for the following switch
instruction:
switch expr
case :
case : stmt
case : stmt
case :
case :
case : stmt
Show all attributes and arrows indicated what attributes are used to compute each value.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started