Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( 4 0 pt ) Consider the C - style switch statement. ( a ) ( 2 5 pt ) Write an S - attributed

(40pt) Consider the C-style switch statement.
(a)(25pt) Write an S-attributed LL(1) grammar that generates C-style switch statements and checks
that all labels of the arms of the switch instructions are distinct. In order to do that, the starting
nonterminal, S, 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 S*dup=O?. Therefore, your
grammar is required to eventually compute the attribute dup of S.
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(1), you can use jflap to compute the parse
table and show there is no conflict; include the jflap answer (whole window) in your answer.
(b)(15pt) Using the above attributed grammar, draw a decorated parse tree for the following switch
instruction:
switch ( expr ){
case 2 :
case 3 : stmt
case 2 : stmt
case 1 :
case 2 :
case 1: stmt
}
Show all attributes and arrows indicated what attributes are used to compute each value.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions