Computers and Technology

(a) Write a context-free grammar for polynomials in x. Add semantic func- tions to produce an attribute grammar that will accumulate the polynomials derivative (as a string) in a synthesized attribute of the root of the parse tree. The following assumes that exponents in the input are all positive integers. PT more-Ts more. Ts. st :=T. d P. d:= more. Ts. d T num T tail > Ttail. c := num. v T. d: T. tail. d T tail x exp exp. c:- T. tail. c ► T. tail. d = exp. d T tail DT-tail. d:="" exp ** num exp. d := float_to_string(exp. cx num. v) + "* **" + int_to_string(num. - 1) expe exp. d := float_to_string(exp. c) more. Ts + + T more. Ts2 ► more. Ts2.st := more. TS. st + "+" +Td more. TS. d:= more. Ts2.d more. Ts € more-Ts. d:= more. Ts. st (b) Replace your semantic functions with action routines that can be evaluated during parsing. P + T {more. Ts. st := T. d} more_Ts {P. d := more-Ts. d} T + num {T-tail. c := num. v} T_tail {T. d := T-tail. d} T tail + x {exp. c := T-tail. c} exp {T-tail. d = exp. d} €{T-tail. d := ""} exp ** num {exp. d := float_to_string(exp. c x num. v) + "x **" + int. to. string(num. v - 1)} € {exp. d := float-to-string(exp. c)} more-Ts → + T {more-Ts2.st := more. Tsi. st + + T. d} more-T2 {more. Ts .d = more. Ts2.d} e{more. Ts. d := more. Ts. st} E Consider provided solutions of PLP Exercise 4.17 (1) Explain essential differences between solutions (a) and (b). (ii) Modify solutions (a), (b) so that the second derivative (not the first derivative) is accumulated in a synthetized attribute of the root of the parse tree.

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 23:00, brooklynmikestovgphx
Suppose s, t, and w are strings that have already been created inside main. write a statement or statements, to be added to main, that will determine if the lengths of the three strings are in order by length, smallest to largest. that is, your code should determine if s is strictly shorter than t, and if t is strictly shorter than w. if these conditions hold your code should print (the boolean value) true. if not, your code should print false. (strictly means: no ties) example: if s, t, and w are "cat", "hats", and "skies" your code should print true - their lengths are 3-4-5; but if s, t, and w are "cats" "shirt", and "trust", then print false - their lengths are 4-5-5 enter your code in the box below
Answers: 2
image
Computers and Technology, 23.06.2019 16:00, ginaaa20
Which analyst position analyzes information using mathematical models to business managers make decisions?
Answers: 1
image
Computers and Technology, 23.06.2019 18:30, milkshakegrande101
Where can page numbers appear? check all that apply. in the header inside tables in the footer at the bottom of columns at the top of columns
Answers: 1
image
Computers and Technology, 24.06.2019 03:30, live4dramaoy0yf9
Explain the importance of html in web page designing in 20 sentences..
Answers: 1
Do you know the correct answer?
(a) Write a context-free grammar for polynomials in x. Add semantic func- tions to produce an attrib...

Questions in other subjects:

Konu
Mathematics, 11.12.2019 17:31