Question: Answer both please. 3. (40) Consider the following context free grammar for an arithmetic expression contain ing operation - only -> number -> - number

Answer both please. 3. (40) Consider the following context free grammar for an arithmetic expression contain ing operation - only

-> number

-> - number |

(a) The following is an attribute grammar to define the value of any arithmetic expres sion specified by the grammar above.

-> number

B .value := .value

B .st := number.value

-> - number

B 2.st := 1.st - number.value

B 1.value := 2.value

->

B .value := .st

Draw a decorated parse tree for 1-2-3-4 using the attribute grammar.

(b) Instead of the value of an arithmetic expression, we would like to know the number of numbers in an arithmetic expression. For example, in 1-2-3-4, we have four numbers.

Write an attribute grammar to define the number of numbers of any arithmetic expression following the grammar in part a).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!