The grammar below generates nested lists of numbers The sema

The grammar below generates nested lists of numbers. The semantic actions are intended to count the number of elements just inside each parenthesized list. For each list found by Rule 2, Marker 44 prints out the number of elements found just inside the list. For example, the input

(a) The grammar uses a global variable count to determine the number of elements in a list. What is wrong with that approach?
(b) Change the semantic actions so that the appropriate values are synthesized

Solution

If you use a global count variable to store the number of elements in a list then the at the end of grammer the count will be equal to total number of elements inside the outer most list. But we wanted seperate count for each list. So instead of using a global variable u can use a local variable for each nested list.
The grammar below generates nested lists of numbers. The semantic actions are intended to count the number of elements just inside each parenthesized list. For

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site