Given a CFG in BNF, (50 points)
<stmt_list> → <stmt> | <stmt>; <stmt_list>
<stmt> → <var> = <expr>
<expr> → <var> + <expr> | <var> * <expr> | <var>
<var> →a| b| c| d
show a derivation for the given sentence a = b*c - d; b = d - a
2. show a parsing tree for a = b*c - d; b = d -
a
1)
<stmt_list>
<stmt>; <stmt_list>
<stmt>; <stmt>
<stmt>; <var> = <expr>
<stmt>; <var> = <var> - <expr>
<stmt>; <var> = <var> - <var>
<stmt>; <var> = <var> - a
<stmt>; <var> = d - a
<stmt>; b = d - a
<var> = <expr>; b = d - a
<var> = <var> * <expr>; b = d - a
<var> = <var> * <var> - <var>; b = d -
a
<var> = <var> * <var> - d; b = d - a
<var> = <var> * c - d; b = d - a
<var> = b * c - d; b = d - a
a = b * c - d; b = d - a
b)
Please up vote. I need it very badly right now.
Given a CFG in BNF, (50 points) <stmt_list> → <stmt> | <stmt>; <stmt_list> <stmt> → <var>...
P2) Given grammar in BNF, answer the following questions (30 points) <stmt-list>→<stmt> | <stmt»; <stmt-list> (a) Rewrite the given grammar into a EBNF (b) Is the given grammar ambiguous? Support your answer to receive the full credit. (c) Given string A-B C-D: B-C-A-D, draw a parsing tree
P2) Given grammar in BNF, answer the following questions (30 points) → |
Concepts of Programming language Convert the following BNF to EBNF <STMT_LIST> -> <stmt> | <stmt>; <stmt_list> <stmt> -> <var> = <expr> <var> -> A | B | C <EXPR> -> <var> + <var> | <var> - <var> | <var>
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 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.
1. In a language, each sentence is a string starting with a capital letter followed by two or more small letters and ending with three or more digits. Example sentences are Abc001, Zyxw9876 etc. a) Write a BNF grammar for the language. b) Show the derivation and the parse tree of the string Test3501. 2. Augment the following BNF to write an attribute grammar. Assume the only possible variable types are integer and float. The language rules are as follows:...
Write a parser program for cSub using the method of recursive descent. The main program here will effectively be the main program of the compiler as a whole. The input to the program will be a Csub source file, specified on the command line. The program will construct a parse tree for the program, with one interior node for every nonterminal in the derivation of the program, and one leaf node for each of the id, num, and real tokens...
Given the following BNF: S → N+S | N N → 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 For each sentence, do two things: draw a parse tree, and write out a leftmost derivation. Don't skip any steps! 2+3 4+5+6
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...
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...