Question

Consider the following grammar: A -> aB | b | cBB B -> aB | bA...

Consider the following grammar:

A -> aB | b | cBB

B -> aB | bA | aBb

C -> aaA | b | caB

  1. Perform the pairwise disjoint test for the grammar.
  2. Rewrite the above grammar so that all grammar rules pass the pairwise disjoint test.
  3. Suppose lex() is the lexical analyzer which gets the next lexeme and puts its token code in the global variable nextToken. And suppose the token codes for terminals a, b, and c are A_CODE, B_CODE, and C_CODE, respectively. Sketch a subprogram in a recursive-descent LL parser to parse the nonterminal A in the grammar you defined above in the question 2.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ans:-

   Given,

A -> aB | b | cBB

B -> aB | bA | aBb

C -> aaA | b | caB

let A, the first sets of each RHS of each nonterminal

a] A -> aB | b | cBB

FIRST(aB) = a

FIRST(b) = b

FIRST(cBB) = c

PASSED

b] B -> aB | bA | aBb

FIRST(aB) = {a}

FIRST(bA) = {b}

FIRST(aBb) = {a}

FAILED

c] C -> aaA | b | caB

FIRST(aaA) = {a}

FIRST(b) = {b}

FIRST(caB) = {c}

PASSED

* PROGRAM:

#include <stdio.h>

void A();
void B();
void C();
char input[100];
int i,error;
int main()
{
printf("/n Enter the inputs:");
   A();
  
}


A()
{
   if (input(i) == 'a''B') {
   i++;
       B();
   }
   else if(input(i) == '|')
   {
   i++;
   }
   else if(input(i) == 'b')
   {
   i++;
   }
   else if(input(i) == '|')
   {
   i++;
   }
   else if(input(i) == 'c''B''B')
   {
   i++;
   B();
   }
}

B()
{
   if (input(i) == 'a''B') {
   i++;
       B();
   }
   else if(input(i) == '|')
   {
   i++;
   }
   else if(input(i) == 'b''A')
   {
   i++;
   A();
   }
   else if(input(i) == '|')
   {
   i++;
   }
   else if(input(i) == 'a''B''b')
   {
   i++;
   B();
   }
}

C()
{
   if (input(i) == 'a''a''A') {
   i++;
       A();
   }
   else if(input(i) == '|')
   {
   i++;
   }
   else if(input(i) == 'b')
   {
   i++;
  
   }
   else if(input(i) == '|')
   {
   i++;
   }
   else if(input(i) == 'c''a''B')
   {
   i++;
   B();
   }
}

Add a comment
Know the answer?
Add Answer to:
Consider the following grammar: A -> aB | b | cBB B -> aB | bA...
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
  • (10] Eliminate left recursion from the grammar A Ba |Aa c B Bb | Ab 1...

    (10] Eliminate left recursion from the grammar A Ba |Aa c B Bb | Ab 1 d A Ad IB A BA ASJAE Consider the following grammar G: S'S S (S)S|e fa) (10] Construct the collection of the sets of LR(0) items (b) [5] When constructing the action table of SLR parser of G what are the rules to determine the parsing actions? That is, what is the rule for a shift action at state /? What is the rule...

  • 1. (p. 2-3.) Which of the following is NOT a reason for studying concepts of programming...

    1. (p. 2-3.) Which of the following is NOT a reason for studying concepts of programming languages according to Sebesta? a. Increased capacity to express ideas. b. Improved background for choosing appropriate languages. c. Increased ability to design new languages. d. Increased ability to learn new languages. 2. (p. 5-6.) What programming language has dominated scientific computing over the past 50 years? a. FORTRAN b. ALGOL c. SNOBOL d. PL/I 3. (p. 6.) What programming language has dominated artificial intelligence...

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