Compiler Theory Ch4 Syntax Analysis-Part 2 For the grammar S->0S1101, indicate t
ID: 3730980 • Letter: C
Question
Compiler Theory Ch4 Syntax Analysis-Part 2 For the grammar S->0S1101, indicate the handle in each of the following right-sentential forms: 1. a. 000111 b. 00S11 2. For the grammar Sss 1sS | a, indicate the handle in each of the following right-sentential forms: b. SS+a*a+ 3. Give bottom-up parses for the following input strings and grammars: a. The input 000111 according to the grammar of above question 1. b. The input aaa+ according to the grammar of above question 2. Ch5 Syntax-Directed Translation 4. Based on the following SDD, give annotated parse trees for the following expressions: PRODUCTION SEMANTIC RULES LEn 1) 3) 4) ET TTj * F | T.oal = T.val × F.t al T.val F.eal 6) F (E) al E.va 7) F digit IF.eal = digit.lexval a) (3+4) (5+6)n b) 1*2"3*(4+5)n Below is a grammar for expressions involving operator+ and integer or floating-point operands. Floating-point numbers are distinguished by having a decimal point. 5. E-E TIT T - num.num | num Give an SDD to determine the type of each term T and expression EExplanation / Answer
1)
Ans:
Given grammar is
S->0S1 suppose assume that it is rule(1)
S->01 rule(2)
let us find handle for the given right sentential forms
a)000111
based on rule(2) we can replace above string as 00S11 (I just replaced 01 with S)
based on rule(1) we can replace above 00S11 as 0S1 (I just replaced 0S1 with S)
and finally based on rule(1) we can replace 0S1 as S
Thus the handle for the above string is 2,1,1
b)00S11
based on rule(1) we can replace above 00S11 as 0S1 (I just replaced 0S1 with S)
and finally based on rule(1) we can replace 0S1 as S
Thus the handle for the above string is 1,1
2)Ans
given grammar is
S->SS+ suppose assume that it is rule(1)
S->SS* rule(2)
S->a rule(3)
let us find handle for given right sentential forms
a)SSS+a*+
based on rule(1) we can replace above SSS+a*+ as S(S)a*+ (I just replaced SS+ with S)
based on rule(3) we can replace S(S)a*+ as S(S)S*+ (I just replaced a with S)
based on rule(2) we can replace S(S)S*+ as S(S)+ (I just replaced SS* with S)
and finally based on rule(1) we can replace S(S)+ as S (I just replaced SS+ with S)
Thus the handle for the above string is 1,3,2,1
b) SS+a*a+
based on rule(1) we can replace above SS+a*a+ as Sa*a+ (I just replaced SS+ with S)
based on rule(3) we can replace Sa*a+ as SS*a+ (I just replaced a with S)
based on rule(2) we can replace SS*a+ as Sa+ (I just replaced SS* with S)
based on rule(3) we can replace Sa+ as SS+ (I just replaced a with S)
based on rule(1) we can replace above SS+ as S (I just replaced SS+ with S)
Thus the handle for the above string is 1,3,2,3,1
c) aaa*a++
based on rule(3) we can replace above aaa*a++ as aaS*a++ (I just replaced a with S)
based on rule(3) we can replace aaS*a++ as aSS*a++ (I just replaced a with S)
based on rule(2) we can replace aSS*a++ as aSa++ (I just replaced SS* with S)
based on rule(3) we can replace aSa++ as aSS++ (I just replaced a with S)
based on rule(1) we can replace above aSS++ as aS+ (I just replaced SS+ with S)
based on rule(3) we can replace aS+ as SS+ (I just replaced a with S)
based on rule(1) we can replace above SS+ as S (I just replaced SS+ with S)
Thus the handle for the above string is 3,3,2,3,1,3,1
Thanks !
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.