Question

You are given the following context free grammar in BNF format. 1 <expression> ::= <term> |...

You are given the following context free grammar in BNF format.
1 <expression> ::= <term> | <expression> "+" <term>

2 <term> ::= <factor> | <term> "*" <factor>

3 <factor> ::= <constant> | <variable> | "(" <expression> ")"

4 <variable> ::= "x" | "y" | "z"

5 <constant> ::= <digit> | <digit> <constant>

6 <digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"

a) Show how the expression 4 * (2 * x + 7) can be reduced to the start symbol of the grammar. Apply only one rule in each step and try in every step to replace the leftmost symbol you can replace.

b) Is any additional information needed to reduce this expression in a meaningful way? Explain.

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

4*12*%+7) <digibst (2*x+7) <Const>* (2*x+7) <tactor>* (2*X+7) < terms * (2*x+7) <teem? * (<digit> * X+7) <tem> * Kconst >.* X<lam * ( <lem>*<vaciable> 4.7) <tcim> (<teem) 4 rlockor +7) skeemo » * 1 <lema ) Lterms * (<Expiremian+7) <teems* ( clxpresi

Add a comment
Know the answer?
Add Answer to:
You are given the following context free grammar in BNF format. 1 <expression> ::= <term> |...
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
  • 1. Consider the following BNF definition of arithmetic expressions: <expression> <expression>+ <term> | <expression>-<term> <term> <term>...

    1. Consider the following BNF definition of arithmetic expressions: <expression> <expression>+ <term> | <expression>-<term> <term> <term> ::= <term>*<factor> <term>/<factor> | <factor> <factor> :: <digit>«<exponent> | <didgit>^«<exponent> <digit>(<expression> <digit>:= 01|2|3|4151617181910. <exponent> :: <sign> <val> <sign>=+1 - <val 1121314 Draw the expression trees of the following expressions, parsed according to the BNF above. a) 46 - 6/4-243. b) 4*6 -(6/4 - 243) c) 31-2-3*2 + 3/2 d) 3^2*5. e) ((3^2)).

  • 3. Consider the following BNF for arithmetic expressions: <expression> ::= <term> <term>+ <expression> | <term> -...

    3. Consider the following BNF for arithmetic expressions: <expression> ::= <term> <term>+ <expression> | <term> - <expression> <term> ::= <factor> | <factor> * <term> | <factor> I <term> <factor> ::= <constant> (<expression>) <constant ::= 0|1|2|3|4|5|6789 a) Show the expression tree of the following expression: 8/7*5/6-6/4/2-7*(5+2). b) Give the value of this expression. c) Same question as (a), if the BNF were <expression> ::= <term> | <expression>+ <term> | <expression> - <term> <term> ::= <factor> | <term>*<factor> | <term> / <factor>...

  • Consider the following BNF grammar that we saw in class:        EXP    ::= EXP + TERM  ...

    Consider the following BNF grammar that we saw in class:        EXP    ::= EXP + TERM   | EXP - TERM    | TERM        TERM   ::= TERM * FACTOR | TERM / FACTOR | FACTOR        FACTOR ::= ( EXP ) | DIGIT        DIGIT ::= 0 | 1 | 2 | 3    (a) Translate into EBNF.    (b) Draw syntax diagrams.    (c) What are the two requirements on a grammar for a predictive parser to be able to...

  • Question 1 Consider the following BNF grammar: Not complete Marked out of 3.00 p Flag question...

    Question 1 Consider the following BNF grammar: Not complete Marked out of 3.00 p Flag question <letter> ::= "a" | "b" | "C" | "d" | "e" | "F" | "g" | "h" | "1" ";" | "K" | "1" | "m" | "n" | "0" | "p" | "q" | "r" | "S" | "t" || "u" | "V" | "W" | "x" | "y" | "z" <digit> ::= "O" | "1" | "2" | "3" | "4" |...

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

  • 1.a    Consider  the following Grammar,                               

    1.a    Consider  the following Grammar,                                                                  <assign> à   <id> = <expr>     <id> à A | B |C    <expr> à < expr> + <expr>         | <expr> * <expr>                   | ( <expr> )                   | <id> Derive the following statement using leftmost derivation.   A = A * (B*(C+ A)) b. 2 a}.    Consider the following grammar that expresses parenthesized expressions of digits, including both addition and multiplication. <expr> := <expr> + <expr> | <expr> * <expr> | (expr>) | <digit> <digit> :=   0 | 1 | 2 |...

  • Construct a context-free grammar generating L. You do not need an inductive proof, but you should...

    Construct a context-free grammar generating L. You do not need an inductive proof, but you should explain how your construction accounts for each rule. Let L be the language over {a,b,c} accepting all strings so that: 1. No b's occur before the first c. 2. No a's occur after the first c. 3. The last symbol of the string is b. 4. Each b that is not the last symbol is immediately followed by at least two d's. 5. There...

  • (8) (3 marks) Write BNF grammar rules for a language that is comprised only of sentences described as follows: symbol,...

    (8) (3 marks) Write BNF grammar rules for a language that is comprised only of sentences described as follows: symbol, fol symbols orjust onéx symbol, A sequence of one or more occurrences of an a lowed by either zero or morez followed by a sequence of one or more b symbols. (9) (1 mark) The following fragment of grammar describes the syntax of the exponentiation operator. What is the associativity ot the operator as detined here? factor | expr factor...

  • 3 points) Question Three Consider the context-free grammar S >SS+1 SS 1a and the string aa...

    3 points) Question Three Consider the context-free grammar S >SS+1 SS 1a and the string aa Give a leftmost derivation for the string. 3 points) (4 poiots) (5 points) (3 points) sECTION IWOLAttcmpt.any 3.(or 2) questions from this.scction Suppose we have two tokens: (1) the keyword if, and (2) id-entifiers, which are strings of letters other than if. Show the DFA for these tokens. Give a nightmost derivation for the string. Give a parse tree for the string i) Is...

  • Consider the following BNF grammar: S ::= A x | B y A ::= B y...

    Consider the following BNF grammar: S ::= A x | B y A ::= B y | C w B ::= x | B w C ::= y Which of the following regular expressions describes the same set of strings as the grammar? 1. xwxy + xww∗y + ywx 2. xwx + xww∗y + yw 3. xw∗y + xwxyx + ywx 4. xwy + xw∗xyx + ywx 5. xw∗y + xw∗yx + ywx 6. none of the above 7. all...

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