1) Using the grammar in Example 3.2, show a completed
parse tree for each of the following statements: a) A = A * (B + (C
* A)) b) A = A * (B + (C))
2) Using the original grammar in Example 3.4, show a completed parse tree for the statement: A = B + C + A
1) Using the grammar in Example 3.2, show a completed parse tree for each of the...
- Using the grammar in Example 3.2, show a parse tree and a leftmost derivation for the following statement: B = C * (A * (B + C)). EXAMPLE 3.2 A Grammar for Simple Assignment Statements <assign> → <id> = <expr> <id> → A | B | C <expr> → <id> + <expr> | <id> * <expr> | ( <expr> ) | <id>
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):
Use the grammar given below and show a parse tree and a leftmost derivation for each of the following statements. 1. A = A * (B + (C * A)) 2. B = C * (A * C + B) 3. A = A * (B + (C)) <assign> → <id> <expr> = <expr> → <id> + <expr> kid<expr> <expr>) ids
6. (8 pts) Using grammar below show a Parse tree and leftmost derivation for a). A = A * (B+C) <assign> à<id> = <expr> <id> à A | B|C <expr>à <expr> + <term> | <term> <term> à <term> * <factor> |<factor> <factor> à ( <expr> ) |<id>
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...
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 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 3: Given the following grammar: assign → id := expr expr → expr + term \ term term -term *factor lfactor factor-(expr) id Using the above grammar, show a leftmost derivation (first five steps) for the following assignment statement: A ((A B)+ C) a. [3 marks] b. Using the above grammar, show a rightmost derivation (first five steps) for the following assignment statement: A:-A+B+C)+A [3 marks] Draw the abstract syntax tree for each of the above statements [4 marks]...
Using the grammar below: <program> → begin <stmt_list> end <stmt_list> <stmt> | <stmt>; <stmt_list> <stmt> <var> = <expression> <var> → ABC <expression> <var> + <var> | <var> - <var> | <var> 1) show a leftmost derivation and draw a parse tree for each of the statements below: (1) begin A=A-B; B=C; C=A end (2) begin A=B+C; C=C+B end 2) try a rightmost derivation and draw a parse tree for each of the statements in Q1).
Question 9 (10 points) Consider the following EBNF grammar for a “Calculator Language": <calculation> → <expr>= <expr> <term> (+1-) <expr> <term> <term> <factor> (* ) <term> <factor> <factor> → (<expr>) <value> <value> → [<sign> ] <unsigned> [. <unsigned> ] <unsigned> <digit> { <digit> } <digit> → 01|2|3|4|567| 8 | 9 <sign> → +|- which of the following sentences is in the language generated by this grammar ? Why? a. 3/+2.5 = b. 5-*3/4= c. (3/-2) + 3 = d. 5...