Question

1.)    Consider the following grammar in which S, A, and B are nonterminal symbols and S...

1.)    Consider the following grammar in which S, A, and B are nonterminal symbols and S is the start symbol.

S → 1A | 0B

A → A0 | 1B

B → 10A| 1

Show that the grammar is ambiguous by showing two parse trees for the sentence 1110110 using leftmost derivation.

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

In the leftmost derivation of a language the leftmost non-terminal is replaced at every step to obtain the required string.

The string 1110110 can be obtained by two leftmost derivations which are as follows:

1.

S-) IA (The leftmost non-terminal is A.) IA → 1 1 B (The leftmost non-terminal is B.) 11B → 1 1 10A (The leftmost non-termina

The parse tree of the above presented derivation is as follows:

2.

S1A (The leftmost non-terminal is A.) 1A → 1A0(The leftmost non-terminal is A.) 1A0 11B0 (The leftmost non-terminal is B.) 11

The parse tree for the above presented representation is as follows:

1 1 0 1 1 1

Since there are two different parse trees possible using the left-most derivation for the same input string therefore, the given grammar is ambiguous.

Add a comment
Know the answer?
Add Answer to:
1.)    Consider the following grammar in which S, A, and B are nonterminal symbols and S...
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
  • Consider the following grammar (S, A, B, and C are nonterminal symbols; S is the start...

    Consider the following grammar (S, A, B, and C are nonterminal symbols; S is the start symbol; 0 and 1 are terminal symbols): S → AA A → BCB B → B0 | B1 | 0 | 1 C → 00 | 11 Which of the following sentences are in the language generated by the grammar? Show derivations for the sentences that can be generated. If a sentence cannot be generated by the grammar, explain why. a) 10010001 b) 01101101...

  • IN HASKELL Consider a context-free grammar with nonterminal symbols: sentence (the start symbol), noun-phrase, verb-phrase, article,...

    IN HASKELL Consider a context-free grammar with nonterminal symbols: sentence (the start symbol), noun-phrase, verb-phrase, article, noun, and verb; terminal symbols: "." (period), "a", "the", "girl", "dog", "sees", and "pets"; and the following rules: sentence = noun-phrase verb-phrase "." . noun-phrase = article noun . article = "a" | "the" . noun = "girl" | "dog" . verb-phrase = verb noun-phrase . verb = "sees" | "pets" . a. Give a left-most derivation of the sentence: a girl pets the...

  • 3. Using the grammar below, show a parse tree and a leftmost derivation for the statement....

    3. Using the grammar below, show a parse tree and a leftmost derivation for the statement. A = ( A + (B)) * C assign <idxpr expr>? <expr> <term> term <term factor factor (<expr>) l <term I <factor l <id> 4. Prove that the following grammar is ambiguous (Give sentence that has two parse trees, and show the parse trees):

  • Consider the following grammar: S → A1B A → 0A |ϵ B → 0B | 1B...

    Consider the following grammar: S → A1B A → 0A |ϵ B → 0B | 1B |ϵ Give parse trees for each of the strings: a. 00101 b. 1001 c. 00011

  • Consider the following grammar (G1) for simple assignment statements. (The symbols in double quotation marks are...

    Consider the following grammar (G1) for simple assignment statements. (The symbols in double quotation marks are terminal symbols.) assign → id “ = ” expr id → “A” | “B” | “C” expr → expr “ + ” expr | expr “ ∗ ” expr | “(” expr “)” | id a) Give a (leftmost) derivation for string A = B ∗ A + C. b) Give the parse tree for string A = B ∗ A + C. c)...

  • Show that the following grammar is ambiguous. Hint: Show two different leftmost or rightmost derivations for...

    Show that the following grammar is ambiguous. Hint: Show two different leftmost or rightmost derivations for the same string. Equivalently, you can show two different parse trees for the same string. <expr> ::= <expr> + <expr> | <expr> - <expr> | <expr> * <expr> | <expr> / <expr> | int int ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Using this grammar show that ambiguity is not acceptable...

  • 2. Consider the following grammar:                         <assign> à <id> = <expr>       

    2. Consider the following grammar:                         <assign> à <id> = <expr>            <id>   à A | B | C            <expr> à <id> + <expr>                      | <id> * <expr>                      | ( <expr> )                      | <id> Show a parse tree and leftmost derivation for the following statements: (a)        A = ( A + B ) * C (b)        A = A * ( B + C ) 3. [10 Points] Show that the following grammar is...

  • Question Set 2 1. Given the following grammar dactor>-> ( <expr> ) a) What is the...

    Question Set 2 1. Given the following grammar dactor>-> ( <expr> ) a) What is the associativity of each of the operators? What is precedence of the operators? Show a leftmost derivation and parse tree for the following sentence: b) c) A-A(B(C A)) d) Rewrite the BNF grammar above to give precedence over and force to be right associative.

  • Question Set 2 1. Given the following grammar dactor>-> ( <expr> ) a) What is the...

    Question Set 2 1. Given the following grammar dactor>-> ( <expr> ) a) What is the associativity of each of the operators? What is precedence of the operators? Show a leftmost derivation and parse tree for the following sentence: b) c) A-A(B(C A)) d) Rewrite the BNF grammar above to give precedence over and force to be right associative.

  • ) Using the following grammar, show a parse tree and a leftmost derivation for the following...

    ) Using the following grammar, show a parse tree and a leftmost derivation for the following sentence (make sure you do not omit parentheses in your derivation):          Grammar          <assign> → <id> = <expr>    <id> → A | B | C    <expr> → <expr> + <term> | <term>    <term> → <term> * <factor> | <factor>    <factor> → (<expr>) | <id> Derive C = (A+B)*(C+A)*(C+B)

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