Answer a:
Pairwise disjointness test for grammar (I):
For S->AbB | bAc, Disjointness of First(S) : First(AbB)
First(bAc) =
. S->AbB | bAc
is disjoint.
For A->Ab | aBB, Disjointness of First(A) : First(Ab)
First(aBB) = {a}
. A->Ab |
aBB is not disjoint.
For B->Ac | cBb | c, Disjointness of First(B) : First(Ac)
First(cBb)
First(c) = {c}
. 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) First(aBB) =
{a}
and in
B->Ac | cBb | c, First(Ac)
First(cBb)
First(c) = {c}
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.
In below picture, the content of stack is shown while parsing through Bottom up parsers like LR(0).
Below is brief idea, how string is reduced to starting symbol S, via its grammar productions.
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.
Q5: (20 points) Consider the following grammars T → int | float L → L,id I...
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 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...