Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Design a context-free grammar for polynomials in x. Add semantic functions to produce an attribute grammar that will store the outcome (as a string) of
Design a context-free grammar for polynomials in x. Add semantic functions to produce an attribute grammar that will store the outcome (as a string) of multiplication by x in a synthesized attribute of the root of the parse tree Hint: Modify the attribute grammar of problem below Write a context-free grammar for polynomials in x. Add semantic func- tions to produce an attribute grammar that will accumulate the polynomial's derivative (as a string) in a synthesized attribute of the root of the parse tree. Answer: The following assumes that exponents in the input are all positive integers. P T more-Ts D more Ts.st-T.d Pd-more-Ts.d T num T-tail T-tail x exp T-tail E T.tail.c: num.v exp.c := T-tail.c T.tal.d :-" " exp.d := float-to-string(exp.c num.v) + "X **" + int-to-string(num,v-1) exp.d := float-to-string(exp.c) more.TS2.st := more.Ts, st + " +" + Td more-Ts.d :-more-Tsst Td := T.tail.d D T.tail.d:- exp.d exp**num exp E more.Tsi + + more-Ts E T more Ts2 more-Tsi'd := more-TS2.d Design a context-free grammar for polynomials in x. Add semantic functions to produce an attribute grammar that will store the outcome (as a string) of multiplication by x in a synthesized attribute of the root of the parse tree Hint: Modify the attribute grammar of problem below Write a context-free grammar for polynomials in x. Add semantic func- tions to produce an attribute grammar that will accumulate the polynomial's derivative (as a string) in a synthesized attribute of the root of the parse tree. Answer: The following assumes that exponents in the input are all positive integers. P T more-Ts D more Ts.st-T.d Pd-more-Ts.d T num T-tail T-tail x exp T-tail E T.tail.c: num.v exp.c := T-tail.c T.tal.d :-" " exp.d := float-to-string(exp.c num.v) + "X **" + int-to-string(num,v-1) exp.d := float-to-string(exp.c) more.TS2.st := more.Ts, st + " +" + Td more-Ts.d :-more-Tsst Td := T.tail.d D T.tail.d:- exp.d exp**num exp E more.Tsi + + more-Ts E T more Ts2 more-Tsi'd := more-TS2.d
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started