Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4. (20pt) Consider the C-style switch statement. (1) (15pt) Write an S-attributed LL(1) grammar that generates C-style switch statements and check that all labels of

image text in transcribed

4. (20pt) Consider the C-style switch statement. (1) (15pt) Write an S-attributed LL(1) grammar that generates C-style switch statements and check 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 = 0. Therefore, your grammar is required to eventually compute the attribute dup of S. For simplicity, assume that the conditional expression of the statement and the constant ex- pressions 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. (2) (5pt) Using this attributed grammar, draw a decorated parse tree for the following switch instruction: switch ( expr ) { case 1 : case 2: case 3 : stmt case 2: stmt case 2: case 3: stmt } Show all attributes and arrows indicated what attributes are used to compute each value. 4. (20pt) Consider the C-style switch statement. (1) (15pt) Write an S-attributed LL(1) grammar that generates C-style switch statements and check 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 = 0. Therefore, your grammar is required to eventually compute the attribute dup of S. For simplicity, assume that the conditional expression of the statement and the constant ex- pressions 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. (2) (5pt) Using this attributed grammar, draw a decorated parse tree for the following switch instruction: switch ( expr ) { case 1 : case 2: case 3 : stmt case 2: stmt case 2: case 3: 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

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions

Question

=+ Why have these changes occurred?

Answered: 1 week ago

Question

=+90 percent of all oil refineries) into several smaller companies

Answered: 1 week ago