Question

Q5: (20 points) Consider the following grammars T → int | float L → L,id I id a) Perform the pairwise disjointness test for g

b) Is grammar (I) LL1 grammar? Why?

Consider the grammar (II) and the input string int id, id; , show the content of the Stack of the Shift-Reduce algorithm. I

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer a:

Pairwise disjointness test for grammar (I):

For S->AbB | bAc, Disjointness of First(S) : First(AbB) \cap First(bAc) = \phi. S->AbB | bAc is disjoint.

For A->Ab | aBB, Disjointness of First(A) : First(Ab) \cap First(aBB) = {a} \neq\phi. A->Ab | aBB is not disjoint.

For B->Ac | cBb | c, Disjointness of First(B) : First(Ac) \cap First(cBb) \cap First(c) = {c} \neq\phi. B->Ac | cBb | c is not disjoint.

Answer b:

No, grammar (I) is not LL(1) because grammar productions are not disjoint.

To be specific, in A->Ab | aBB, First(Ab) \cap First(aBB) = {a} \neq\phi and in B->Ac | cBb | c, First(Ac) \cap First(cBb) \cap First(c) = {c} \neq\phi and hence compiler cannot decide which production Ab or aBB should parse.

Answer 3:

By creating DFA with LR(0) items of grammar (II), it is clear that grammar has no conflict states.

L→ル, は

In below picture, the content of stack is shown while parsing through Bottom up parsers like LR(0).

Stack Epmeien Action sutr id Reduce L,74, L Redime TLS means

Below is brief idea, how string is reduced to starting symbol S, via its grammar productions.

nt id id;

Although grammar (II) is left recursive but since in LR(0) there is no lookahead while constructing the DFA using grammar. So, whether it is left recursive or right recursive, no grammar would cause any problem.

Add a comment
Know the answer?
Add Answer to:
Q5: (20 points) Consider the following grammars T → int | float L → L,id I...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array...

    Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array double[10]; c. charl charArray "Computer Science"; None of the above Analyze the following code: class Test public static void main(Stringl] args) System.out.println(xMethod(10); public static int xMethod(int n) System.out.println("int"); return n; public static long xMethod(long n) System.out.,println("long"); return n The program displays int followed by 10 The program displays long followed by 10. The program does not compile. None of the above. tions 3-4 are...

  • IN c++ i post this question 5 times. hope this time somebody answer.. 16.5 Homework 5...

    IN c++ i post this question 5 times. hope this time somebody answer.. 16.5 Homework 5 OVERVIEW This homework builds on Hw4(given in bottom) We will modify the classes to do a few new things We will add copy constructors to the Antique and Merchant classes. We will overload the == operator for Antique and Merchant classes. We will overload the + operator for the antique class. We will add a new class the "MerchantGuild." Please use the provided templates...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT