Question: ( 2 0 pt ) Consider the switch statement in C - like languages, defined here according to this grammar: Switch longrightarrow switch (

(20pt) Consider the switch statement in C-like languages, defined here according to this grammar:
Switch \longrightarrow switch ( expr ){ Cases Default }
Cases }\longrightarrow\mathrm{ Cases Case
Cases }\longrightarrow
Case }\longrightarrow\mathrm{ case const: Stmt
Stmt \longrightarrow stmt; break;
Stmt }\longrightarrow\mathrm{ stmt;
Stmt \longrightarrow }
Default \longrightarrow default: stmt;
Default \longrightarrow
(a)(2pt) Compute the sets FIRSt(x) and FOLlOW(x), for all non-terminals x, and the sets
PREDICT(p) for all production rules p.
(b)(3pt) Prove that G is not an LL(1) grammar. Describe all conflicts.
(c)(5pt) Build an LL(1) grammar, G1, equivalent with G. Compute, for G1, the sets FIRST (x)
and Follow (x), for all non-terminals x, and the sets PrEdiCT(p) for all production rules p.
(d)(5pt) Show how the switch statement can be used, in general, to simulate any if ..then ..else
statement.
(e)(5pt) How is it possible that the switch statement can simulate if's and have an LL(1)
grammar, since we said that there is no top-down grammar for if ..then. . else statements?
( 2 0 pt ) Consider the switch statement in C -

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!