Menu

[Solved]Consider Following Grammar G 2 S C S S C S Else S S Statement C Condition Production 1 Pro Q37164102

Consider the following grammar G. 2. s> if C then S S->if C then S else S S-> statement C->condition (Production 1) (Producti

Consider the following grammar G. 2. s> if C then S S->if C then S else S S-> statement C->condition (Production 1) (Production 2) (Production 3) (Production 4) A. Show that G is ambiguous. You will do this by finding one sentence that has two different valid parse trees. B. Explain in words the problem introduced by this ambiguity- what is the difference in meaning between the two parse trees from A? How does C++ handle this problem (HINT: look at some C++ code with nested ifs!)? Give a modified version of G that captures the way that C++ disambiguates the two parse trees (HINT: Your modified G will have the same number of productions as the original, you will just make small modifications to two of the productions. This is NOT like the disambiguation we did in class). Give the parse trees generated by your new grammar that are analogous to your parse trees from step A (that is, where you applied Production 1 in step A, apply the modified version of Production 1 from step C, etc.) What do you notice about the sentences generated by the new parse trees? C. D. Show transcribed image text Consider the following grammar G. 2. s> if C then S S->if C then S else S S-> statement C->condition (Production 1) (Production 2) (Production 3) (Production 4) A. Show that G is ambiguous. You will do this by finding one sentence that has two different valid parse trees. B. Explain in words the problem introduced by this ambiguity- what is the difference in meaning between the two parse trees from A? How does C++ handle this problem (HINT: look at some C++ code with nested ifs!)? Give a modified version of G that captures the way that C++ disambiguates the two parse trees (HINT: Your modified G will have the same number of productions as the original, you will just make small modifications to two of the productions. This is NOT like the disambiguation we did in class). Give the parse trees generated by your new grammar that are analogous to your parse trees from step A (that is, where you applied Production 1 in step A, apply the modified version of Production 1 from step C, etc.) What do you notice about the sentences generated by the new parse trees? C. D.

Expert Answer


Answer to Consider the following grammar G. 2. s> if C then S S->if C then S else S S-> statement C->condition (Production 1) (Pro… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *