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 v : S
case v : S
case Vn: Sn
default: Sn
where E is an integer int expression, v v Vn are distinct integer
constants and S S Sn 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 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
