Question

1. Given grammar: E -> E*E | E + E | num and input string num...

1. Given grammar: E -> E*E | E + E | num and input string num + num *num.

1a.Write 2 possible leftmost derivations from E to the input string.

1b.Draw parse tree for the two leftmost derivation that you wrote above.

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

1a.

First leftmost derivation :

E -> E * E -> E + E * E -> num + E * E -> num + num * E -> num + num * num

Second Leftmost derivation

E -> E + E -> num + E -> num + E * E -> num + num * E -> num + num * num

1b. Two parse trees for the input string num + num * num are :

Taking E * E production first

num num

Taking E + E production first:РАТ Еж шт)

Add a comment
Know the answer?
Add Answer to:
1. Given grammar: E -> E*E | E + E | num and input string num...
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
  • For the grammar <A> ::= <A><A> '+' | <A><A> '*' | 'a' and the string aa...

    For the grammar <A> ::= <A><A> '+' | <A><A> '*' | 'a' and the string aa + a* Give the leftmost derivation Give the rightmost derivation Give a parse tree Is the grammar ambiguous or unambiguous? (Justify your answer) Describe the language generated by this grammar

  • 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.

  • Given the following ambiguous context free grammar (3x20) 1. (a) Explain why the grammar is ambiguous...

    Given the following ambiguous context free grammar (3x20) 1. (a) Explain why the grammar is ambiguous (b) Find an equivalent unambiguous context-free grammar. (c) Give the unique leftmost derivation and derivation tree for the string s generated from the unambiguous grammar above. 2. Construct non-deterministic pushdown automata to accept the following language (20) 3. Convert the following CFG into an cquivalent CFG in Chomsky Normal Form (CNF) (20)-

  • The questions in this section are based on the grammar given as the following: prog ->...

    The questions in this section are based on the grammar given as the following: prog -> assign | expr assign -> id = expr expr -> expr + term | expr - term | term term -> factor | factor * term factor -> ( expr ) | id | num id -> A | B | C num -> 0 | 1 | 2 | 3 (2a) What is the associativity of the * operator? (5 points) (2b) What...

  • For both of the following languages, provide a grammar that generates it, an intuitive explanatio...

    Please actually answer it For both of the following languages, provide a grammar that generates it, an intuitive explanation why this grammar generates this language, and a graphical representation of a push-down automaton that recognizes this language. (a) The language of properly nested sets of parentheses over the alphabet G)). Note that the string (COO))) belongs to this language, while the string (O) () does not because the third closing parenthesis does not have a matching opening parenthesis. Provide a...

  • Please help me with the coding for LL(1)!! The given grammar was: P → PL |...

    Please help me with the coding for LL(1)!! The given grammar was: P → PL | L L → N; | M; | C N → print E M → print "W" W → TW | ε C → if E {P} | if E {P} else {P} E → (EOE) | V (note: this has a variable O) O → + | - | * V → 0 | 1 | 2 | 3 (note: this has a terminal...

  • The questions in this section are based on the grammar given as the following: prog ->...

    The questions in this section are based on the grammar given as the following: prog -> assign | expr assign -> id = expr expr -> expr + term | expr - term | term term -> factor | factor * term factor -> ( expr ) | id | num id -> A | B | C num -> 0 | 1 | 2 | 3 (2a) What is the associativity of the * operator? (5 points) (2b) What...

  • 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):

  • Name: 3. (10 points) Given grammar: <program> → <stmts> Page: 2 <term> → <var> 1 const...

    Name: 3. (10 points) Given grammar: <program> → <stmts> Page: 2 <term> → <var> 1 const 1), write down derivation of: c-5+a 2) What are terminals and what are non-terminals in the grammar? Show a complete parse, including the parse stack contents, input string, and action for the string: id - id + id, using the grammar and parse table below. (10 points) 4. Grammar State id S4 4. T F 5. F (E) R2 S7 R4 R4 R2İR2 Parse...

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