Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 2 : - The following grammar produces strings that describe trees. 1 . S - > tree 2 . tree - > ( SUM
Question :
The following grammar produces strings that describe trees.
S tree
tree SUM treelist
tree ZERO treelist
tree HEIGHT treelist
tree DOUBLE tree
tree NUMBER
treelist treelist tree
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 sum
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 selfevident
So attach a short explanation.
Question :computer program
The translation scheme you wrote in question 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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started