Question

In: Computer Science

Given a Syntax Directed Translation as follows. Production Semantic Rules L → E n L.val =...

Given a Syntax Directed Translation as follows.

Production

Semantic Rules

L → E n

L.val = E.val

E → E1 + T

E.val = E1 .val + T.val

E → T

E.val =T.val

T → T1 * F

T.val = T1.val x F.val

T → F

T.val = F.val   

F → ( E )        

F.val = E.val

F → digit

F.val = digit.lexval

Question

Create an annotated parse tree for the following statements

  1. a. (3+4) * (5+6)n
  2. b. 1*2*3*(4+5)n

Solutions

Expert Solution

An annotated parse tree contains the values of attributes at each node for given input string. There are two types of attributes in an annotated parse tree.

1. Synthesized attributes and

2. Inherited attributes.

In an annotated parse tree value of synthesized attribute at node is computed from the values of attributes at children nodes in parse tree. In the first and second examples we used synthesized attributes.

The value of inherited attributes are computed by value of parent or sibling nodes.


Related Solutions

# Problem Description Given a directed graph G = (V,E) with edge length l(e) > 0...
# Problem Description Given a directed graph G = (V,E) with edge length l(e) > 0 for any e in E, and a source vertex s. Use Dijkstra’s algorithm to calculate distance(s,v) for all of the vertices v in V. (You can implement your own priority queue or use the build-in function for C++/Python) # Input The graph has `n` vertices and `m` edges. There are m + 1 lines, the first line gives three numbers `n`,`m` and `s`(1 <=...
You are given a directed graph G(V,E) with n vertices and m edges. Let S be...
You are given a directed graph G(V,E) with n vertices and m edges. Let S be the subset of vertices in G that are able to reach some cycle in G. Design an O(n + m) time algorithm to compute the set S. You can assume that G is given to you in the adjacency-list representation.
# Problem Description Given a directed graph G = (V, E), find the number of connected...
# Problem Description Given a directed graph G = (V, E), find the number of connected components in G. # Input The graph has `n` vertices and `m` edges. There are m + 1 lines, the first line gives two numbers `n` and `m`, describing the number of vertices and edges. Each of the following lines contains two numbers `a` and `b` meaning there is an edge (a,b) belong to E. All the numbers in a line are separated by...
Please use python: # Problem Description Given a directed graph G = (V, E), find the...
Please use python: # Problem Description Given a directed graph G = (V, E), find the number of connected components in G. # Input The graph has `n` vertices and `m` edges. There are m + 1 lines, the first line gives two numbers `n` and `m`, describing the number of vertices and edges. Each of the following lines contains two numbers `a` and `b` meaning there is an edge (a,b) belong to E. All the numbers in a line...
Rule Based System 1. Given the rule following rules from the class notes on production rules...
Rule Based System 1. Given the rule following rules from the class notes on production rules to convert an Arabic number less than 40 to a roman numeral. USING LOGIC Rule 1: if x is null then prompt the user and read x Rule 2: if x is higher than 999 then print “too Big” and make x null Rule 3: if x is between 10 and 39 then print “X” and reduce x by 10 Rule 4: if x...
#1 We are given the grammar rules A ➝ F B E B ➝ A C...
#1 We are given the grammar rules A ➝ F B E B ➝ A C These rules are only some of the rules of a larger grammar G, but we are not given the remaining rules of G. We are told that A is the start symbol of G and that the following holds: {ε, c, d} ⊆ FIRST(C) {ε, e} ⊆ FIRST(E) {ε, f, g} ⊆ FIRST(F) Recall that end of file is denoted EOF. The symbol ⊆...
Given the balanced equation: 3Ni(s) + 2Au3+(aq) :⟶2Au(s) + 3Ni2+(aq), E^o_{cell}\:E c e l l o=...
Given the balanced equation: 3Ni(s) + 2Au3+(aq) :⟶2Au(s) + 3Ni2+(aq), E^o_{cell}\:E c e l l o= 1.76 V, what is the cell potential for this reaction when [Au3+] = 0.95 M and [Ni2+] = 0.016 M at 298 K? Group of answer choices 1.78 V 1.71 V 1.81 V 1.92 V
Two decision rules are given here. Assume that the quality characteristic follows a normal distribution and...
Two decision rules are given here. Assume that the quality characteristic follows a normal distribution and the control chart has two-sigma control limits, and the sample size is ? = 4. Rule 1: If one or more of the next 3 samples yield values of the sample average that fall outside the control limits, conclude that the process is out of control. Rule 2: If all of the next 5 samples fall on the same side of the center line,...
Given any positive integer n, the hailstone sequence starting at n is obtained as follows. You...
Given any positive integer n, the hailstone sequence starting at n is obtained as follows. You write a sequence of numbers, one after another. Start by writing n. If n is even, then the next number is n/2. If n is odd, then the next number is 3n + 1. Continue in this way until you write the number 1. For example, if you start at 7, then the next number is 22 (3 × 7 + 1). The next...
Consider the economy described by the production function Y = F (K, L x E) =...
Consider the economy described by the production function Y = F (K, L x E) = Kα(LE)1-α (a) Derive per effective worker production function. (b) Assume there is population growth rate, depreciation rate and technology growth rate. -Write the law of motion of k. -Tell how k* will be changed when population growth rate increases with graph. (c) Calculate steady state equilibrium. k∗ = y∗ = c∗ = (d) Calculate gold rule capital stock and output. kgold = ygold =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT