Question: Consider switch statement of C language with the syntax as follows: switch ( E ) { case v 1 : S 1 case v 2

Consider switch statement of C language with the syntax as follows:
switch (E)
{
case v1 : S1
case v 2 : S2
.......................
.........................
case Vn-1: Sn-1
default: Sn
where E is an integer (int) expression, v 1, v 2,..., Vn-1 are (distinct) integer
constants and S 1, S 2,..., Sn-1 are list of statements. The semantics of switch
statement is defined as in C.
a. Define a suitable grammar for switch statement. Assume vi's as literals. There can
be zero or more case clauses and zero or one default clause. For [10+ simplicity you
may assume that all case clauses precede the default clause.
Note: You do not need to write the production rules for E and S.
b. Propose a translation scheme for switch statement 'based on your grammar. Show
the semantic actions for every production of the grammar.
Note: There is no need to show the actions for E and S as you have not expanded
the production rules for them.

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 Programming Questions!