Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 2 : - The following grammar produces strings that describe trees. 1 . S - > tree 2 . tree - > ( SUM

Question 2 :-
The following grammar produces strings that describe trees.
1. S -> tree
2. tree ->(SUM treelist)
3. tree ->(ZERO treelist)
4. tree ->( HEIGHT treelist )
5. tree ->(DOUBLE tree)
6. tree -> NUMBER
7. treelist -> treelist tree
8. treelist -> tree
The leaves of the trees appear from natural numbers.
Internal nodes (with one or more children) are marked with a label (sum or zero or height or
double). A tree that includes only one node (which must be a leaf) is described by the number that appears on the leaf.
A tree that has more than one node is described by parentheses in which the label at the root appears and after it
Strings describing the subtrees of the root appear.
For example the string
(height (sum (sum 1(sum 2)))3)
describes the following tree:
It is allowed to set attributes to the grammar variables as needed. Do not define global variables.
The actions that are attached to each derivation rule should refer only to the features of the signs that appear
in the same rule and not for global variables.
The NUMBER token represents numbers. Assume that the val.NUMBER attribute specifies a value
the number
In the solution all attributes should be numeric. There is no need to define an attribute whose value is a tree.
It is allowed to use functions like maximum. If the meaning of the function is not self-evident
So attach a short explanation.
Question 3 :-(computer program -45%)
The translation scheme you wrote in question 2 must be implemented
You can use bison & flex or other tools.s
The input to the program will be a file containing a description of a tree as described in question 2
The input file will be given as a command line argument.
The output will be the value of the tree. It will be written to standard output.
Call the executable file exe.tree. (or tree if you work on Linux).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions