Given the following grammar
statement if-stmt | other | Ԑ
if-stmt if (exp) statement else-part
else-part else statement | Ԑ
exp 0 | 1
a) Draw a parse tree for the string
If (0) if (1) other else else other
b) What is the purpose of the two else’s?
I need the the diagram of the parse tree
PLEASE UPVOTE IF YOU FIND THE SOLUTION USEFUL.
PARSE TREE:
The first else refers to the inner if(1) part according to the above parse tree and the outer else with result as other is part of outer if(0) part.
Given the following grammar statement if-stmt | other | Ԑ if-stmt if (exp) statement else-part else-part...
The following grammar describes the syntax of the Java if statement: <stmt> rightarrow <matched> | <unmatched> <matched> rightarrow if (<logic_expr>) <matched> else <matched> | <non_if_stmt> <unmatched> rightarrow if (<logic_expr>) <stmt> | if (<logic_expr>) <matched> else <unmatched> Using this grammar, draw a parse tree for the following sentential form: if (<logic_expr>) if (<logic_expr>) <non_if_stmt> else <non_if_stmt>
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) → |
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...
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...
Consider the following grammar: (//some alternative rules are listed on separate lines without using symbol |): stmt −> assignment −> subr call assignment −> id := expr subr call −> id ( arg list ) expr −> primary expr tail expr tail −> op expr −> ε primary −> id −> subr call −> ( expr ) op −> + | - | * | / arg list −> expr args tail args tail −> , arg list −> ε...
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.
3. Given the following grammar and the right sentential forms, draw a parse tree and show the phrases and simple phrases, as well as the handle. <S> <A> <B> →. a <A> b b <B> <A> → a b a <A> <B> → a <B> b (a) a a <A> a bb (b) b <B> a <A> b
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]...
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.
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...