Modify the solution of PLP problem 4.6, attached below, so that the attribute of the root accumulates the number of arit

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Modify the solution of PLP problem 4.6, attached below, so that the attribute of the root accumulates the number of arit

Post by answerhappygod »

Modify the solution of PLP problem 4.6, attached below, so that
the attribute of the root accumulates the number of arithmetic
operations +, −, ∗, / instead of the maximum depth of nested
parentheses.
Modify The Solution Of Plp Problem 4 6 Attached Below So That The Attribute Of The Root Accumulates The Number Of Arit 1
Modify The Solution Of Plp Problem 4 6 Attached Below So That The Attribute Of The Root Accumulates The Number Of Arit 1 (422.42 KiB) Viewed 35 times
4.6 Refer back to the context-free grammar of Exercise 2.13. Add attribute rules to the grammar to accumulate into the root of the tree a count of the maximum depth to which parentheses are nested in the program string. For example, given the string f1(a, f2(b * (c + (d - (e - f))))), the stmt at the root of the tree should have an attribute with a count of 3 (the parentheses surrounding argument lists don't count). Answer: stmt → assignment stmt -7 subr_call assignment - id := expr subr_call + id ( arg_list ) expr + primary expr_tail expr_tail + op expr expr_tail —— € primary →id primary + subr-call primary + ( expr ) op + -|- |*|/ arg_list + expr args_tail args-tail → args_tail D stmt.depth := assignment.depth stmt.depth := subr-call.depth o assignment.depth := expr.depth o subr-call.depth := arg.list.depth expr.depth := max(primary.depth, expr_tail.depth) expr_tail.depth := expr.depth ► expr-tail.depth := 0 primary.depth := 0 primary.depth := subr-call.depth s primary.depth := expr.depth + 1 + Dargslist.depth := max(expr.depth, args_tail.depth) sargstail.depth := args-list.depth Dargs_tail.depth = 0 3 arg-list E
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply